java.lang.Object
org.miaixz.bus.pager.dialect.AbstractDialect
org.miaixz.bus.pager.dialect.AbstractPaging
- All Implemented Interfaces:
Dialect
- Direct Known Subclasses:
AS400,CirroData,Db2,Firebird,HerdDB,Hsqldb,Informix,MySql,Oracle,Oracle9i,Oscar,PostgreSql,SqlServer,Xugudb
Abstract base class for pagination dialect implementations, specifically for
PageContext. This class provides
common logic for handling pagination, including SQL generation, parameter processing, and result handling, while
delegating database-specific SQL generation to subclasses.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringKey for the first pagination parameter in the parameter map.static StringKey for the second pagination parameter in the parameter map.static StringSuffix for the count query ID, used to identify count MappedStatements.static StringSuffix for the page ID, used to identify paginated MappedStatements.Fields inherited from class org.miaixz.bus.pager.dialect.AbstractDialect
countSqlParser, orderBySqlParser -
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 to process the count result.Called after the pagination query has been executed to process the results.booleanbeforeCount(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Determines whether a count query should be executed before the main pagination query.booleanbeforePage(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Determines whether the main pagination query should be executed.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.<T> Page<T> Retrieves thePageobject associated with the current thread.abstract StringgetPageSql(String sql, Page page, org.apache.ibatis.cache.CacheKey pageKey) Abstract method to generate the database-specific pagination SQL.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.protected voidhandleParameter(org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.mapping.MappedStatement ms, Class<?> firstClass, Class<?> secondClass) Handles the injection of pagination parameters into theBoundSqlby adding newParameterMappingentries for the first and second pagination parameters.abstract ObjectprocessPageParameter(org.apache.ibatis.mapping.MappedStatement ms, Map<String, Object> paramMap, Page page, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey pageKey) Abstract method to process pagination parameters, to be implemented by concrete dialect classes.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 for pagination.voidsetProperties(Properties properties) Sets the properties for this dialect.final booleanskip(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) This method is not intended to be called directly in this implementation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.pager.Dialect
asyncCountTask, isAsyncCount
-
Field Details
-
SUFFIX_PAGE
Suffix for the page ID, used to identify paginated MappedStatements. -
SUFFIX_COUNT
Suffix for the count query ID, used to identify count MappedStatements. -
PAGEPARAMETER_FIRST
Key for the first pagination parameter in the parameter map. -
PAGEPARAMETER_SECOND
Key for the second pagination parameter in the parameter map.
-
-
Constructor Details
-
AbstractPaging
public AbstractPaging()
-
-
Method Details
-
getLocalPage
Retrieves thePageobject associated with the current thread.- Type Parameters:
T- the type of elements in the paginated data- Returns:
- the current Page object
-
skip
public final boolean skip(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) This method is not intended to be called directly in this implementation. Always returns true to indicate that the skip logic is handled elsewhere.- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- always true
-
beforeCount
public boolean beforeCount(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) Determines whether a count query should be executed before the main pagination query. A count query is executed if the currentPageis not set toorderByOnlyandcountis enabled.- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- true if a count query should be executed, false otherwise
-
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. It usesCountSqlParserto get a smart count SQL.- Specified by:
getCountSqlin interfaceDialect- Overrides:
getCountSqlin classAbstractDialect- 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 to process the count result. It sets the total count in thePageobject and determines if the main pagination query should proceed.- 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 for pagination. This method handles various parameter types and injects pagination-specific parameters into the parameter map.- Parameters:
ms- the MappedStatement objectparameterObject- the original 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, typically a Map containing all necessary parameters
-
processPageParameter
public abstract Object processPageParameter(org.apache.ibatis.mapping.MappedStatement ms, Map<String, Object> paramMap, Page page, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey pageKey) Abstract method to process pagination parameters, to be implemented by concrete dialect classes.- Parameters:
ms- the MappedStatement objectparamMap- a map containing the query parameterspage- thePageobject containing pagination detailsboundSql- the BoundSql object for the querypageKey- 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) Determines whether the main pagination query should be executed. It proceeds if the page is set toorderByOnlyor ifpageSizeis greater than 0.- Parameters:
ms- the MappedStatement objectparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- true if the pagination query should be executed, false otherwise
-
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. It applies the order by clause if specified in thePageobject, and then delegates to an abstract method for database-specific pagination SQL generation.- 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
Abstract method to generate the database-specific pagination SQL. To be implemented by concrete dialect classes.- Parameters:
sql- the original SQL stringpage- thePageobject containing pagination detailspageKey- the CacheKey for the paginated query- Returns:
- the database-specific 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. It adds the results to thePageobject and sets the total count if applicable.- Parameters:
pageList- the list of results from the paginated queryparameterObject- the parameter object for the queryrowBounds- the RowBounds object containing pagination parameters- Returns:
- the processed paginated results, typically the
Pageobject itself
-
afterAll
public void afterAll()Called after all pagination tasks are completed. This implementation does nothing. -
setProperties
Sets the properties for this dialect. Delegates to the superclass to set common properties.- Specified by:
setPropertiesin interfaceDialect- Overrides:
setPropertiesin classAbstractDialect- Parameters:
properties- the properties to set
-
handleParameter
protected void handleParameter(org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.mapping.MappedStatement ms, Class<?> firstClass, Class<?> secondClass) Handles the injection of pagination parameters into theBoundSqlby adding newParameterMappingentries for the first and second pagination parameters.- Parameters:
boundSql- the BoundSql object to modifyms- the MappedStatement objectfirstClass- the class type for the first pagination parametersecondClass- the class type for the second pagination parameter
-