Package org.javalite.activejdbc
Class RawPaginator
java.lang.Object
org.javalite.activejdbc.RawPaginator
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionRawPaginator(String tableName, String[] columns, int pageSize, String subQuery, Object... params)
Convenience constructor.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). -
Method Summary
Modifier and TypeMethodDescriptiongetCount()
Returns total count of records based on provided criteria.int
Returns index of current page, or 0 if this instance has not produced a page yet.boolean
getNext()
Synonym forhasNext()
.getPage(int pageNumber)
This method will return a list of records for a specific page.boolean
Synonym forhasPrevious()
.boolean
hasNext()
boolean
Use to set order by(s).long
-
Constructor Details
-
RawPaginator
public RawPaginator(String tableName, String[] columns, int pageSize, String subQuery, Object... params)Convenience constructor. Defaults to "default" database andsuppressCount = false
- Parameters:
tableName
- name of a table to usecolumns
- list of columns to select, ornull
to select all columnspageSize
- number of items per page.subQuery
- - sub query to select some records, such as "last_name like ?". Ifnull
is provided, all records are selected without any filteringparams
- 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 databasetableName
- name of a table to usecolumns
- list of columns to select, ornull
to select all columnspageSize
- 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 timegetCount()
is called fromhasNext()
as well.subQuery
- - sub query to select some records, such as "last_name like ?". Ifnull
is provided, all records are selected without any filteringparams
- a set of parameters if a query is parametrized (has question marks '?').
-
-
Method Details
-
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
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 forhasPrevious()
.- Returns:
- true if a previous page is available.
-
hasPrevious
public boolean hasPrevious() -
getNext
public boolean getNext()Synonym forhasNext()
.- Returns:
- true if a next page is available.
-
hasNext
public boolean hasNext() -
pageCount
public long pageCount() -
getCount
Returns total count of records based on provided criteria.- Returns:
- total count of records based on provided criteria
-