Module bus.pager

Class PageAutoDialect

java.lang.Object
org.miaixz.bus.pager.binding.PageAutoDialect

public class PageAutoDialect extends Object
Provides automatic identification and configuration of database pagination dialects. This class manages a mapping of dialect aliases to their implementations and handles the dynamic selection of the appropriate dialect based on the database connection.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • PageAutoDialect

      public PageAutoDialect()
  • Method Details

    • registerDialectAlias

      public static void registerDialectAlias(String alias, Class<? extends Dialect> dialectClass)
      Registers a database dialect alias with its corresponding implementation class.
      Parameters:
      alias - the alias for the dialect (e.g., "mysql", "oracle")
      dialectClass - the Dialect implementation class
    • registerAutoDialectAlias

      public static void registerAutoDialectAlias(String alias, Class<? extends AutoDialect> autoDialectClass)
      Registers an auto-dialect alias with its corresponding implementation class.
      Parameters:
      alias - the alias for the auto-dialect
      autoDialectClass - the AutoDialect implementation class
    • fromJdbcUrl

      public static String fromJdbcUrl(String jdbcUrl)
      Extracts the dialect name from a JDBC URL.
      Parameters:
      jdbcUrl - the JDBC URL string
      Returns:
      the dialect name if recognized, otherwise null
    • resloveDialectClass

      public static Class resloveDialectClass(String className) throws Exception
      Resolves a dialect class from its name or alias.
      Parameters:
      className - the dialect class name or alias
      Returns:
      the resolved dialect implementation class
      Throws:
      Exception - if the class does not exist or cannot be loaded
    • instanceDialect

      public static AbstractPaging instanceDialect(String dialectClass, Properties properties)
      Instantiates a dialect object from its class name or alias.
      Parameters:
      dialectClass - the dialect class name or alias
      properties - the properties to set on the dialect instance
      Returns:
      an instance of AbstractPaging
      Throws:
      org.miaixz.bus.core.lang.exception.PageException - if instantiation fails or the class is not a valid dialect implementation
    • getDelegate

      public AbstractPaging getDelegate()
      Retrieves the current dialect delegate. If a thread-local dialect is set, it returns that; otherwise, it returns the default delegate.
      Returns:
      the current AbstractPaging instance
    • clearDelegate

      public void clearDelegate()
      Clears the thread-local dialect delegate.
    • getDialectThreadLocal

      public AbstractPaging getDialectThreadLocal()
      Retrieves the thread-local dialect instance.
      Returns:
      the thread-local AbstractPaging instance
    • setDialectThreadLocal

      public void setDialectThreadLocal(AbstractPaging delegate)
      Sets the thread-local dialect instance.
      Parameters:
      delegate - the AbstractPaging instance to set for the current thread
    • initDelegateDialect

      public void initDelegateDialect(org.apache.ibatis.mapping.MappedStatement ms, String dialectClass)
      Initializes the dialect delegate, supporting runtime specification of the dialect. If a specific dialect class is provided, it will be used. Otherwise, it attempts to auto-detect the dialect.
      Parameters:
      ms - the MyBatis MappedStatement
      dialectClass - the dialect implementation class name or alias (e.g., "mysql", "oracle"), can be null for auto-detection
    • autoGetDialect

      public AbstractPaging autoGetDialect(org.apache.ibatis.mapping.MappedStatement ms)
      Automatically retrieves the pagination dialect implementation based on the MappedStatement and DataSource.
      Parameters:
      ms - the MyBatis MappedStatement
      Returns:
      an instance of AbstractPaging representing the detected dialect
    • setProperties

      public void setProperties(Properties properties)
      Sets the pagination configuration properties for this PageAutoDialect instance. This method initializes auto-dialect settings, registers custom dialect aliases, and sets the default dialect.
      Parameters:
      properties - the properties to set