因为GAE规定了返回的条数不能超过1000条,所以只能分两种做法:
当记录的条数小于1000的时候:
当记录的条数大于1000的时候:
最有效的方法是新建一个表,一个counter字段来记录总记录数目。(原话:the most efficient solution would be incrementing a
counter with every write and just reading this value when it's needed)
当记录的条数小于1000的时候:
PersistenceManager pm = getPersistenceManager();
Query query = pm.newQuery(Chapter.class);
query.setResult("count(this)");
int count = 0;
try {
count = (Integer) query.execute();
} finally {
pm.close();
} 当记录的条数大于1000的时候:
最有效的方法是新建一个表,一个counter字段来记录总记录数目。(原话:the most efficient solution would be incrementing a
counter with every write and just reading this value when it's needed)
本文介绍了在Google App Engine (GAE) 中如何处理超过1000条记录的查询限制问题。当记录数量少于1000条时,可以通过PersistenceManager和Query API直接获取总数。而当记录数量超过1000条时,则建议使用额外的计数器表来记录总记录数,以提高查询效率。

被折叠的 条评论
为什么被折叠?



