It can be seen that Hibernate is very flexible in querying pages. Hibernate will first try the paging SQL of a specific database. If not, try Scrollable again. If not, finally, rset is used. next.
(1) pager class
* @ (#) Pager. java 2005-5-3
*
* Copyright (c) 2005, Jeffrey Hsu
*/
Package com. jeffrey. messagelove;
/**
* Pager holds the page info.
*/
Public class Pager {
Private int totalRows = 0; // total number of records
Private int totalPages = 0; // total number of pages
Private int pageSize = 10; // The number of data entries per page. The default value is 10.
Private int currentPage = 1; // current page number
Private boolean hasPrevious = false; // whether the previous page exists
Private boolean hasNext = false; // whether the next page exists
Public Pager (){
}
/**
* Initialize Pager
* @ Param totalRows total record rows
* @ Param pageSize total record is hold by every page
*/
Public void init (int totalRows, int pageSize ){
This. totalRows = totalRows;
This. pageSize = pageSize;
TotalPages = (totalRows + pageSize)-1)/pageSize;
Refresh (); // refresh the current page
}
/**
* @ Return Returns the currentPage.
*/
Public int getCurrentPage (){
Return currentPage;
}
/**
* @ Param currentPage current page
*/
Public void setCurrentPage (int currentPage ){
This. currentPage = currentPage;
Refresh ();
}
/**
* @ Return Returns the pageSize.
*/
Public int getPageSize (){
Return pageSize;
}
/**
* @ Param pageSize The pageSize to set.
*/
Public void setPageSize (int pageSize ){
This. pageSize = pageSize;
Refresh ();
}
/**
* @ Return Returns the totalPages.
*/
Public int getTotalPages (){
Return totalPages;
}
/**
* @ Param totalPages The totalPages to set.
*/
Public void setTotalPages (int totalPages ){
This. totalPages = totalPages;
Refresh ();
}
/**
* @ Return Returns the totalRows.
*/
Public int getTotalRows (){
Return totalRows;
}
/**
* @ Param totalRows The totalRows to set.
*/
Public void setTotalRows (int totalRows ){
This. totalRows = totalRows;
Refresh ();
}
// Jump to the first page
Public void first (){
CurrentPage = 1;
This. setHasPrevious (false );
Refresh ();
}
// Retrieve the previous page (reset the current page)
Public void previous (){
CurrentPage --;
Refresh ();
}
// Get the next page
Public void next (){
System. out. println ("next: totalPages:" + totalPages +
"CurrentPage:" + currentPage );
If (currentPage <totalPages ){
CurrentPage ++;
}
Refresh ();
}
// Jump to the last page
Public void last (){
CurrentPage = totalPages;
This. setHasNext (false );
Refresh ();
}
Public boolean isHasNext (){
Return hasNext;
}
/**
* @ Param hasNext The hasNext to set.
*/
Public void setHasNext (boolean hasNext ){
This. hasNext = hasNext;
}
Public boolean isHasPrevious (){
Return hasPrevious;
}
/**
* @ Param hasPrevious The hasPrevious to set.
*/
Public void setHasPrevious (boolean hasPrevious ){
This. hasPrevious = hasPrevious;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.