简体   繁体   English

使用Java为App Engine数据存储区设置游标

[英]Setting Cursor for App Engine Datastore using Java

What should the startCursor be set to if I want to query results from my first element to 10th element? 如果要查询从第一个元素到第十个元素的结果,应该将startCursor设置为什么?

I understand that startCursor should be a Cursor object, but what value should I set it to? 我知道startCursor应该是Cursor对象,但是应该将其设置为什么值?

My entity ID's are primitive integers starting from 1. 我的实体ID是从1开始的原始整数。

Please comment if any further information is necessary. 如果需要进一步的信息,请发表评论。

You set a cursor on a query when you have it. 您在查询中设置了光标。 Otherwise, you simply don't set it - this will query from the very beginning. 否则,您根本不需要设置它-它将从一开始就进行查询。

For example: 例如:

Query q = new Query("Person");
QueryResultList<Entity> results;
Cursor cursor = null;
FetchOptions queryOptions = FetchOptions.Builder.withChunkSize(500);

do {
    if (cursor != null) {
        queryOptions.startCursor(cursor);
    }
    results = datastore.prepare(q).asQueryResultList(queryOptions);

    for (Entity entity : results) {
        // do something
    }
    cursor = results.getCursor();

} while (results.size() == 500);

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

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