java.lang.Object
org.miaixz.bus.pager.binding.CountExecutor
Utility class for executing count queries in MyBatis pagination. This class handles the creation and execution of
count SQL, as well as parameter processing.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LongexecuteAutoCount(Dialect dialect, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement countMs, Object parameter, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler) Executes an automatically generated count query.static LongexecuteManualCount(org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement countMs, Object parameter, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.session.ResultHandler resultHandler) Executes a manually configured count query.getAdditionalParameter(org.apache.ibatis.mapping.BoundSql boundSql) Retrieves the `additionalParameters` map from aBoundSqlobject using reflection.static org.apache.ibatis.mapping.MappedStatementgetExistedMappedStatement(org.apache.ibatis.session.Configuration configuration, String msId) Attempts to retrieve an already existingMappedStatementfrom the configuration.static String[]getProviderMethodArgumentNames(org.apache.ibatis.builder.annotation.ProviderSqlSource providerSqlSource) Retrieves the `providerMethodArgumentNames` array from aProviderSqlSourceobject using reflection.static <E> List<E> pageQuery(Dialect dialect, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement ms, Object parameter, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey cacheKey) Executes a paginated query.
-
Constructor Details
-
CountExecutor
public CountExecutor()
-
-
Method Details
-
getAdditionalParameter
public static Map<String,Object> getAdditionalParameter(org.apache.ibatis.mapping.BoundSql boundSql) Retrieves the `additionalParameters` map from aBoundSqlobject using reflection.- Parameters:
boundSql- the BoundSql object- Returns:
- a map of additional parameters
- Throws:
org.miaixz.bus.core.lang.exception.PageException- if anIllegalAccessExceptionoccurs during field access
-
getProviderMethodArgumentNames
public static String[] getProviderMethodArgumentNames(org.apache.ibatis.builder.annotation.ProviderSqlSource providerSqlSource) Retrieves the `providerMethodArgumentNames` array from aProviderSqlSourceobject using reflection. This method is used for compatibility with different MyBatis versions.- Parameters:
providerSqlSource- the ProviderSqlSource object- Returns:
- an array of provider method argument names, or null if the field does not exist or cannot be accessed
- Throws:
org.miaixz.bus.core.lang.exception.PageException- if anIllegalAccessExceptionoccurs during field access
-
getExistedMappedStatement
public static org.apache.ibatis.mapping.MappedStatement getExistedMappedStatement(org.apache.ibatis.session.Configuration configuration, String msId) Attempts to retrieve an already existingMappedStatementfrom the configuration. This supports custom count and page MappedStatements.- Parameters:
configuration- the MyBatis configurationmsId- the ID of the MappedStatement to retrieve- Returns:
- the MappedStatement if found, otherwise null
-
executeManualCount
public static Long executeManualCount(org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement countMs, Object parameter, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.session.ResultHandler resultHandler) throws SQLException Executes a manually configured count query. The parameters for this query must be the same as the paginated method.- Parameters:
executor- the MyBatis executorcountMs- the MappedStatement for the count queryparameter- the parameter object for the queryboundSql- the BoundSql object for the original queryresultHandler- the result handler for the query- Returns:
- the total count of records
- Throws:
SQLException- if a database access error occurs
-
executeAutoCount
public static Long executeAutoCount(Dialect dialect, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement countMs, Object parameter, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler) throws SQLException Executes an automatically generated count query.- Parameters:
dialect- the database dialect to useexecutor- the MyBatis executorcountMs- the MappedStatement for the count queryparameter- the parameter object for the queryboundSql- the BoundSql object for the original queryrowBounds- the RowBounds object containing pagination parametersresultHandler- the result handler for the query- Returns:
- the total count of records
- Throws:
SQLException- if a database access error occurs
-
pageQuery
public static <E> List<E> pageQuery(Dialect dialect, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement ms, Object parameter, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey cacheKey) throws SQLException Executes a paginated query.- Type Parameters:
E- the type of elements in the result list- Parameters:
dialect- the database dialect to useexecutor- the MyBatis executorms- the MappedStatement for the queryparameter- the parameter object for the queryrowBounds- the RowBounds object containing pagination parametersresultHandler- the result handler for the queryboundSql- the BoundSql object for the original querycacheKey- the CacheKey for the query- Returns:
- a list of paginated results
- Throws:
SQLException- if a database access error occurs
-