简体   繁体   中英

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?

I understand that startCursor should be a Cursor object, but what value should I set it to?

My entity ID's are primitive integers starting from 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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