如何在 JDO 中进行批量 Google DataStore 键查找查询
我在 appengine 中存储了大约 50k 个实体。我可以通过 GQL 管理界面查找单个记录,查询如下:
SELECT * FROM Pet where __key__ = KEY( 'Pet','Fido')
但我无法弄清楚如何通过 JDO 执行此批处理版本。现在我有这个:
PersistenceManager pm = ...;
for(Pet pet : pets) {
for(String k : getAllAliases(pet)) {
keys.add(KeyFactory.createKeyString(Pet.class.getSimpleName(), k));
}
}
Query q = pm.newQuery("select from " + Pet.class.getName() + " where id == :keys");
List<Pet> petlist = (List<Pet>) q.execute(keys);
但是虽然“Fido”在 GQL 情况下工作,但当我使用 Java + JDO 代码时它不会返回任何内容。我做错了什么?
I have about 50k entities stored in appengine. I am able to look up an individual record via the GQL admin interface with a query like:
SELECT * FROM Pet where __key__ = KEY( 'Pet','Fido')
But I'm having trouble figuring out how to do a batch version of this via JDO. Right now I have this:
PersistenceManager pm = ...;
for(Pet pet : pets) {
for(String k : getAllAliases(pet)) {
keys.add(KeyFactory.createKeyString(Pet.class.getSimpleName(), k));
}
}
Query q = pm.newQuery("select from " + Pet.class.getName() + " where id == :keys");
List<Pet> petlist = (List<Pet>) q.execute(keys);
But though 'Fido' works in the GQL case, it returns nothing when I use that Java + JDO code. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要使用查询按键获取实体 - 它们效率低下,并且需要对检索的每个对象进行查询!相反,按键获取对象。 JDO 似乎不支持按键批量获取,但一次按一个键获取它们仍然比对它们进行查询要高效得多。
Don't use queries to fetch entities by key - they're inefficient, and require a query for each object retrieved! Instead, get the objects by key. Bulk fetches by key don't appear to be supported by JDO, but fetching them by key one at a time is still going to be a lot more efficient than doing queries for them.
可能在 JDOQL 情况下不起作用,因为它不是有效的 JDOQL :-P
即过滤器使用 Java 语法
Likely doesn't work in the JDOQL case since it isn't valid JDOQL :-P
i.e the filter uses Java syntax
http://gae-java-persistence.blogspot。 com/2009/10/executing-batch-gets.html
我没有尝试JDO版本,但JPA版本确实可以工作!
http://gae-java-persistence.blogspot.com/2009/10/executing-batch-gets.html
I didn't try the JDO version, but the JPA version does work!