public class Paginator<T extends Model> extends Object implements Serializable
Cached
, then this class will
cache the total count of records returned by getCount()
, as LazyList will cache the result sets.
This class is thread safe and the same instance could be used across multiple web requests and even
across multiple users/sessions. You can generate an instance each time you need one,
or you can cache an instance in a session or even servlet context.Constructor and Description |
---|
Paginator(Class<? extends T> modelClass,
int pageSize,
boolean suppressCounts,
String query,
Object... params)
Convenience constructor.
|
Paginator(Class<? extends T> modelClass,
int pageSize,
boolean suppressCounts,
String query,
String countQuery,
Object... params)
Paginator is created with parameters to jump to chunks of result sets (pages).
|
Paginator(Class<? extends T> modelClass,
int pageSize,
String query,
Object... params)
Convenience constructor.
|
Modifier and Type | Method and Description |
---|---|
Long |
getCount()
Returns total count of records based on provided criteria.
|
int |
getCurrentPage()
Returns index of current page, or 0 if this instance has not produced a page yet.
|
boolean |
getNext()
Synonym for
hasNext() . |
LazyList<T> |
getPage(int pageNumber)
This method will return a list of records for a specific page.
|
int |
getPageSize() |
boolean |
getPrevious()
Synonym for
hasPrevious() . |
boolean |
hasNext() |
boolean |
hasPrevious() |
static <E extends Model> |
instance()
Use to create a paginator instance, and provide arguments as needed.
|
Paginator |
orderBy(String orderBys)
Use to set order by(s).
|
long |
pageCount() |
public Paginator(Class<? extends T> modelClass, int pageSize, String query, Object... params)
Paginator(Class, int, String, Object...)
and passes true for suppressCounts
.public Paginator(Class<? extends T> modelClass, int pageSize, boolean suppressCounts, String query, Object... params)
Paginator(Class, int, String, Object...)
and passes null for countQuery
.public Paginator(Class<? extends T> modelClass, int pageSize, boolean suppressCounts, String query, String countQuery, Object... params)
"last_name like '%John%'"
- this is a sub-query, and the rest of the information will be filled out
by this classmodelClass
- model class mapped to a table.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.params
- a set of parameters if a query is parametrized (has question marks '?').query
- this is a query that will be applied every time a new page is requested; this
query should not contain limit, offset or order by clauses of any kind, Paginator will do this automatically.
This parameter can have two forms, a sub-query or a full query.public Paginator orderBy(String orderBys)
"category, created_at desc"
orderBys
- a comma-separated list of field names followed by either "desc" or "asc"public LazyList<T> getPage(int pageNumber)
pageNumber
- page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will
be rejected.public int getCurrentPage()
public boolean getPrevious()
hasPrevious()
.public boolean hasPrevious()
public boolean getNext()
hasNext()
.public boolean hasNext()
public long pageCount()
public Long getCount()
public int getPageSize()
public static <E extends Model> org.javalite.activejdbc.Paginator.PaginatorBuilder<E> instance()
Copyright © 2016 JavaLite. All rights reserved.