我要执行以下操作:

PreparedQuery pq = datastore.prepare(q);
int count = pq.countEntities(FetchOptions.ALL);


但是没有所有选项。那我该怎么办呢?

对于上下文,假设我要计算表中颜色为橙色的所有条目。

如果我不能直接使用DatastoreService执行此操作,是否可以使用Datanucleus的JPA?它们是否支持Appengine数据存储的SELECT COUNT(*) ...

最佳答案

您可以使用以下代码计算总记录数。

com.google.appengine.api.datastore.Query qry = new com.google.appengine.api.datastore.Query("EntityName");
com.google.appengine.api.datastore.DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
int totalCount = datastoreService.prepare(qry).countEntities(FetchOptions.Builder.withDefaults());


希望对您有帮助。

关于java - 数据存储区计数查询fetchOptions,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16863368/

10-11 05:02