·¬ÇÑÉçÇø

Brightspot CMS Developer Guide

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 object is returned that is limited to the first 10 User objects.

 PaginatedResult<User> results = Query.from(User.class) 
                                      .select(0, 10);
 List<User> users = results.getItems();
  • Returns a PaginatedResult with . This method specifies the number of objects to return starting at a particular offset. If the offset were set to 5 and the limit set to 15, the method would return 15 instances starting at offset 5.

    The PaginatedResult object only contains the number of objects specified in select(long offset, int limit), which is typically a subset of the total objects retrieved. For example, a query might return a total of 1,000 objects, which can be determined with the getCount method on PaginatedResult.
  • Returns the objects contained by PaginatedResult.

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; 
Query<User> query = Query.from(User.class); 
PaginatedResult<User> result = query.select(0, limit); 
while (result.hasNext()) { 
    /* 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 Query object for searching users.
  • Returns a PaginatedResult with the first 100 User objects.
  • Iterates PaginatedResult in batches of 100 items. Successive iterations continue until all of the objects retrieved by the query are processed.

Previous Topic
Predicates
Next Topic
Binding variables
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

•
•
•
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

• Content types
• Modules
• Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

• Dashboards
• Publishing
• Workflows
• Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

• Field types
• Content modeling
• Rich-text elements
• Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

• Google Analytics
• Shopify
• Apple News