According to JDO, you can use PersistenceManager.getObjectsById to load multiple entity instances by their object id.
What kind of Collection does one need to use here? A Google Data Store Key does not work as object id.
Use PersistenceManager.newObjectIdInstance(), as such
List<Object> ids = new ArrayList<Object>();
for (Key key : keys) {
ids.add(pm.newObjectIdInstance(Foo.class, key));
}
return (List<Foo>) pm.getObjectsById(ids);
I'm not sure however how expensive the call to newObjectIdInstance is (it shouldn't be from what I can see).
Not a direct answer, by as an alternative to getObjectsById
, it seems that you can use a JDOQL query to load multiple entities by key:
public List getById(List keys) {
Query q = pm.newQuery(
"select from " + Book.class.getName() + " where :keys.contains(key)");
return (List) q.execute(keys);
}
Apparently, this query is optimized to use an efficient low-level bulk API.
The order of the keys does get lost though, so you will have to re-sort the result in Java land.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With