2017-09-01 49 views
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); 
} 

回答

0

啊確定 - 如果我是一個有點更有耐心,我會發現在引用鏈接的文檔中的答案:

「因爲NOT_EQUAL和IN操作符與多個查詢執行,查詢使用它們不支持遊標,也不使用CompositeFilterOperator.or方法構造組合查詢。「

+0

但是你怎麼做呢,如果你有一個CompositeFilterOperator.or查詢,你需要使用遊標? – Lull

相關問題