我正在尝试将此 Python 代码从演示文稿 Building Scalable, Complex Apps on App Engine翻译成 Java ,
GAEJ 是否支持这样做?
indexes = db.GqlQuery( "SELECT __key__ FROM MessageIndex " "WHERE receivers = :1", me)
keys = [k.parent() for k in indexes]
messages = db.get(keys)
下面是我在 Java 中的实现。这些功能和性能是否等效?如果我有大量密钥会怎样?
Query query1 = new Query("MessageIndex");
query1.setKeysOnly();
query1.addFilter("receivers", FilterOperator.EQUAL, me);
PreparedQuery pq2 = datastore.prepare(query1);
Iterable<Entity> entities = pq2.asIterable();
HashSet<Key> keys = new HashSet<Key>();
for (Entity en : entities)
keys.add(en.getParent());
Query query2 = new Query("Messages");
query2.addFilter("__key__", FilterOperator.IN, keys);