java.lang.Object
org.miaixz.bus.pager.binding.PageAutoDialect
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionautoGetDialect(org.apache.ibatis.mapping.MappedStatement ms) Automatically retrieves the pagination dialect implementation based on the MappedStatement and DataSource.voidClears the thread-local dialect delegate.static StringfromJdbcUrl(String jdbcUrl) Extracts the dialect name from a JDBC URL.Retrieves the current dialect delegate.Retrieves the thread-local dialect instance.voidinitDelegateDialect(org.apache.ibatis.mapping.MappedStatement ms, String dialectClass) Initializes the dialect delegate, supporting runtime specification of the dialect.static AbstractPaginginstanceDialect(String dialectClass, Properties properties) Instantiates a dialect object from its class name or alias.static voidregisterAutoDialectAlias(String alias, Class<? extends AutoDialect> autoDialectClass) Registers an auto-dialect alias with its corresponding implementation class.static voidregisterDialectAlias(String alias, Class<? extends Dialect> dialectClass) Registers a database dialect alias with its corresponding implementation class.static ClassresloveDialectClass(String className) Resolves a dialect class from its name or alias.voidsetDialectThreadLocal(AbstractPaging delegate) Sets the thread-local dialect instance.voidsetProperties(Properties properties) Sets the pagination configuration properties for thisPageAutoDialectinstance.
-
Constructor Details
-
PageAutoDialect
public PageAutoDialect()
-
-
Method Details
-
registerDialectAlias
Registers a database dialect alias with its corresponding implementation class.- Parameters:
alias- the alias for the dialect (e.g., "mysql", "oracle")dialectClass- theDialectimplementation 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-dialectautoDialectClass- theAutoDialectimplementation class
-
fromJdbcUrl
Extracts the dialect name from a JDBC URL.- Parameters:
jdbcUrl- the JDBC URL string- Returns:
- the dialect name if recognized, otherwise null
-
resloveDialectClass
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
Instantiates a dialect object from its class name or alias.- Parameters:
dialectClass- the dialect class name or aliasproperties- 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
Retrieves the current dialect delegate. If a thread-local dialect is set, it returns that; otherwise, it returns the default delegate.- Returns:
- the current
AbstractPaginginstance
-
clearDelegate
public void clearDelegate()Clears the thread-local dialect delegate. -
getDialectThreadLocal
Retrieves the thread-local dialect instance.- Returns:
- the thread-local
AbstractPaginginstance
-
setDialectThreadLocal
Sets the thread-local dialect instance.- Parameters:
delegate- theAbstractPaginginstance to set for the current thread
-
initDelegateDialect
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 MappedStatementdialectClass- the dialect implementation class name or alias (e.g., "mysql", "oracle"), can be null for auto-detection
-
autoGetDialect
Automatically retrieves the pagination dialect implementation based on the MappedStatement and DataSource.- Parameters:
ms- the MyBatis MappedStatement- Returns:
- an instance of
AbstractPagingrepresenting the detected dialect
-
setProperties
Sets the pagination configuration properties for thisPageAutoDialectinstance. This method initializes auto-dialect settings, registers custom dialect aliases, and sets the default dialect.- Parameters:
properties- the properties to set
-