HHH-7725 - Make handling multi-table bulk HQL operations more pluggable

This commit is contained in:
Steve Ebersole 2012-10-31 11:45:55 -05:00
parent 54d29f715b
commit 87fe888ad5
2 changed files with 37 additions and 14 deletions

View File

@ -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();

View File

@ -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;