Skip to main content

Pagination

Results of both list queries and sum queries are paginated.

There are two methods for handling paginated results:

  1. Retrieve a page of results at a time – useful for implementing pagination in an end-user application, such as infinite scroll.
  2. Iterate through individual results - useful for processing results in an application, such as generating a report (where pages are incidental).

Retrieving pages

Each page contains a cursor. To retrieve the next page, you perform another query, providing the cursor from the previous page.

The cursor contains all details about the query (e.g. filter, group by, and page size parameters), so you do not need to provide those when retrieving a subsequent page.

The default page size for all page queries is 100. You can optionally provide a different page size when making the request.

Action.Page page1 = new Action.ListBuilder()
.setFilter("destinationAccountId=$1")
.addFilterParameter("alice")
.setPageSize(10)
.getPage(ledger);
for (Action action : page1.items) {
System.out.println("action: " + action.type);
System.out.println("flavor: " + action.flavorId);
System.out.println("amount: " + action.amount);
}

String cursor = page1.cursor;

Action.Page page2 = new Action.ListBuilder()
.getPage(ledger, cursor);
for (Action action : page2.items) {
System.out.println("action: " + action.type);
System.out.println("flavor: " + action.flavorId);
System.out.println("amount: " + action.amount);
}

Iterating results

When iterating results, you do not need to interact with the underlying pages, which will be fetched automatically by the SDK when necessary.

Action.Iterable actions = new Action.ListBuilder()
.setFilter("destinationAccountId=$1")
.addFilterParameter("alice")
.getIterable(ledger);
for (Action action : actions) {
System.out.println("action: " + action.type);
System.out.println("flavor: " + action.flavorId);
System.out.println("amount: " + action.amount);
}