From 87fe888ad5d74197aa0c56e5b54fef8299d55e5d Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 31 Oct 2012 11:45:55 -0500 Subject: [PATCH] HHH-7725 - Make handling multi-table bulk HQL operations more pluggable --- .../org/hibernate/cfg/SettingsFactory.java | 47 ++++++++++++++----- .../internal/SessionFactoryImpl.java | 4 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/SettingsFactory.java b/hibernate-core/src/main/java/org/hibernate/cfg/SettingsFactory.java index 1ea354ebcd..f94bbbcbbf 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/SettingsFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/SettingsFactory.java @@ -33,12 +33,12 @@ import org.hibernate.ConnectionReleaseMode; import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.MultiTenancyStrategy; -import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.cache.internal.NoCachingRegionFactory; import org.hibernate.cache.internal.RegionFactoryInitiator; import org.hibernate.cache.internal.StandardQueryCacheFactory; import org.hibernate.cache.spi.QueryCacheFactory; import org.hibernate.cache.spi.RegionFactory; +import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.ExtractedDatabaseMetaData; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.transaction.spi.TransactionFactory; @@ -101,16 +101,11 @@ public class SettingsFactory implements Serializable { // Transaction settings: settings.setJtaPlatform( serviceRegistry.getService( JtaPlatform.class ) ); - MultiTableBulkIdStrategy multiTableBulkIdStrategy = serviceRegistry.getService( StrategySelector.class ) - .resolveStrategy( - MultiTableBulkIdStrategy.class, - properties.getProperty( AvailableSettings.HQL_BULK_ID_STRATEGY ) - ); - if ( multiTableBulkIdStrategy == null ) { - multiTableBulkIdStrategy = jdbcServices.getDialect().supportsTemporaryTables() - ? TemporaryTableBulkIdStrategy.INSTANCE - : new PersistentTableBulkIdStrategy(); - } + final MultiTableBulkIdStrategy multiTableBulkIdStrategy = getMultiTableBulkIdStrategy( + properties, + jdbcServices.getDialect(), + serviceRegistry.getService( ClassLoaderService.class ) + ); settings.setMultiTableBulkIdStrategy( multiTableBulkIdStrategy ); boolean flushBeforeCompletion = ConfigurationHelper.getBoolean(AvailableSettings.FLUSH_BEFORE_COMPLETION, properties); @@ -375,6 +370,36 @@ public class SettingsFactory implements Serializable { } + private MultiTableBulkIdStrategy getMultiTableBulkIdStrategy( + Properties properties, + Dialect dialect, + ClassLoaderService classLoaderService) { + final Object setting = properties.get( AvailableSettings.HQL_BULK_ID_STRATEGY ); + if ( setting != null ) { + if ( MultiTableBulkIdStrategy.class.isInstance( setting ) ) { + return (MultiTableBulkIdStrategy) setting; + } + final Class strategyClass; + if ( Class.class.isInstance( setting ) ) { + strategyClass = (Class) setting; + } + else { + strategyClass = classLoaderService.classForName( setting.toString() ); + } + try { + return (MultiTableBulkIdStrategy) strategyClass.newInstance(); + } + catch (Exception e) { + throw new HibernateException( "Unable to interpret MultiTableBulkIdStrategy setting [" + setting + "]", e ); + } + } + else { + return dialect.supportsTemporaryTables() + ? TemporaryTableBulkIdStrategy.INSTANCE + : new PersistentTableBulkIdStrategy(); + } + } + // protected BytecodeProvider buildBytecodeProvider(String providerName) { // if ( "javassist".equals( providerName ) ) { // return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index af2d2cb87a..6399d6e9cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -39,7 +39,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import javax.naming.Reference; import javax.naming.StringRefAddr; @@ -93,7 +92,6 @@ import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.engine.ResultSetMappingDefinition; -import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; @@ -116,7 +114,6 @@ import org.hibernate.id.UUIDGenerator; import org.hibernate.id.factory.IdentifierGeneratorFactory; import org.hibernate.integrator.spi.Integrator; import org.hibernate.integrator.spi.IntegratorService; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; @@ -136,6 +133,7 @@ import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.classloading.spi.ClassLoadingException; import org.hibernate.service.config.spi.ConfigurationService; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.service.jndi.spi.JndiService; import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.spi.ServiceRegistryImplementor;