Module bus.pager

Class AbstractPaging

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

public abstract class AbstractPaging extends AbstractDialect
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

    Fields
    Modifier and Type
    Field
    Description
    static String
    Key for the first pagination parameter in the parameter map.
    static String
    Key for the second pagination parameter in the parameter map.
    static String
    Suffix for the count query ID, used to identify count MappedStatements.
    static String
    Suffix for the page ID, used to identify paginated MappedStatements.

    Fields inherited from class org.miaixz.bus.pager.dialect.AbstractDialect

    countSqlParser, orderBySqlParser
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called after all pagination tasks are completed.
    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.
    afterPage(List pageList, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds)
    Called after the pagination query has been executed to process the results.
    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.
    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.
    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 the Page object associated with the current thread.
    abstract String
    getPageSql(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 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 the BoundSql by adding new ParameterMapping entries for the first and second pagination parameters.
    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.
    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.
    void
    Sets the properties for this dialect.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.pager.Dialect

    asyncCountTask, isAsyncCount
  • Field Details

    • SUFFIX_PAGE

      public static String SUFFIX_PAGE
      Suffix for the page ID, used to identify paginated MappedStatements.
    • SUFFIX_COUNT

      public static String SUFFIX_COUNT
      Suffix for the count query ID, used to identify count MappedStatements.
    • PAGEPARAMETER_FIRST

      public static String PAGEPARAMETER_FIRST
      Key for the first pagination parameter in the parameter map.
    • PAGEPARAMETER_SECOND

      public static String PAGEPARAMETER_SECOND
      Key for the second pagination parameter in the parameter map.
  • Constructor Details

    • AbstractPaging

      public AbstractPaging()
  • Method Details

    • getLocalPage

      public <T> Page<T> getLocalPage()
      Retrieves the Page object 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 object
      parameterObject - the parameter object for the query
      rowBounds - 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 current Page is not set to orderByOnly and count is enabled.
      Parameters:
      ms - the MappedStatement object
      parameterObject - the parameter object for the query
      rowBounds - 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 uses CountSqlParser to get a smart count SQL.
      Specified by:
      getCountSql in interface Dialect
      Overrides:
      getCountSql in class AbstractDialect
      Parameters:
      ms - the MappedStatement object
      boundSql - the BoundSql object containing the original SQL and parameters
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      countKey - 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 the Page object and determines if the main pagination query should proceed.
      Parameters:
      count - the total number of records found by the count query
      parameterObject - the parameter object for the query
      rowBounds - 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 object
      parameterObject - the original parameter object for the query
      boundSql - the BoundSql object containing the original SQL and parameters
      pageKey - 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 object
      paramMap - a map containing the query parameters
      page - the Page object containing pagination details
      boundSql - the BoundSql object for the query
      pageKey - 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 to orderByOnly or if pageSize is greater than 0.
      Parameters:
      ms - the MappedStatement object
      parameterObject - the parameter object for the query
      rowBounds - 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 the Page object, and then delegates to an abstract method for database-specific pagination SQL generation.
      Parameters:
      ms - the MappedStatement object
      boundSql - the BoundSql object containing the original SQL and parameters
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      pageKey - the CacheKey for the paginated query
      Returns:
      the generated paginated SQL string
    • getPageSql

      public abstract String getPageSql(String sql, Page page, org.apache.ibatis.cache.CacheKey pageKey)
      Abstract method to generate the database-specific pagination SQL. To be implemented by concrete dialect classes.
      Parameters:
      sql - the original SQL string
      page - the Page object containing pagination details
      pageKey - 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 the Page object and sets the total count if applicable.
      Parameters:
      pageList - the list of results from the paginated query
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      Returns:
      the processed paginated results, typically the Page object itself
    • afterAll

      public void afterAll()
      Called after all pagination tasks are completed. This implementation does nothing.
    • setProperties

      public void setProperties(Properties properties)
      Sets the properties for this dialect. Delegates to the superclass to set common properties.
      Specified by:
      setProperties in interface Dialect
      Overrides:
      setProperties in class AbstractDialect
      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 the BoundSql by adding new ParameterMapping entries for the first and second pagination parameters.
      Parameters:
      boundSql - the BoundSql object to modify
      ms - the MappedStatement object
      firstClass - the class type for the first pagination parameter
      secondClass - the class type for the second pagination parameter