3

I want to execute a query, get the results and then get the cursor to the next item if there is any. The only relevant post I found was: Objectify paging with Cursors

Is there a way of doing this without iterating through the items?

Query<User> query = ofy().load().type(User.class).limit(RecordLimit).filter("gameId", gameId);
//execute and get the results
List<User> users = query.list()
//get the cursor for the next user
Community
  • 1
  • 1
mbsheikh
  • 2,501
  • 5
  • 23
  • 33

2 Answers2

1
String cursor = query.iterator().getCursor().toWebSafeString();

Look at these unit tests to make things a bit more clear.

varun
  • 4,522
  • 33
  • 28
-2

Query is itself iterable - like a cursor.

You can directly do:

Query<User> query = blah;
for(User u: query) {
    //u is next item from the "cursor"
}
gvaish
  • 9,374
  • 3
  • 38
  • 43
  • Thanks but it doesn't solve my problem. I don't want to iterate through the results. – mbsheikh Mar 07 '13 at 16:53
  • You can try: query.iterator().next() to get the "next item, if any". Not sure if this is what you're looking for. – gvaish Mar 08 '13 at 05:06
  • He is wanting `iterator.getCursor().toWebSafeString()` without ever having to care about the interator. This can be done in JDO so i would be shocked if not the much better Ofy. But i can't figure it out either, did you ever? – j_walker_dev Aug 29 '15 at 07:06