Module bus.pager

Class Page<E>

Type Parameters:
E - the type of elements in this page
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>

public class Page<E> extends ArrayList<E> implements Closeable
MyBatis paging object, supporting paginated queries and result set management. This class extends ArrayList to hold the paginated data and implements Closeable to manage the paging context.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • Page

      public Page()
      Default constructor.
    • Page

      public Page(int pageNo, int pageSize)
      Constructs a Page object with specified page number and page size.
      Parameters:
      pageNo - the page number (starts from 1)
      pageSize - the size of the page
    • Page

      public Page(int pageNo, int pageSize, boolean count)
      Constructs a Page object with specified page number, page size, and whether to perform a count query.
      Parameters:
      pageNo - the page number (starts from 1)
      pageSize - the size of the page
      count - true to perform a count query, false otherwise
    • Page

      public Page(int[] rowBounds, boolean count)
      Constructs a Page object based on row bounds for pagination.
      Parameters:
      rowBounds - an array containing row bounds, where index 0 is offset and index 1 is limit
      count - true to perform a count query, false otherwise
  • Method Details

    • getStackTrace

      public String getStackTrace()
      Retrieves the stack trace where this Page object was created.
      Returns:
      the stack trace information
    • getResult

      public List<E> getResult()
      Retrieves the paginated result set.
      Returns:
      a list of paginated data
    • getPages

      public int getPages()
      Retrieves the total number of pages.
      Returns:
      the total number of pages
    • setPages

      public Page<E> setPages(int pages)
      Sets the total number of pages.
      Parameters:
      pages - the total number of pages
      Returns:
      the current Page object
    • getEndRow

      public long getEndRow()
      Retrieves the ending row position.
      Returns:
      the ending row position
    • setEndRow

      public Page<E> setEndRow(long endRow)
      Sets the ending row position.
      Parameters:
      endRow - the ending row position
      Returns:
      the current Page object
    • getPageNo

      public int getPageNo()
      Retrieves the current page number.
      Returns:
      the current page number
    • setPageNo

      public Page<E> setPageNo(int pageNo)
      Sets the page number, with support for reasonableness handling. If reasonableness is enabled and pageNo is less than or equal to 0, it will be set to 1.
      Parameters:
      pageNo - the page number
      Returns:
      the current Page object
    • getPageSize

      public int getPageSize()
      Retrieves the page size.
      Returns:
      the page size
    • setPageSize

      public Page<E> setPageSize(int pageSize)
      Sets the page size.
      Parameters:
      pageSize - the page size
      Returns:
      the current Page object
    • getStartRow

      public long getStartRow()
      Retrieves the starting row position.
      Returns:
      the starting row position
    • setStartRow

      public Page<E> setStartRow(long startRow)
      Sets the starting row position.
      Parameters:
      startRow - the starting row position
      Returns:
      the current Page object
    • getTotal

      public long getTotal()
      Retrieves the total number of records.
      Returns:
      the total number of records
    • setTotal

      public void setTotal(long total)
      Sets the total number of records and calculates the total number of pages.
      Parameters:
      total - the total number of records
    • getReasonable

      public Boolean getReasonable()
      Retrieves the state of the pagination reasonableness switch.
      Returns:
      the state of the reasonableness switch
    • setReasonable

      public Page<E> setReasonable(Boolean reasonable)
      Sets the pagination reasonableness switch. If reasonableness is enabled and the current page number is less than or equal to 0, it will be set to 1.
      Parameters:
      reasonable - the reasonableness switch
      Returns:
      the current Page object
    • getPageSizeZero

      public Boolean getPageSizeZero()
      Retrieves the state of the pageSizeZero switch.
      Returns:
      the state of the pageSizeZero switch
    • setPageSizeZero

      public Page<E> setPageSizeZero(Boolean pageSizeZero)
      Sets the pageSizeZero switch. If true, and pageSize is 0, all results are returned without pagination.
      Parameters:
      pageSizeZero - true if pageSize 0 should return all results, false otherwise
      Returns:
      the current Page object
    • getOrderBy

      public String getOrderBy()
      Retrieves the order by clause.
      Returns:
      the order by clause
    • setOrderBy

      public <E> Page<E> setOrderBy(String orderBy)
      Sets the order by clause.
      Type Parameters:
      E - the type of elements in this page
      Parameters:
      orderBy - the order by clause
      Returns:
      the current Page object
    • setUnsafeOrderBy

      public <E> Page<E> setUnsafeOrderBy(String orderBy)
      Sets the order by clause unsafely. This method does not perform SQL injection checks, so ensure the orderBy parameter is safe.
      Type Parameters:
      E - the type of elements in this page
      Parameters:
      orderBy - the order by clause
      Returns:
      the current Page object
    • isOrderByOnly

      public boolean isOrderByOnly()
      Checks if only ordering should be applied without pagination.
      Returns:
      true if only ordering should be applied, false otherwise
    • setOrderByOnly

      public void setOrderByOnly(boolean orderByOnly)
      Sets whether only ordering should be applied without pagination.
      Parameters:
      orderByOnly - true if only ordering should be applied, false otherwise
    • getDialectClass

      public String getDialectClass()
      Retrieves the dialect class used for pagination.
      Returns:
      the dialect class name
    • setDialectClass

      public void setDialectClass(String dialectClass)
      Sets the dialect class used for pagination.
      Parameters:
      dialectClass - the dialect class name
    • getKeepOrderBy

      public Boolean getKeepOrderBy()
      Retrieves whether to retain the order by clause in the count query.
      Returns:
      true if the order by clause should be retained, false otherwise
    • setKeepOrderBy

      public Page<E> setKeepOrderBy(Boolean keepOrderBy)
      Sets whether to retain the order by clause in the count query.
      Parameters:
      keepOrderBy - true if the order by clause should be retained, false otherwise
      Returns:
      the current Page object
    • getKeepSubSelectOrderBy

      public Boolean getKeepSubSelectOrderBy()
      Retrieves whether to retain the order by clause of sub-queries in the count query.
      Returns:
      true if the order by clause of sub-queries should be retained, false otherwise
    • setKeepSubSelectOrderBy

      public void setKeepSubSelectOrderBy(Boolean keepSubSelectOrderBy)
      Sets whether to retain the order by clause of sub-queries in the count query.
      Parameters:
      keepSubSelectOrderBy - true if the order by clause of sub-queries should be retained, false otherwise
    • getAsyncCount

      public Boolean getAsyncCount()
      Retrieves whether asynchronous count queries are enabled.
      Returns:
      true if asynchronous count queries are enabled, false otherwise
    • setAsyncCount

      public void setAsyncCount(Boolean asyncCount)
      Sets whether asynchronous count queries are enabled.
      Parameters:
      asyncCount - true to enable asynchronous count queries, false otherwise
    • using

      public Page<E> using(String dialect)
      Specifies the pagination implementation to use.
      Parameters:
      dialect - the dialect class name, can use aliases registered in PageAutoDialect like "mysql", "oracle"
      Returns:
      the current Page object
    • isCount

      public boolean isCount()
      Checks if a count query should be executed.
      Returns:
      true if a count query should be executed, false otherwise
    • setCount

      public Page<E> setCount(boolean count)
      Sets whether a count query should be executed.
      Parameters:
      count - true to execute a count query, false otherwise
      Returns:
      the current Page object
    • pageNo

      public Page<E> pageNo(int pageNo)
      Sets the page number. If reasonableness is enabled and pageNo is less than or equal to 0, it will be set to 1.
      Parameters:
      pageNo - the page number
      Returns:
      the current Page object
    • pageSize

      public Page<E> pageSize(int pageSize)
      Sets the page size.
      Parameters:
      pageSize - the page size
      Returns:
      the current Page object
    • count

      public Page<E> count(Boolean count)
      Sets whether a count query should be executed.
      Parameters:
      count - true to execute a count query, false otherwise
      Returns:
      the current Page object
    • reasonable

      public Page<E> reasonable(Boolean reasonable)
      Sets the pagination reasonableness switch.
      Parameters:
      reasonable - the pagination reasonableness switch
      Returns:
      the current Page object
    • pageSizeZero

      public Page<E> pageSizeZero(Boolean pageSizeZero)
      Sets the pageSizeZero switch.
      Parameters:
      pageSizeZero - true if pageSize 0 should return all results, false otherwise
      Returns:
      the current Page object
    • boundSqlInterceptor

      public Page<E> boundSqlInterceptor(BoundSqlBuilder boundSqlHandler)
      Sets the BoundSql interceptor.
      Parameters:
      boundSqlHandler - the BoundSql interceptor
      Returns:
      the current Page object
    • countColumn

      public Page<E> countColumn(String columnName)
      Specifies the column name for the count query.
      Parameters:
      columnName - the column name
      Returns:
      the current Page object
    • keepOrderBy

      public Page<E> keepOrderBy(boolean keepOrderBy)
      Sets whether to retain the order by clause in the count query.
      Parameters:
      keepOrderBy - true if the order by clause should be retained, false otherwise
      Returns:
      the current Page object
    • keepOrderBy

      public boolean keepOrderBy()
      Checks if the order by clause should be retained in the count query.
      Returns:
      true if the order by clause should be retained, false otherwise
    • keepSubSelectOrderBy

      public Page<E> keepSubSelectOrderBy(boolean keepSubSelectOrderBy)
      Sets whether to retain the order by clause of sub-queries in the count query.
      Parameters:
      keepSubSelectOrderBy - true if the order by clause of sub-queries should be retained, false otherwise
      Returns:
      the current Page object
    • keepSubSelectOrderBy

      public boolean keepSubSelectOrderBy()
      Checks if the order by clause of sub-queries should be retained in the count query.
      Returns:
      true if the order by clause of sub-queries should be retained, false otherwise
    • asyncCount

      public Page<E> asyncCount(boolean asyncCount)
      Sets whether asynchronous count queries are enabled.
      Parameters:
      asyncCount - true to enable asynchronous count queries, false otherwise
      Returns:
      the current Page object
    • enableAsyncCount

      public Page<E> enableAsyncCount()
      Enables asynchronous count queries.
      Returns:
      the current Page object
    • disableAsyncCount

      public Page<E> disableAsyncCount()
      Disables asynchronous count queries.
      Returns:
      the current Page object
    • asyncCount

      public boolean asyncCount()
      Checks if asynchronous count queries are enabled.
      Returns:
      true if asynchronous count queries are enabled, false otherwise
    • toPageInfo

      public Paginating<E> toPageInfo()
      Converts the current Page object to a Paginating object.
      Returns:
      a Paginating object
    • toPageInfo

      public <T> Paginating<T> toPageInfo(org.miaixz.bus.core.center.function.FunctionX<E,T> function)
      Converts the paginated data and returns a Paginating object.
      Type Parameters:
      T - the type of the converted data elements
      Parameters:
      function - the data conversion function
      Returns:
      a Paginating object with converted data
    • toPageSerializable

      public Serialize<E> toPageSerializable()
      Converts the current Page object to a Serialize object.
      Returns:
      a Serialize object
    • toPageSerializable

      public <T> Serialize<T> toPageSerializable(org.miaixz.bus.core.center.function.FunctionX<E,T> function)
      Converts the paginated data and returns a Serialize object.
      Type Parameters:
      T - the type of the converted data elements
      Parameters:
      function - the data conversion function
      Returns:
      a Serialize object with converted data
    • doSelectPage

      public <E> Page<E> doSelectPage(Querying select)
      Executes a paginated query.
      Type Parameters:
      E - the type of elements in this page
      Parameters:
      select - the query object
      Returns:
      the current Page object
    • doSelectPageInfo

      public <E> Paginating<E> doSelectPageInfo(Querying select)
      Executes a paginated query and returns a Paginating object.
      Type Parameters:
      E - the type of elements in this page
      Parameters:
      select - the query object
      Returns:
      a Paginating object
    • doSelectPageSerializable

      public <E> Serialize<E> doSelectPageSerializable(Querying select)
      Executes a paginated query and returns a Serialize object.
      Type Parameters:
      E - the type of elements in this page
      Parameters:
      select - the query object
      Returns:
      a Serialize object
    • doCount

      public long doCount(Querying select)
      Executes a count query.
      Parameters:
      select - the query object
      Returns:
      the total number of records
    • getCountColumn

      public String getCountColumn()
      Retrieves the column name used for the count query.
      Returns:
      the count query column name
    • setCountColumn

      public void setCountColumn(String countColumn)
      Sets the column name for the count query, including SQL injection validation.
      Parameters:
      countColumn - the column name
    • getBoundSqlInterceptor

      public BoundSqlBuilder getBoundSqlInterceptor()
      Retrieves the BoundSql interceptor.
      Returns:
      the BoundSql interceptor
    • setBoundSqlInterceptor

      public void setBoundSqlInterceptor(BoundSqlBuilder boundSqlHandler)
      Sets the BoundSql interceptor.
      Parameters:
      boundSqlHandler - the BoundSql interceptor
    • toString

      public String toString()
      Returns a string representation of the Page object.
      Overrides:
      toString in class AbstractCollection<E>
      Returns:
      a string representation of the object
    • close

      public void close()
      Closes the Page object and clears the paging context. This method is part of the Closeable interface implementation.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable