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.
You can generate an instance each time you need one, or you can cache an instance in a session or even servlet context.Modifier and Type | Class and Description |
---|---|
static class |
Paginator.PaginatorBuilder<T extends Model>
Provides a builder pattern to create new instances of paginator.
|
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.
|
long |
getFrom()
Returns index of the first item in a current page.
|
boolean |
getNext()
Synonym for
hasNext() . |
LazyList<T> |
getPage() |
LazyList<T> |
getPage(int pageNumber)
This method will return a list of records for a specific page.
|
int |
getPageSize() |
boolean |
getPrevious()
Synonym for
hasPrevious() . |
long |
getTo()
Returns index of the last item in a current page.
|
boolean |
hasNext() |
boolean |
hasPrevious() |
static <E extends Model> |
instance()
Use to create a paginator instance, and provide arguments as needed.
|
Paginator<T> |
orderBy(String orderBys)
Use to set order by(s).
|
long |
pageCount() |
void |
setCurrentPageIndex(int currentPageIndex,
boolean skipCheck)
Sets an index of a current page.
|
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<T> 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> Paginator.PaginatorBuilder<E> instance()
public void setCurrentPageIndex(int currentPageIndex, boolean skipCheck)
currentPageIndex
- index of a current page.skipCheck
- true
to skip the upper boundary check (will not make a call to DB).public long getFrom()
Displaying 101 to 140 items
ir something similar.public long getTo()
Displaying 101 to 140 items
ir something similar.Copyright © 2019 JavaLite. All rights reserved.