How to do batch Google DataStore keyword search query in JDO

I have about 50 thousand objects stored in appengine. I can find a single entry through the GQL admin interface with a query like:

SELECT * FROM Pet where __key__ = KEY( 'Pet','Fido')

But it's hard for me to figure out how to make a batch version of this through 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 although "Fido" works in the case of GQL, it does not return anything when I use this Java + JDO code. What am I doing wrong?

+3
source share
3 answers

- ! . JDO, - , .

+2

, JDOQL, . JDOQL: -P

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

i.e Java

+1

http://gae-java-persistence.blogspot.com/2009/10/executing-batch-gets.html

I have not tried the JDO version, but the JPA version works!

0
source

Source: https://habr.com/ru/post/1737464/


All Articles