Package com.jk.data.dynamic.paging
Class DataBasePager
java.lang.Object
com.jk.data.dynamic.paging.DataBasePager
- All Implemented Interfaces:
DataPager
This class implements the
DataPager
interface to allow paging through
database query results.
It provides methods to query a database, retrieve the total number of rows, and navigate through pages of data.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
This method gets the total number of rows in the data set.int
This method gets the current page number.int
This method gets the number of rows displayed on the current page.int
This method gets the total number of pages in the data set.getQuery()
This method gets the SQL query used for retrieving data from the database.This method gets the cached query result set.static void
This main method demonstrate the usage of this class.void
This method moves to the first page in the data set.void
This method moves to the last page in the data set.void
This method moves to the next page in the data set.void
moveToPage
(int page) This method moves to a specific page in the data set.void
This method moves to the previous page in the data set.void
setDatasource
(JKDataSource datasource) void
setPageRowsCount
(int pageRowsCount) This method sets the number of rows to be displayed on each page.void
This method sets the SQL query to retrieve data from the database and calculates the number of pages based on the total row count and page size.
-
Constructor Details
-
DataBasePager
public DataBasePager()This method constructs a newDataBasePager
.
-
-
Method Details
-
main
This main method demonstrate the usage of this class.- Parameters:
args
- the command-line arguments.
-
getAllRowsCount
public int getAllRowsCount()This method gets the total number of rows in the data set.- Specified by:
getAllRowsCount
in interfaceDataPager
- Returns:
- the total number of rows in the data set.
-
getCurrentPage
public int getCurrentPage()This method gets the current page number.- Specified by:
getCurrentPage
in interfaceDataPager
- Returns:
- the current page number.
-
getPageRowsCount
public int getPageRowsCount()This method gets the number of rows displayed on the current page.- Specified by:
getPageRowsCount
in interfaceDataPager
- Returns:
- the number of rows on the current page.
-
getPagesCount
public int getPagesCount()This method gets the total number of pages in the data set.- Specified by:
getPagesCount
in interfaceDataPager
- Returns:
- the total number of pages.
-
getQuery
This method gets the SQL query used for retrieving data from the database.- Returns:
- the SQL query.
-
getResultSet
This method gets the cached query result set.- Returns:
- the the query result set.
-
moveToFirstPage
This method moves to the first page in the data set.- Specified by:
moveToFirstPage
in interfaceDataPager
- Throws:
PagingException
- if an error occurs while navigating to the first page.
-
moveToLastPage
This method moves to the last page in the data set.- Specified by:
moveToLastPage
in interfaceDataPager
- Throws:
PagingException
- if an error occurs while navigating to the last page.
-
moveToNextPage
This method moves to the next page in the data set.- Specified by:
moveToNextPage
in interfaceDataPager
- Throws:
PagingException
- if an error occurs while navigating to the next page.
-
moveToPage
public void moveToPage(int page) This method moves to a specific page in the data set.- Specified by:
moveToPage
in interfaceDataPager
- Parameters:
page
- Specifies the page number to move to.
-
moveToPreviousePage
This method moves to the previous page in the data set.- Specified by:
moveToPreviousePage
in interfaceDataPager
- Throws:
PagingException
- if an error occurs while navigating to the previous page.
-
setDatasource
-
setPageRowsCount
public void setPageRowsCount(int pageRowsCount) This method sets the number of rows to be displayed on each page.- Specified by:
setPageRowsCount
in interfaceDataPager
- Parameters:
pageRowsCount
- Specifies the new number of rows per page.
-
setQuery
This method sets the SQL query to retrieve data from the database and calculates the number of pages based on the total row count and page size.- Parameters:
query
- Specifies the SQL query.
-