0
我想使用GAE游标使用此页https://cloud.google.com/appengine/docs/standard/java/datastore/query-cursors作为灵感。 问题是,我的代码下面返回的游标为空 - 我不明白为什么,因为我认为我使用与上述链接相同的结构,即查询的结果是QueryResultList,并且我使用getCursor方法在结果上获得对游标的引用。 NON_SENT_MATCHES_LIMIT是20,如果我对查询设置了无限制,那么有超过2000个实体,所以我期望得到一个非空的游标。为什么从我的GAE数据存储查询返回游标为空?
任何人都可以向我解释为什么游标为空?
public ProductRuleMatchWithCursor getNonSentMatchesBatch(Transaction transaction, long shopId, Cursor startCursor) {
Query.FilterPredicate activeOrderProduct = new Query.FilterPredicate(ProductRuleMatchDBFields.ACTIVE, Query.FilterOperator.EQUAL, true);
Query.FilterPredicate pendingOrderProduct = new Query.FilterPredicate(ProductRuleMatchDBFields.MATCH_STATUS, Query.FilterOperator.EQUAL, MatchStatus.PENDING.getId());
Query.FilterPredicate failedOrderProduct = new Query.FilterPredicate(ProductRuleMatchDBFields.MATCH_STATUS, Query.FilterOperator.EQUAL, MatchStatus.FAILED_CAN_RECOVER.getId());
Query query = new Query(ProductRuleMatchDBFields.PRODUCT_RULE_MATCH_TABLE_NAME).setFilter(Query.CompositeFilterOperator.and(activeOrderProduct, Query.CompositeFilterOperator.or(pendingOrderProduct, failedOrderProduct)));
query.setAncestor(KeyFactory.createKey(ShopDBFields.SHOP_TABLE_NAME, shopId));
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(NON_SENT_MATCHES_LIMIT);
if (startCursor != null){
fetchOptions.startCursor(startCursor);
}
QueryResultList<Entity> entities = datastore.prepare(transaction, query).asQueryResultList(fetchOptions);
List<ProductRuleMatch> matches = new ArrayList<>();
for (Entity entity : entities) {
matches.add(createModelFromEntity(entity));
}
Cursor cursor = entities.getCursor();
logger.info("The cursor is: " + cursor);
return new ProductRuleMatchWithCursor(matches, cursor);
}
但是你怎么做呢,如果你有一个CompositeFilterOperator.or查询,你需要使用游标? – Lull