Paginated results
The Query
API includes methods for returning paginated results. A paginated result prevents all query results from being returned at one time, potentially exceeding system memory. It allows you to incrementally return and process query results in batches.
In the following snippet, a PaginatedResult object is returned that is limited to the first 10 User
objects.
PaginatedResult<User> results = Query.from(User.class) 1 .select(0, 10); List<User> users = results.getItems(); 2
Returns a The | |
Returns the objects contained by |
To iterate query results in batches, use the PaginatedResult
methods hasNext()
and getNextOffset()
. The following snippet builds paginated results in batches of 100 objects.
int limit = 100; 1 Query<User> query = Query.from(User.class); 2 PaginatedResult<User> result = query.select(0, limit); 3 while (result.hasNext()) { 4 /* Do something with the current batch of items referenced in the result object */ result = query.select(result.getNextOffset(), limit); }
Variable for limiting the number of retrieved records in a page. | |
Instantiates a | |
Returns a | |
Iterates |