简体   繁体   English

为什么我的GAE数据存储区查询返回的游标为空?

[英]Why is the cursor returned from my GAE datastore query null?

I am trying to use GAE cursors using this page https://cloud.google.com/appengine/docs/standard/java/datastore/query-cursors as inspiration. 我正在尝试通过https://cloud.google.com/appengine/docs/standard/java/datastore/query-cursors此页面使用GAE游标。 The problem is that the cursor returned by my code below is null - I do not understand why, as I think I use the same structure as the above link, ie the result from the query is a QueryResultList, and I use the getCursor method on the result to obtain a reference to the cursor. 问题是我下面的代码返回的游标为空-我不明白为什么,因为我认为我使用与上述链接相同的结构,即查询的结果是QueryResultList,并且我在getCursor方法上使用结果以获得对游标的引用。 The NON_SENT_MATCHES_LIMIT is 20 and if I set no limit on the query there are more than 2000 entities, so I would expect a non-null cursor as a result. NON_SENT_MATCHES_LIMIT为20,如果我对查询没有设置限制,则实体数将超过2000,因此我希望结果是非空游标。

Can anybody explain to me why the cursor is null? 有人可以向我解释为什么光标为空吗?

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);
}

Ahh ok - if I had been a bit more patient I would have found the answer in the documentation in the referenced link: 嗯,好吧-如果我比较耐心,我会在参考链接的文档中找到答案:

"Because the NOT_EQUAL and IN operators are implemented with multiple queries, queries that use them do not support cursors, nor do composite queries constructed with the CompositeFilterOperator.or method." “因为用多个查询实现了NOT_EQUAL和IN运算符,所以使用它们的查询不支持游标,也不支持使用CompositeFilterOperator.or方法构造的复合查询。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM