sai-pullabhotla
7/21/2016 - 9:11 PM

Catatumbo - Paginating through Query Results

Catatumbo - Paginating through Query Results

final String baseQuery = "SELECT * FROM people ORDER BY __key__ LIMIT @Limit";
String query = baseQuery;
EntityQueryRequest request = em.createEntityQueryRequest(query);
request.setNamedBinding("Limit", 5);
QueryResponse<Person> response = em.executeEntityQueryRequest(Person.class, request);
List<Person> persons = response.getResults();
// Process the first page of results as needed...

// Get Next Page.  
query = baseQuery + " OFFSET @Offset";
request.setQuery(query);
//Set the offset to the endCursor from previous response. 
request.setNamedBinding("Offset", response.getEndCursor());
response = em.executeEntityQueryRequest(Person.class, request);
persons = response.getResults();
//Process the second page as needed