Cursor-based pagination
To browse through the objects returned by using search, we use cursor-based pagination. Cursor-based pagination is used because of the real-time aspect of the handled data, which is a little bit different than the usual offset based pagination.
Search request properties
For limiting the number of objects returned at one time use the limit
property.
To retrieve the objects after the limited number of objects, use the after
property, and before
property to retrieve objects before those retrieved.
We provide two additional useful properties hasNext
and hasPrevious
, which tell you if there are objects before or after the currently retrieved list.
Simple paginated search
CustomerSearchRequest req = new CustomerSearchRequest()
.after('customer_uid') // or .before('customer_uid')
.limit(20);
Handing results
Result of a search is a Collection object which contains the items themselves and several helpful properties mentioned above. Iterating is thus very easy.
CustomerCollection result = gateway.customer().search(req);
for (Customer customer: result.getItems()) {
System.out.println(customer.getUid());
}