Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 谷歌应用引擎-推荐的Ids查询方法_Google App Engine_Jpa_Google Cloud Datastore - Fatal编程技术网

Google app engine 谷歌应用引擎-推荐的Ids查询方法

Google app engine 谷歌应用引擎-推荐的Ids查询方法,google-app-engine,jpa,google-cloud-datastore,Google App Engine,Jpa,Google Cloud Datastore,任何人都可以推荐通过GAE HRD数据存储中的多个ID查询实体的更好方法吗 一, mgr=getEntityManager(); Query dbQuery=mgr.createQuery(“从CustomEntity中选择id位于(:ids)中的CustomEntity作为CustomEntity”); setParameter(“ids”,results.getIds()); return(List)dbQuery.getResultList(); 二, List customEntity

任何人都可以推荐通过GAE HRD数据存储中的多个ID查询实体的更好方法吗

一,

mgr=getEntityManager();
Query dbQuery=mgr.createQuery(“从CustomEntity中选择id位于(:ids)中的CustomEntity作为CustomEntity”);
setParameter(“ids”,results.getIds());
return(List)dbQuery.getResultList();
二,

List customEntityKeys=new ArrayList();
for(字符串id:results.getIds()){
添加(KeyFactory.createKey(“CustomEntity”,id));
}
mgr=getEntityManager();
JPADatastoreBridge=新的JPADatastoreBridge();
List customEntities=new ArrayList();
Map customEntityMap=datastore.get(customEntityKeys);
对于(实体customEntityEntity:customEntityMap.values()){
添加((CustomEntity)jpaBridge.getJPAFromEntity(customEntityEntity,mgr,CustomEntity.class));
}
返回实体;
在“更好的方法”中,我指的主要是性能方面。还有,如果有别的办法的话,我会很高兴听到的。 谢谢

p、 s.

我使用JPA作为我的持久性方法。不确定这是否真的很重要。

我不知道大部分代码,但如果您询问是否应该使用
查询(“选择….WHERE ID IN….”)
数据存储。获取(…)
,第二个更好。GET比使用App Engine数据存储的查询效率要高得多——更不用说它们始终是强一致的,而非祖先查询最终才是一致的

mgr = getEntityManager();           
Query dbQuery = mgr.createQuery("SELECT FROM CustomEntity as CustomEntity WHERE id IN (:ids)");
dbQuery.setParameter("ids", results.getIds());
return (List<CustomEntity>) dbQuery.getResultList();
List<Key> customEntityKeys = new ArrayList<Key>();
for (String id : results.getIds()) {
    customEntityKeys.add(KeyFactory.createKey("CustomEntity", id));
}

mgr = getEntityManager();
JPADatastoreBridge jpaBridge = new JPADatastoreBridge();
List<CustomEntity> customEntities = new ArrayList<CustomEntity>();

Map<Key,Entity> customEntityMap = datastore.get(customEntityKeys);
for (Entity customEntityEntity : customEntityMap.values()) {
    customEntities.add((CustomEntity) jpaBridge.getJPAFromEntity(customEntityEntity, mgr, CustomEntity.class));                 
}
return customEntities;