Module bus.pager

Class PageContext

All Implemented Interfaces:
BoundSqlBuilder.Chain, Dialect

public class PageContext extends PageMethod implements Dialect, BoundSqlBuilder.Chain
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_PAGE

    Fields inherited from interface org.miaixz.bus.pager.builder.BoundSqlBuilder.Chain

    DO_NOTHING
  • 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.
    afterPage(List pageList, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds)
    Called after the pagination query has been executed to process the results.
    <T> Future<T>
    Executes an asynchronous count query task, ensuring that ThreadLocal values are properly propagated.
    boolean
    beforeCount(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds)
    Called before executing the count query.
    boolean
    beforePage(org.apache.ibatis.mapping.MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds)
    Called before executing the pagination query.
    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.
    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.
    boolean
    Checks 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.
    void
    Sets the properties for the PageContext, initializing internal components like PageParams, PageAutoDialect, and PageBoundSqlBuilder.
    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 current Page settings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 current Page settings.
      Specified by:
      skip in interface Dialect
      Parameters:
      ms - the MappedStatement object
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      Returns:
      true to skip and return default query results, false to proceed with pagination query
    • isAsyncCount

      public boolean isAsyncCount()
      Checks if asynchronous count queries are enabled for the current page.
      Specified by:
      isAsyncCount in interface Dialect
      Returns:
      true if asynchronous count queries are enabled, false otherwise
    • asyncCountTask

      public <T> Future<T> asyncCountTask(Callable<T> task)
      Executes an asynchronous count query task, ensuring that ThreadLocal values are properly propagated.
      Specified by:
      asyncCountTask in interface Dialect
      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:
      beforeCount in interface Dialect
      Parameters:
      ms - the MappedStatement object
      parameterObject - the parameter object for the query
      rowBounds - 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:
      getCountSql in interface Dialect
      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. Delegates to the current database dialect.
      Specified by:
      afterCount in interface Dialect
      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 before the query is executed. Delegates to the current database dialect.
      Specified by:
      processParameterObject in interface Dialect
      Parameters:
      ms - the MappedStatement object
      parameterObject - the 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
    • 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:
      beforePage in interface Dialect
      Parameters:
      ms - the MappedStatement object
      parameterObject - the parameter object for the query
      rowBounds - 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:
      getPageSql in interface Dialect
      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 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 string
      page - the Page object containing pagination details
      rowBounds - the RowBounds object containing pagination parameters
      pageKey - 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.
      Specified by:
      afterPage in interface Dialect
      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
    • 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.
      Specified by:
      afterAll in interface Dialect
    • 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:
      doBoundSql in interface BoundSqlBuilder.Chain
      Parameters:
      type - the type of BoundSql operation (e.g., COUNT, PAGE)
      boundSql - the original BoundSql object
      cacheKey - the CacheKey for the SQL operation
      Returns:
      the processed BoundSql object
    • setProperties

      public void setProperties(Properties properties)
      Sets the properties for the PageContext, initializing internal components like PageParams, PageAutoDialect, and PageBoundSqlBuilder. It also configures the asynchronous count service.
      Specified by:
      setProperties in interface Dialect
      Parameters:
      properties - the properties to set