如何在 JDO 中进行批量 Google DataStore 键查找查询

发布于 2024-08-25 18:04:43 字数 628 浏览 10 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝咒 2024-09-01 18:04:43

不要使用查询按键获取实体 - 它们效率低下,并且需要对检索的每个对象进行查询!相反,按键获取对象。 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.

辞慾 2024-09-01 18:04:43

可能在 JDOQL 情况下不起作用,因为它不是有效的 JDOQL :-P

Collection keys = ... (create your keys collection)
Query q = pm.newQuery("SELECT FROM " + Pet.class.getName() + " WHERE :keys.contains(id)");

即过滤器使用 Java 语法

Likely doesn't work in the JDOQL case since it isn't valid JDOQL :-P

Collection keys = ... (create your keys collection)
Query q = pm.newQuery("SELECT FROM " + Pet.class.getName() + " WHERE :keys.contains(id)");

i.e the filter uses Java syntax

三人与歌 2024-09-01 18:04:43

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文