私は、Javaアプリケーションエンジンオブジェクトをリストプロパティを通じてモデル化して、効率的なクエリを効率的に実行しようとしています。このコードを改善することはできますか?Google App Engine用Javaのリストプロパティ - これは最も効率的でパフォーマンスの高いJDOコードですか?
私は本当にObjectifyに移行したくありません。
は、ここでそれを取得するためのコードです:
query = persistenceManager.newQuery(HuddleCreatorIndex.class, ":p.contains(creator)");
List<HuddleCreatorIndex> myCreatorIndexList = (List<HuddleCreatorIndex>) query.execute(KeyFactory.createKey(Contact.class.getSimpleName(), fbUserId));
if (myCreatorIndexList.size() > 0) {
Set<Long> huddles = myCreatorIndexList.get(0).getHuddles();
//THIS FOR LOOP DID THE TRICK, why is this necessary? Never saw it in any examples
for (Long huddleKey : huddles)
alist.add(persistenceManager.newObjectIdInstance(Huddle.class, huddleKey));
Collection<Huddle> huddlesICreated = persistenceManager.getObjectsById(huddles);
allMyHuddles.addAll(huddlesICreated);
}
はここでオブジェクトが元々保存されているかを示すサポートするコードの残りの部分、及び、関連するモデルクラスです。
このコード作戦会議の作成時にに呼び出され(これは正しくデータストア内のすべてのオブジェクトを設定します)
txn.begin();
//First, create the Huddle, this main model class
newHuddle.setInvitees(inviteeList);
newHuddle = pm.makePersistent(newHuddle);
huddleId = newHuddle.getId();
//Now create the first index
HuddleIndex newIndex = new HuddleIndex();
newIndex.setParent(KeyFactory.createKey(Huddle.class.getSimpleName(), newHuddle.getId()));
newIndex.setInvitees(inviteeList);
pm.makePersistent(newIndex);
//And finally, create the other index
Query query = pm.newQuery(HuddleCreatorIndex.class);
query.setFilter(":p.contains(creator)");
List<HuddleCreatorIndex> list = (List<HuddleCreatorIndex>) query.execute(creator.getId());
if (list != null && list.size() > 0) {
HuddleCreatorIndex thisIndex = list.get(0);
Set<Key> huddles = thisIndex.getHuddles();
huddles.add(KeyFactory.createKey(Huddle.class.getSimpleName(), newHuddle.getId()));
thisIndex.setHuddles(huddles);
} else {
HuddleCreatorIndex newCreatorIndex = new HuddleCreatorIndex();
newCreatorIndex.setCreator(creator.getId());
Set<Long> huddleSet = new HashSet<Long>(1);
huddleSet.add(newHuddle.getId());
newCreatorIndex.setHuddles(huddleSet);
pm.makePersistent(newCreatorIndex);
}
txn.commit();
ここでは、実際のデータ
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Huddle {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
private Key creator;
private String name;
private Date whenTimeStamp;
private Date creationTimeStamp;
private String userIdType;
private Set<Key> invitees;
private String status;
private Set<Key> choices;
private List<Vote> votes;
//setters, getters, and constructor omitted
}
私と私の実際のモデルオブジェクトですリストプロパティの魔法を起こすためのインデックスオブジェクト
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class HuddleCreatorIndex {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
private Key creator;
private Set<Long> huddles;
//setters, getters, and constructor omitted
}
私はGAEのJDOプラグインのバージョン2.3を使用しています。私はモデルオブジェクトの "作成"のための周囲のコードでトランザクションの私の使用をきれいにすることに基づいて問題1を解決しました。しかし、私はまだJDOObjectNotFoundExceptionsを取得している検索で問題はありますが、オブジェクトがそこにあることがわかります!私はこのアップデートで写真を投稿します。 –
JDOのFYI v2.3は、GAE JDOプラグイン(datanucleus-appengine jar)のv1.0を意味します。 – DataNucleus