Class RawPaginator

java.lang.Object
org.javalite.activejdbc.RawPaginator
All Implemented Interfaces:
Serializable

public class RawPaginator extends Object implements Serializable
This paginator is for paging through free-form queries unrelated to models. It is used to collect an arbitrary number of columns form a table, whereas the Paginator is tied to models, where each model collects all columns from underlying table.

This class can be more efficient because it allows to load only the columns you need to display on the UI.

This class supports pagination of result sets in ActiveJDBC. It is useful for paging through tables. If the You can generate an instance each time you need one, or you can cache an instance in a session or even servlet context.
Author:
Igor Polevoy
See Also:
Serialized Form
  • Constructor Details

    • RawPaginator

      public RawPaginator(String tableName, String[] columns, int pageSize, String subQuery, Object... params)
      Convenience constructor. Defaults to "default" database and suppressCount = false
      Parameters:
      tableName - name of a table to use
      columns - list of columns to select, or null to select all columns
      pageSize - number of items per page.
      subQuery - - sub query to select some records, such as "last_name like ?". If null is provided, all records are selected without any filtering
      params - a set of parameters if a query is parametrized (has question marks '?').
    • RawPaginator

      public RawPaginator(String dbName, String tableName, String[] columns, int pageSize, boolean suppressCounts, String subQuery, Object... params)
      Paginator is created with parameters to jump to chunks of result sets (pages). This class is useful "paging" through result on a user interface (web page).
      Parameters:
      dbName - name of database
      tableName - name of a table to use
      columns - list of columns to select, or null to select all columns
      pageSize - number of items per page.
      suppressCounts - suppress calling "select count(*)... " on a table each time. If set to true, it will call count only once. If set to false, it will call count each time getCount() is called from hasNext() as well.
      subQuery - - sub query to select some records, such as "last_name like ?". If null is provided, all records are selected without any filtering
      params - a set of parameters if a query is parametrized (has question marks '?').
  • Method Details

    • orderBy

      public RawPaginator orderBy(String orderBy)
      Use to set order by(s). Example: paginator.orderBy("category").orderBy("tab");
      Parameters:
      orderBy - - a single "order by" expression.
      Returns:
      instance to self.
    • getPage

      public List<Map<String,​Object>> getPage(int pageNumber)
      This method will return a list of records for a specific page.
      Parameters:
      pageNumber - page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will be rejected.
      Returns:
      list of records that match a query make up a "page".
    • getCurrentPage

      public int getCurrentPage()
      Returns index of current page, or 0 if this instance has not produced a page yet.
      Returns:
      index of current page, or 0 if this instance has not produced a page yet.
    • getPrevious

      public boolean getPrevious()
      Synonym for hasPrevious().
      Returns:
      true if a previous page is available.
    • hasPrevious

      public boolean hasPrevious()
    • getNext

      public boolean getNext()
      Synonym for hasNext().
      Returns:
      true if a next page is available.
    • hasNext

      public boolean hasNext()
    • pageCount

      public long pageCount()
    • getCount

      public Long getCount()
      Returns total count of records based on provided criteria.
      Returns:
      total count of records based on provided criteria