java.lang.Object
org.miaixz.bus.pager.binding.PageMethod
org.miaixz.bus.pager.PageContext
- All Implemented Interfaces:
BoundSqlBuilder.Chain,Dialect
Mybatis - Universal Paging Interceptor. This class extends
PageMethod and implements Dialect and
BoundSqlBuilder.Chain to provide comprehensive pagination functionality, including SQL dialect handling,
parameter processing, and asynchronous count queries.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from class org.miaixz.bus.pager.binding.PageMethod
DEFAULT_COUNT, LOCAL_PAGEFields inherited from interface org.miaixz.bus.pager.builder.BoundSqlBuilder.Chain
DO_NOTHING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll()Called after all pagination tasks are completed.booleanafterCount(long count, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called after the count query has been executed.Called after the pagination query has been executed to process the results.<T> Future<T> asyncCountTask(Callable<T> task) Executes an asynchronous count query task, ensuring thatThreadLocalvalues are properly propagated.booleanbeforeCount(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called before executing the count query.booleanbeforePage(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called before executing the pagination query.org.apache.ibatis.mapping.BoundSqldoBoundSql(BoundSqlBuilder.Type type, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey cacheKey) Processes the BoundSql chain for different types of SQL operations.getCountSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey countKey) Generates the SQL for the count query.getPageSql(String sql, Page page, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey pageKey) Generates the SQL for the paginated query using a raw SQL string.getPageSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey pageKey) Generates the SQL for the paginated query.booleanChecks if asynchronous count queries are enabled for the current page.processParameterObject(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey pageKey) Processes the parameter object before the query is executed.voidsetProperties(Properties properties) Sets the properties for the PageContext, initializing internal components likePageParams,PageAutoDialect, andPageBoundSqlBuilder.booleanskip(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Determines whether to skip the count query and pagination query based on the currentPagesettings.Methods inherited from class org.miaixz.bus.pager.binding.PageMethod
clearPage, count, getLocalPage, offsetPage, offsetPage, orderBy, setLocalPage, setStaticProperties, startPage, startPage, startPage, startPage, startPage
-
Constructor Details
-
PageContext
public PageContext()
-
-
Method Details
-
skip
public boolean skip(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Determines whether to skip the count query and pagination query based on the currentPagesettings. -
isAsyncCount
public boolean isAsyncCount()Checks if asynchronous count queries are enabled for the current page.- Specified by:
isAsyncCountin interfaceDialect- Returns:
- true if asynchronous count queries are enabled, false otherwise
-
asyncCountTask
Executes an asynchronous count query task, ensuring thatThreadLocalvalues are properly propagated.- Specified by:
asyncCountTaskin interfaceDialect- Type Parameters:
T- the type of the result of the task- Parameters:
task- the asynchronous query task- Returns:
- a Future representing the pending completion of the task
-
beforeCount
public boolean beforeCount(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called before executing the count query. Delegates to the current database dialect.- Specified by:
beforeCountin interfaceDialect- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- true to proceed with count query, false to skip to
beforePage
-
getCountSql
public String getCountSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey countKey) Generates the SQL for the count query. Delegates to the current database dialect.- Specified by:
getCountSqlin interfaceDialect- Parameters:
ms- the MappedStatement objectboundSql- the BoundSql object containing the original SQL and parametersparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameterscountKey- the CacheKey for the count query- Returns:
- the generated count SQL string
-
afterCount
public boolean afterCount(long count, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called after the count query has been executed. Delegates to the current database dialect.- Specified by:
afterCountin interfaceDialect- Parameters:
count- the total number of records found by the count queryparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- true to continue with the pagination query, false to return immediately
-
processParameterObject
public Object processParameterObject(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey pageKey) Processes the parameter object before the query is executed. Delegates to the current database dialect.- Specified by:
processParameterObjectin interfaceDialect- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryboundSql- the BoundSql object containing the original SQL and parameterspageKey- the CacheKey for the paginated query- Returns:
- the processed parameter object
-
beforePage
public boolean beforePage(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called before executing the pagination query. Delegates to the current database dialect.- Specified by:
beforePagein interfaceDialect- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- true to proceed with pagination query, false to return default results
-
getPageSql
public String getPageSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey pageKey) Generates the SQL for the paginated query. Delegates to the current database dialect.- Specified by:
getPageSqlin interfaceDialect- Parameters:
ms- the MappedStatement objectboundSql- the BoundSql object containing the original SQL and parametersparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameterspageKey- the CacheKey for the paginated query- Returns:
- the generated paginated SQL string
-
getPageSql
public String getPageSql(String sql, Page page, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey pageKey) Generates the SQL for the paginated query using a raw SQL string.- Parameters:
sql- the original SQL stringpage- thePageobject containing pagination detailsrowBounds- the RowBounds object containing pagination parameterspageKey- the CacheKey for the paginated query- Returns:
- the generated paginated SQL string
-
afterPage
public Object afterPage(List pageList, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Called after the pagination query has been executed to process the results. Delegates to the current database dialect. This method will be executed even if pagination is skipped, so a null check for the delegate is performed. -
afterAll
public void afterAll()Called after all pagination tasks are completed. Clears the delegate and the page context. This method will be executed even if pagination is skipped, so a null check for the delegate is performed. -
doBoundSql
public org.apache.ibatis.mapping.BoundSql doBoundSql(BoundSqlBuilder.Type type, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey cacheKey) Processes the BoundSql chain for different types of SQL operations.- Specified by:
doBoundSqlin interfaceBoundSqlBuilder.Chain- Parameters:
type- the type of BoundSql operation (e.g., COUNT, PAGE)boundSql- the original BoundSql objectcacheKey- the CacheKey for the SQL operation- Returns:
- the processed BoundSql object
-
setProperties
Sets the properties for the PageContext, initializing internal components likePageParams,PageAutoDialect, andPageBoundSqlBuilder. It also configures the asynchronous count service.- Specified by:
setPropertiesin interfaceDialect- Parameters:
properties- the properties to set
-