HHH-13993 Bootstrap analysis: avoid initializing many Dialect classes
This commit is contained in:
parent
fcc5c150c0
commit
bbdefc2487
|
@ -0,0 +1,281 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.boot.registry.selector.internal;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.CUBRIDDialect;
|
||||||
|
import org.hibernate.dialect.Cache71Dialect;
|
||||||
|
import org.hibernate.dialect.DB2390Dialect;
|
||||||
|
import org.hibernate.dialect.DB2390V8Dialect;
|
||||||
|
import org.hibernate.dialect.DB2400Dialect;
|
||||||
|
import org.hibernate.dialect.DB2400V7R3Dialect;
|
||||||
|
import org.hibernate.dialect.DB2Dialect;
|
||||||
|
import org.hibernate.dialect.DerbyTenFiveDialect;
|
||||||
|
import org.hibernate.dialect.DerbyTenSevenDialect;
|
||||||
|
import org.hibernate.dialect.DerbyTenSixDialect;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.dialect.FirebirdDialect;
|
||||||
|
import org.hibernate.dialect.FrontBaseDialect;
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
import org.hibernate.dialect.HANAColumnStoreDialect;
|
||||||
|
import org.hibernate.dialect.HANARowStoreDialect;
|
||||||
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
|
import org.hibernate.dialect.InformixDialect;
|
||||||
|
import org.hibernate.dialect.Ingres10Dialect;
|
||||||
|
import org.hibernate.dialect.Ingres9Dialect;
|
||||||
|
import org.hibernate.dialect.IngresDialect;
|
||||||
|
import org.hibernate.dialect.InterbaseDialect;
|
||||||
|
import org.hibernate.dialect.JDataStoreDialect;
|
||||||
|
import org.hibernate.dialect.MckoiDialect;
|
||||||
|
import org.hibernate.dialect.MimerSQLDialect;
|
||||||
|
import org.hibernate.dialect.MySQL57Dialect;
|
||||||
|
import org.hibernate.dialect.MySQL57InnoDBDialect;
|
||||||
|
import org.hibernate.dialect.MySQL5Dialect;
|
||||||
|
import org.hibernate.dialect.MySQL5InnoDBDialect;
|
||||||
|
import org.hibernate.dialect.MySQL8Dialect;
|
||||||
|
import org.hibernate.dialect.Oracle10gDialect;
|
||||||
|
import org.hibernate.dialect.Oracle8iDialect;
|
||||||
|
import org.hibernate.dialect.Oracle9iDialect;
|
||||||
|
import org.hibernate.dialect.PointbaseDialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL9Dialect;
|
||||||
|
import org.hibernate.dialect.PostgresPlusDialect;
|
||||||
|
import org.hibernate.dialect.ProgressDialect;
|
||||||
|
import org.hibernate.dialect.SAPDBDialect;
|
||||||
|
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||||
|
import org.hibernate.dialect.SQLServer2008Dialect;
|
||||||
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
|
import org.hibernate.dialect.Sybase11Dialect;
|
||||||
|
import org.hibernate.dialect.SybaseASE157Dialect;
|
||||||
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
|
import org.hibernate.dialect.SybaseAnywhereDialect;
|
||||||
|
import org.hibernate.dialect.TeradataDialect;
|
||||||
|
import org.hibernate.dialect.TimesTenDialect;
|
||||||
|
|
||||||
|
public class DefaultDialectSelector implements LazyServiceResolver<Dialect> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Dialect> resolve(final String name) {
|
||||||
|
Objects.requireNonNull( name);
|
||||||
|
if ( name.isEmpty() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//Let's organize all string matches in groups by first letter:
|
||||||
|
final char n = name.charAt( 0 );
|
||||||
|
switch ( n ) {
|
||||||
|
case 'C': return caseC( name );
|
||||||
|
case 'D': return caseD( name );
|
||||||
|
case 'F': return caseF( name );
|
||||||
|
case 'H': return caseH( name );
|
||||||
|
case 'I': return caseI( name );
|
||||||
|
case 'J': return caseJ( name );
|
||||||
|
case 'M': return caseM( name );
|
||||||
|
case 'O': return caseO( name );
|
||||||
|
case 'P': return caseP( name );
|
||||||
|
case 'S': return caseS( name );
|
||||||
|
case 'T': return caseT( name );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseC(final String name) {
|
||||||
|
if ( name.equals( "Cache71" ) ) {
|
||||||
|
return Cache71Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "CUBRID" ) ) {
|
||||||
|
return CUBRIDDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseD(final String name) {
|
||||||
|
if ( name.equals( "DB2" ) ) {
|
||||||
|
return DB2Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DB2390" ) ) {
|
||||||
|
return DB2390Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DB2390V8" ) ) {
|
||||||
|
return DB2390V8Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DB2400" ) ) {
|
||||||
|
return DB2400Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DB2400V7R3" ) ) {
|
||||||
|
return DB2400V7R3Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DerbyTenFive" ) ) {
|
||||||
|
return DerbyTenFiveDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DerbyTenSix" ) ) {
|
||||||
|
return DerbyTenSixDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "DerbyTenSeven" ) ) {
|
||||||
|
return DerbyTenSevenDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseF(final String name) {
|
||||||
|
if ( name.equals( "Firebird" ) ) {
|
||||||
|
return FirebirdDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "FrontBase" ) ) {
|
||||||
|
return FrontBaseDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseH(final String name) {
|
||||||
|
if ( name.equals( "H2" ) ) {
|
||||||
|
return H2Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "HANAColumnStore" ) ) {
|
||||||
|
return HANAColumnStoreDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "HANARowStore" ) ) {
|
||||||
|
return HANARowStoreDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "HSQL" ) ) {
|
||||||
|
return HSQLDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseI(final String name) {
|
||||||
|
if ( name.equals( "Informix" ) ) {
|
||||||
|
return InformixDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Ingres" ) ) {
|
||||||
|
return IngresDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Ingres9" ) ) {
|
||||||
|
return Ingres9Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Ingres10" ) ) {
|
||||||
|
return Ingres10Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Interbase" ) ) {
|
||||||
|
return InterbaseDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseJ(final String name) {
|
||||||
|
if ( name.equals( "JDataStore" ) ) {
|
||||||
|
return JDataStoreDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseM(final String name) {
|
||||||
|
if ( name.equals( "Mckoi" ) ) {
|
||||||
|
return MckoiDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MimerSQL" ) ) {
|
||||||
|
return MimerSQLDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MySQL5" ) ) {
|
||||||
|
return MySQL5Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MySQL5InnoDB" ) ) {
|
||||||
|
return MySQL5InnoDBDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MySQL57InnoDB" ) ) {
|
||||||
|
return MySQL57InnoDBDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MySQL57" ) ) {
|
||||||
|
return MySQL57Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "MySQL8" ) ) {
|
||||||
|
return MySQL8Dialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseO(final String name) {
|
||||||
|
if ( name.equals( "Oracle8i" ) ) {
|
||||||
|
return Oracle8iDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Oracle9i" ) ) {
|
||||||
|
return Oracle9iDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Oracle10g" ) ) {
|
||||||
|
return Oracle10gDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseP(final String name) {
|
||||||
|
if ( name.equals( "Pointbase" ) ) {
|
||||||
|
return PointbaseDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "PostgresPlus" ) ) {
|
||||||
|
return PostgresPlusDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "PostgreSQL81" ) ) {
|
||||||
|
return PostgreSQL81Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "PostgreSQL82" ) ) {
|
||||||
|
return PostgreSQL82Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "PostgreSQL9" ) ) {
|
||||||
|
return PostgreSQL9Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Progress" ) ) {
|
||||||
|
return ProgressDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseS(final String name) {
|
||||||
|
if ( name.equals( "SAPDB" ) ) {
|
||||||
|
return SAPDBDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SQLServer" ) ) {
|
||||||
|
return SQLServerDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SQLServer2005" ) ) {
|
||||||
|
return SQLServer2005Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SQLServer2008" ) ) {
|
||||||
|
return SQLServer2008Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Sybase11" ) ) {
|
||||||
|
return Sybase11Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SybaseAnywhere" ) ) {
|
||||||
|
return SybaseAnywhereDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "Sybase11" ) ) {
|
||||||
|
return Sybase11Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SybaseAnywhere" ) ) {
|
||||||
|
return SybaseAnywhereDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SybaseASE15" ) ) {
|
||||||
|
return SybaseASE15Dialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "SybaseASE157" ) ) {
|
||||||
|
return SybaseASE157Dialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Dialect> caseT(final String name) {
|
||||||
|
if ( name.equals( "Teradata" ) ) {
|
||||||
|
return TeradataDialect.class;
|
||||||
|
}
|
||||||
|
if ( name.equals( "TimesTen" ) ) {
|
||||||
|
return TimesTenDialect.class;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.boot.registry.selector.internal;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface LazyServiceResolver<T> {
|
||||||
|
|
||||||
|
Class<? extends T> resolve(String name);
|
||||||
|
|
||||||
|
}
|
|
@ -23,55 +23,7 @@ import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
||||||
import org.hibernate.cache.internal.SimpleCacheKeysFactory;
|
import org.hibernate.cache.internal.SimpleCacheKeysFactory;
|
||||||
import org.hibernate.cache.spi.CacheKeysFactory;
|
import org.hibernate.cache.spi.CacheKeysFactory;
|
||||||
import org.hibernate.dialect.CUBRIDDialect;
|
|
||||||
import org.hibernate.dialect.Cache71Dialect;
|
|
||||||
import org.hibernate.dialect.DB2390Dialect;
|
|
||||||
import org.hibernate.dialect.DB2390V8Dialect;
|
|
||||||
import org.hibernate.dialect.DB2400Dialect;
|
|
||||||
import org.hibernate.dialect.DB2400V7R3Dialect;
|
|
||||||
import org.hibernate.dialect.DB2Dialect;
|
|
||||||
import org.hibernate.dialect.DerbyTenFiveDialect;
|
|
||||||
import org.hibernate.dialect.DerbyTenSevenDialect;
|
|
||||||
import org.hibernate.dialect.DerbyTenSixDialect;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.FirebirdDialect;
|
|
||||||
import org.hibernate.dialect.FrontBaseDialect;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
|
||||||
import org.hibernate.dialect.HANAColumnStoreDialect;
|
|
||||||
import org.hibernate.dialect.HANARowStoreDialect;
|
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
|
||||||
import org.hibernate.dialect.InformixDialect;
|
|
||||||
import org.hibernate.dialect.Ingres10Dialect;
|
|
||||||
import org.hibernate.dialect.Ingres9Dialect;
|
|
||||||
import org.hibernate.dialect.IngresDialect;
|
|
||||||
import org.hibernate.dialect.InterbaseDialect;
|
|
||||||
import org.hibernate.dialect.JDataStoreDialect;
|
|
||||||
import org.hibernate.dialect.MckoiDialect;
|
|
||||||
import org.hibernate.dialect.MimerSQLDialect;
|
|
||||||
import org.hibernate.dialect.MySQL57Dialect;
|
|
||||||
import org.hibernate.dialect.MySQL57InnoDBDialect;
|
|
||||||
import org.hibernate.dialect.MySQL8Dialect;
|
|
||||||
import org.hibernate.dialect.MySQL5Dialect;
|
|
||||||
import org.hibernate.dialect.MySQL5InnoDBDialect;
|
|
||||||
import org.hibernate.dialect.Oracle10gDialect;
|
|
||||||
import org.hibernate.dialect.Oracle8iDialect;
|
|
||||||
import org.hibernate.dialect.Oracle9iDialect;
|
|
||||||
import org.hibernate.dialect.PointbaseDialect;
|
|
||||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
|
||||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
|
||||||
import org.hibernate.dialect.PostgreSQL9Dialect;
|
|
||||||
import org.hibernate.dialect.PostgresPlusDialect;
|
|
||||||
import org.hibernate.dialect.ProgressDialect;
|
|
||||||
import org.hibernate.dialect.SAPDBDialect;
|
|
||||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
|
||||||
import org.hibernate.dialect.SQLServer2008Dialect;
|
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
|
||||||
import org.hibernate.dialect.Sybase11Dialect;
|
|
||||||
import org.hibernate.dialect.SybaseASE157Dialect;
|
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
|
||||||
import org.hibernate.dialect.SybaseAnywhereDialect;
|
|
||||||
import org.hibernate.dialect.TeradataDialect;
|
|
||||||
import org.hibernate.dialect.TimesTenDialect;
|
|
||||||
import org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform;
|
||||||
import org.hibernate.engine.transaction.jta.platform.internal.BitronixJtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.internal.BitronixJtaPlatform;
|
||||||
import org.hibernate.engine.transaction.jta.platform.internal.BorlandEnterpriseServerJtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.internal.BorlandEnterpriseServerJtaPlatform;
|
||||||
|
@ -90,10 +42,6 @@ import org.hibernate.engine.transaction.jta.platform.internal.WebSphereJtaPlatfo
|
||||||
import org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform;
|
||||||
import org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform;
|
||||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||||
import org.hibernate.event.internal.EntityCopyAllowedLoggedObserver;
|
|
||||||
import org.hibernate.event.internal.EntityCopyAllowedObserver;
|
|
||||||
import org.hibernate.event.internal.EntityCopyNotAllowedObserver;
|
|
||||||
import org.hibernate.event.spi.EntityCopyObserver;
|
|
||||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||||
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
|
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
|
||||||
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
|
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
|
||||||
|
@ -163,7 +111,7 @@ public class StrategySelectorBuilder {
|
||||||
final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
|
final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
|
||||||
|
|
||||||
// build the baseline...
|
// build the baseline...
|
||||||
addDialects( strategySelector );
|
strategySelector.registerStrategyLazily( Dialect.class, new DefaultDialectSelector() );
|
||||||
addJtaPlatforms( strategySelector );
|
addJtaPlatforms( strategySelector );
|
||||||
addTransactionCoordinatorBuilders( strategySelector );
|
addTransactionCoordinatorBuilders( strategySelector );
|
||||||
addMultiTableBulkIdStrategies( strategySelector );
|
addMultiTableBulkIdStrategies( strategySelector );
|
||||||
|
@ -196,65 +144,6 @@ public class StrategySelectorBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDialects(StrategySelectorImpl strategySelector) {
|
|
||||||
addDialect( strategySelector, Cache71Dialect.class );
|
|
||||||
addDialect( strategySelector, CUBRIDDialect.class );
|
|
||||||
addDialect( strategySelector, DB2Dialect.class );
|
|
||||||
addDialect( strategySelector, DB2390Dialect.class );
|
|
||||||
addDialect( strategySelector, DB2390V8Dialect.class );
|
|
||||||
addDialect( strategySelector, DB2400Dialect.class );
|
|
||||||
addDialect( strategySelector, DB2400V7R3Dialect.class );
|
|
||||||
addDialect( strategySelector, DerbyTenFiveDialect.class );
|
|
||||||
addDialect( strategySelector, DerbyTenSixDialect.class );
|
|
||||||
addDialect( strategySelector, DerbyTenSevenDialect.class );
|
|
||||||
addDialect( strategySelector, FirebirdDialect.class );
|
|
||||||
addDialect( strategySelector, FrontBaseDialect.class );
|
|
||||||
addDialect( strategySelector, H2Dialect.class );
|
|
||||||
addDialect( strategySelector, HANAColumnStoreDialect.class );
|
|
||||||
addDialect( strategySelector, HANARowStoreDialect.class );
|
|
||||||
addDialect( strategySelector, HSQLDialect.class );
|
|
||||||
addDialect( strategySelector, InformixDialect.class );
|
|
||||||
addDialect( strategySelector, IngresDialect.class );
|
|
||||||
addDialect( strategySelector, Ingres9Dialect.class );
|
|
||||||
addDialect( strategySelector, Ingres10Dialect.class );
|
|
||||||
addDialect( strategySelector, InterbaseDialect.class );
|
|
||||||
addDialect( strategySelector, JDataStoreDialect.class );
|
|
||||||
addDialect( strategySelector, MckoiDialect.class );
|
|
||||||
addDialect( strategySelector, MimerSQLDialect.class );
|
|
||||||
addDialect( strategySelector, MySQL5Dialect.class );
|
|
||||||
addDialect( strategySelector, MySQL5InnoDBDialect.class );
|
|
||||||
addDialect( strategySelector, MySQL57InnoDBDialect.class );
|
|
||||||
addDialect( strategySelector, MySQL57Dialect.class );
|
|
||||||
addDialect( strategySelector, MySQL8Dialect.class );
|
|
||||||
addDialect( strategySelector, Oracle8iDialect.class );
|
|
||||||
addDialect( strategySelector, Oracle9iDialect.class );
|
|
||||||
addDialect( strategySelector, Oracle10gDialect.class );
|
|
||||||
addDialect( strategySelector, PointbaseDialect.class );
|
|
||||||
addDialect( strategySelector, PostgresPlusDialect.class );
|
|
||||||
addDialect( strategySelector, PostgreSQL81Dialect.class );
|
|
||||||
addDialect( strategySelector, PostgreSQL82Dialect.class );
|
|
||||||
addDialect( strategySelector, PostgreSQL9Dialect.class );
|
|
||||||
addDialect( strategySelector, ProgressDialect.class );
|
|
||||||
addDialect( strategySelector, SAPDBDialect.class );
|
|
||||||
addDialect( strategySelector, SQLServerDialect.class );
|
|
||||||
addDialect( strategySelector, SQLServer2005Dialect.class );
|
|
||||||
addDialect( strategySelector, SQLServer2008Dialect.class );
|
|
||||||
addDialect( strategySelector, Sybase11Dialect.class );
|
|
||||||
addDialect( strategySelector, SybaseAnywhereDialect.class );
|
|
||||||
addDialect( strategySelector, SybaseASE15Dialect.class );
|
|
||||||
addDialect( strategySelector, SybaseASE157Dialect.class );
|
|
||||||
addDialect( strategySelector, TeradataDialect.class );
|
|
||||||
addDialect( strategySelector, TimesTenDialect.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDialect(StrategySelectorImpl strategySelector, Class<? extends Dialect> dialectClass) {
|
|
||||||
String simpleName = dialectClass.getSimpleName();
|
|
||||||
if ( simpleName.endsWith( "Dialect" ) ) {
|
|
||||||
simpleName = simpleName.substring( 0, simpleName.length() - "Dialect".length() );
|
|
||||||
}
|
|
||||||
strategySelector.registerStrategyImplementor( Dialect.class, simpleName, dialectClass );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addJtaPlatforms(StrategySelectorImpl strategySelector) {
|
private void addJtaPlatforms(StrategySelectorImpl strategySelector) {
|
||||||
addJtaPlatforms(
|
addJtaPlatforms(
|
||||||
strategySelector,
|
strategySelector,
|
||||||
|
|
|
@ -13,7 +13,9 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategyCreator;
|
import org.hibernate.boot.registry.selector.spi.StrategyCreator;
|
||||||
|
@ -28,10 +30,10 @@ import org.jboss.logging.Logger;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class StrategySelectorImpl implements StrategySelector {
|
public class StrategySelectorImpl implements StrategySelector {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger( StrategySelectorImpl.class );
|
private static final Logger log = Logger.getLogger( StrategySelectorImpl.class );
|
||||||
|
|
||||||
|
private static final StrategyCreator STANDARD_STRATEGY_CREATOR = strategyClass -> {
|
||||||
public static final StrategyCreator STANDARD_STRATEGY_CREATOR = strategyClass -> {
|
|
||||||
try {
|
try {
|
||||||
return strategyClass.newInstance();
|
return strategyClass.newInstance();
|
||||||
}
|
}
|
||||||
|
@ -43,8 +45,14 @@ public class StrategySelectorImpl implements StrategySelector {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Map based approach: most suited for explicit registrations from integrators
|
||||||
private final Map<Class,Map<String,Class>> namedStrategyImplementorByStrategyMap = new ConcurrentHashMap<>();
|
private final Map<Class,Map<String,Class>> namedStrategyImplementorByStrategyMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
//"Lazy" approach: more efficient as we aim to not initialize all implementation classes;
|
||||||
|
//this is preferable for internal services such as Dialect, as we have a significant amount of them, making
|
||||||
|
//it worthwhile to try be a bit more efficient about them.
|
||||||
|
private final Map<Class, LazyServiceResolver> lazyStrategyImplementorByStrategyMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final ClassLoaderService classLoaderService;
|
private final ClassLoaderService classLoaderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,6 +64,13 @@ public class StrategySelectorImpl implements StrategySelector {
|
||||||
this.classLoaderService = classLoaderService;
|
this.classLoaderService = classLoaderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> void registerStrategyLazily(Class<T> strategy, LazyServiceResolver<T> resolver) {
|
||||||
|
LazyServiceResolver previous = lazyStrategyImplementorByStrategyMap.put( strategy, resolver );
|
||||||
|
if ( previous != null ) {
|
||||||
|
throw new HibernateException( "Detected a second LazyServiceResolver replacing an existing LazyServiceResolver implementation for strategy " + strategy.getName() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation) {
|
public <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation) {
|
||||||
Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
|
Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
|
||||||
|
@ -125,6 +140,14 @@ public class StrategySelectorImpl implements StrategySelector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LazyServiceResolver lazyServiceResolver = lazyStrategyImplementorByStrategyMap.get( strategy );
|
||||||
|
if ( lazyServiceResolver != null ) {
|
||||||
|
Class resolve = lazyServiceResolver.resolve( name );
|
||||||
|
if ( resolve != null ) {
|
||||||
|
return resolve;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return classLoaderService.classForName( name );
|
return classLoaderService.classForName( name );
|
||||||
}
|
}
|
||||||
|
@ -177,6 +200,10 @@ public class StrategySelectorImpl implements StrategySelector {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Collection getRegisteredStrategyImplementors(Class strategy) {
|
public Collection getRegisteredStrategyImplementors(Class strategy) {
|
||||||
|
LazyServiceResolver lazyServiceResolver = lazyStrategyImplementorByStrategyMap.get( strategy );
|
||||||
|
if ( lazyServiceResolver != null ) {
|
||||||
|
throw new StrategySelectionException( "Can't use this method on for strategy types which are embedded in the core library" );
|
||||||
|
}
|
||||||
final Map<String, Class> registrations = namedStrategyImplementorByStrategyMap.get( strategy );
|
final Map<String, Class> registrations = namedStrategyImplementorByStrategyMap.get( strategy );
|
||||||
if ( registrations == null ) {
|
if ( registrations == null ) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.strategyselectors;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.selector.internal.DefaultDialectSelector;
|
||||||
|
import org.hibernate.dialect.*;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DefaultDialectSelectorTest {
|
||||||
|
|
||||||
|
private DefaultDialectSelector strategySelector = new DefaultDialectSelector();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyAllDialectNamingResolve() {
|
||||||
|
testDialectNamingResolution( Cache71Dialect.class );
|
||||||
|
testDialectNamingResolution( CUBRIDDialect.class );
|
||||||
|
testDialectNamingResolution( DB2Dialect.class );
|
||||||
|
testDialectNamingResolution( DB2390Dialect.class );
|
||||||
|
testDialectNamingResolution( DB2390V8Dialect.class );
|
||||||
|
testDialectNamingResolution( DB2400Dialect.class );
|
||||||
|
testDialectNamingResolution( DB2400V7R3Dialect.class );
|
||||||
|
testDialectNamingResolution( DerbyTenFiveDialect.class );
|
||||||
|
testDialectNamingResolution( DerbyTenSixDialect.class );
|
||||||
|
testDialectNamingResolution( DerbyTenSevenDialect.class );
|
||||||
|
testDialectNamingResolution( FirebirdDialect.class );
|
||||||
|
testDialectNamingResolution( FrontBaseDialect.class );
|
||||||
|
testDialectNamingResolution( H2Dialect.class );
|
||||||
|
testDialectNamingResolution( HANAColumnStoreDialect.class );
|
||||||
|
testDialectNamingResolution( HANARowStoreDialect.class );
|
||||||
|
testDialectNamingResolution( HSQLDialect.class );
|
||||||
|
testDialectNamingResolution( InformixDialect.class );
|
||||||
|
testDialectNamingResolution( IngresDialect.class );
|
||||||
|
testDialectNamingResolution( Ingres9Dialect.class );
|
||||||
|
testDialectNamingResolution( Ingres10Dialect.class );
|
||||||
|
testDialectNamingResolution( InterbaseDialect.class );
|
||||||
|
testDialectNamingResolution( JDataStoreDialect.class );
|
||||||
|
|
||||||
|
testDialectNamingResolution( MckoiDialect.class );
|
||||||
|
testDialectNamingResolution( MimerSQLDialect.class );
|
||||||
|
testDialectNamingResolution( MySQL5Dialect.class );
|
||||||
|
testDialectNamingResolution( MySQL5InnoDBDialect.class );
|
||||||
|
testDialectNamingResolution( MySQL57InnoDBDialect.class );
|
||||||
|
testDialectNamingResolution( MySQL57Dialect.class );
|
||||||
|
testDialectNamingResolution( MySQL8Dialect.class );
|
||||||
|
testDialectNamingResolution( Oracle8iDialect.class );
|
||||||
|
testDialectNamingResolution( Oracle9iDialect.class );
|
||||||
|
testDialectNamingResolution( Oracle10gDialect.class );
|
||||||
|
|
||||||
|
testDialectNamingResolution( PointbaseDialect.class );
|
||||||
|
testDialectNamingResolution( PostgresPlusDialect.class );
|
||||||
|
testDialectNamingResolution( PostgreSQL81Dialect.class );
|
||||||
|
testDialectNamingResolution( PostgreSQL82Dialect.class );
|
||||||
|
testDialectNamingResolution( PostgreSQL9Dialect.class );
|
||||||
|
testDialectNamingResolution( ProgressDialect.class );
|
||||||
|
|
||||||
|
testDialectNamingResolution( SAPDBDialect.class );
|
||||||
|
testDialectNamingResolution( SQLServerDialect.class );
|
||||||
|
testDialectNamingResolution( SQLServer2005Dialect.class );
|
||||||
|
testDialectNamingResolution( SQLServer2008Dialect.class );
|
||||||
|
testDialectNamingResolution( Sybase11Dialect.class );
|
||||||
|
testDialectNamingResolution( SybaseAnywhereDialect.class );
|
||||||
|
testDialectNamingResolution( SybaseASE15Dialect.class );
|
||||||
|
testDialectNamingResolution( SybaseASE157Dialect.class );
|
||||||
|
testDialectNamingResolution( TeradataDialect.class );
|
||||||
|
testDialectNamingResolution( TimesTenDialect.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testDialectNamingResolution(final Class<?> dialectClass) {
|
||||||
|
String simpleName = dialectClass.getSimpleName();
|
||||||
|
if ( simpleName.endsWith( "Dialect" ) ) {
|
||||||
|
simpleName = simpleName.substring( 0, simpleName.length() - "Dialect".length() );
|
||||||
|
}
|
||||||
|
Class<? extends Dialect> aClass = strategySelector.resolve( simpleName );
|
||||||
|
Assert.assertNotNull( aClass );
|
||||||
|
Assert.assertEquals( dialectClass, aClass );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue