HHH-7683 - Optimize performance of AbstractLazyInitializer.prepareForPossibleSpecialSpecjInitialization()

(cherry picked from commit c9fd71fe57)
This commit is contained in:
Steve Ebersole 2012-10-10 13:21:12 -05:00
parent c5a7916010
commit 3078cfa43f
4 changed files with 58 additions and 49 deletions

View File

@ -81,6 +81,7 @@ public final class Settings {
private boolean namedQueryStartupCheckingEnabled;
private EntityTuplizerFactory entityTuplizerFactory;
private boolean checkNullability;
private boolean initializeLazyStateOutsideTransactions;
// private ComponentTuplizerFactory componentTuplizerFactory; todo : HHH-3517 and HHH-1907
// private BytecodeProvider bytecodeProvider;
private String importFiles;
@ -264,6 +265,7 @@ public final class Settings {
// return componentTuplizerFactory;
// }
// package protected setters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setDefaultSchemaName(String string) {
@ -458,4 +460,12 @@ public final class Settings {
void setMultiTenancyStrategy(MultiTenancyStrategy multiTenancyStrategy) {
this.multiTenancyStrategy = multiTenancyStrategy;
}
public boolean isInitializeLazyStateOutsideTransactionsEnabled() {
return initializeLazyStateOutsideTransactions;
}
void setInitializeLazyStateOutsideTransactions(boolean initializeLazyStateOutsideTransactions) {
this.initializeLazyStateOutsideTransactions = initializeLazyStateOutsideTransactions;
}
}

View File

@ -75,7 +75,7 @@ public class SettingsFactory implements Serializable {
//SessionFactory name:
String sessionFactoryName = props.getProperty( Environment.SESSION_FACTORY_NAME );
String sessionFactoryName = props.getProperty( AvailableSettings.SESSION_FACTORY_NAME );
settings.setSessionFactoryName( sessionFactoryName );
settings.setSessionFactoryNameAlsoJndiName(
ConfigurationHelper.getBoolean( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, props, true )
@ -97,13 +97,13 @@ public class SettingsFactory implements Serializable {
// Transaction settings:
settings.setJtaPlatform( serviceRegistry.getService( JtaPlatform.class ) );
boolean flushBeforeCompletion = ConfigurationHelper.getBoolean(Environment.FLUSH_BEFORE_COMPLETION, properties);
boolean flushBeforeCompletion = ConfigurationHelper.getBoolean(AvailableSettings.FLUSH_BEFORE_COMPLETION, properties);
if ( debugEnabled ) {
LOG.debugf( "Automatic flush during beforeCompletion(): %s", enabledDisabled(flushBeforeCompletion) );
}
settings.setFlushBeforeCompletionEnabled(flushBeforeCompletion);
boolean autoCloseSession = ConfigurationHelper.getBoolean(Environment.AUTO_CLOSE_SESSION, properties);
boolean autoCloseSession = ConfigurationHelper.getBoolean(AvailableSettings.AUTO_CLOSE_SESSION, properties);
if ( debugEnabled ) {
LOG.debugf( "Automatic session close at end of transaction: %s", enabledDisabled(autoCloseSession) );
}
@ -111,7 +111,7 @@ public class SettingsFactory implements Serializable {
//JDBC and connection settings:
int batchSize = ConfigurationHelper.getInt(Environment.STATEMENT_BATCH_SIZE, properties, 0);
int batchSize = ConfigurationHelper.getInt(AvailableSettings.STATEMENT_BATCH_SIZE, properties, 0);
if ( !meta.supportsBatchUpdates() ) {
batchSize = 0;
}
@ -120,14 +120,14 @@ public class SettingsFactory implements Serializable {
}
settings.setJdbcBatchSize(batchSize);
boolean jdbcBatchVersionedData = ConfigurationHelper.getBoolean(Environment.BATCH_VERSIONED_DATA, properties, false);
boolean jdbcBatchVersionedData = ConfigurationHelper.getBoolean(AvailableSettings.BATCH_VERSIONED_DATA, properties, false);
if ( batchSize > 0 && debugEnabled ) {
LOG.debugf( "JDBC batch updates for versioned data: %s", enabledDisabled(jdbcBatchVersionedData) );
}
settings.setJdbcBatchVersionedData(jdbcBatchVersionedData);
boolean useScrollableResultSets = ConfigurationHelper.getBoolean(
Environment.USE_SCROLLABLE_RESULTSET,
AvailableSettings.USE_SCROLLABLE_RESULTSET,
properties,
meta.supportsScrollableResults()
);
@ -136,19 +136,19 @@ public class SettingsFactory implements Serializable {
}
settings.setScrollableResultSetsEnabled(useScrollableResultSets);
boolean wrapResultSets = ConfigurationHelper.getBoolean(Environment.WRAP_RESULT_SETS, properties, false);
boolean wrapResultSets = ConfigurationHelper.getBoolean(AvailableSettings.WRAP_RESULT_SETS, properties, false);
if ( debugEnabled ) {
LOG.debugf( "Wrap result sets: %s", enabledDisabled(wrapResultSets) );
}
settings.setWrapResultSetsEnabled(wrapResultSets);
boolean useGetGeneratedKeys = ConfigurationHelper.getBoolean(Environment.USE_GET_GENERATED_KEYS, properties, meta.supportsGetGeneratedKeys());
boolean useGetGeneratedKeys = ConfigurationHelper.getBoolean(AvailableSettings.USE_GET_GENERATED_KEYS, properties, meta.supportsGetGeneratedKeys());
if ( debugEnabled ) {
LOG.debugf( "JDBC3 getGeneratedKeys(): %s", enabledDisabled(useGetGeneratedKeys) );
}
settings.setGetGeneratedKeysEnabled(useGetGeneratedKeys);
Integer statementFetchSize = ConfigurationHelper.getInteger(Environment.STATEMENT_FETCH_SIZE, properties);
Integer statementFetchSize = ConfigurationHelper.getInteger(AvailableSettings.STATEMENT_FETCH_SIZE, properties);
if ( statementFetchSize != null && debugEnabled ) {
LOG.debugf( "JDBC result set fetch size: %s", statementFetchSize );
}
@ -160,7 +160,7 @@ public class SettingsFactory implements Serializable {
}
settings.setMultiTenancyStrategy( multiTenancyStrategy );
String releaseModeName = ConfigurationHelper.getString( Environment.RELEASE_CONNECTIONS, properties, "auto" );
String releaseModeName = ConfigurationHelper.getString( AvailableSettings.RELEASE_CONNECTIONS, properties, "auto" );
if ( debugEnabled ) {
LOG.debugf( "Connection release mode: %s", releaseModeName );
}
@ -185,8 +185,8 @@ public class SettingsFactory implements Serializable {
//SQL Generation settings:
String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
String defaultSchema = properties.getProperty( AvailableSettings.DEFAULT_SCHEMA );
String defaultCatalog = properties.getProperty( AvailableSettings.DEFAULT_CATALOG );
if ( defaultSchema != null && debugEnabled ) {
LOG.debugf( "Default schema: %s", defaultSchema );
}
@ -196,31 +196,31 @@ public class SettingsFactory implements Serializable {
settings.setDefaultSchemaName( defaultSchema );
settings.setDefaultCatalogName( defaultCatalog );
Integer maxFetchDepth = ConfigurationHelper.getInteger( Environment.MAX_FETCH_DEPTH, properties );
Integer maxFetchDepth = ConfigurationHelper.getInteger( AvailableSettings.MAX_FETCH_DEPTH, properties );
if ( maxFetchDepth != null ) {
LOG.debugf( "Maximum outer join fetch depth: %s", maxFetchDepth );
}
settings.setMaximumFetchDepth( maxFetchDepth );
int batchFetchSize = ConfigurationHelper.getInt(Environment.DEFAULT_BATCH_FETCH_SIZE, properties, 1);
int batchFetchSize = ConfigurationHelper.getInt(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, properties, 1);
if ( debugEnabled ) {
LOG.debugf( "Default batch fetch size: %s", batchFetchSize );
}
settings.setDefaultBatchFetchSize( batchFetchSize );
boolean comments = ConfigurationHelper.getBoolean( Environment.USE_SQL_COMMENTS, properties );
boolean comments = ConfigurationHelper.getBoolean( AvailableSettings.USE_SQL_COMMENTS, properties );
if ( debugEnabled ) {
LOG.debugf( "Generate SQL with comments: %s", enabledDisabled(comments) );
}
settings.setCommentsEnabled( comments );
boolean orderUpdates = ConfigurationHelper.getBoolean( Environment.ORDER_UPDATES, properties );
boolean orderUpdates = ConfigurationHelper.getBoolean( AvailableSettings.ORDER_UPDATES, properties );
if ( debugEnabled ) {
LOG.debugf( "Order SQL updates by primary key: %s", enabledDisabled(orderUpdates) );
}
settings.setOrderUpdatesEnabled( orderUpdates );
boolean orderInserts = ConfigurationHelper.getBoolean(Environment.ORDER_INSERTS, properties);
boolean orderInserts = ConfigurationHelper.getBoolean(AvailableSettings.ORDER_INSERTS, properties);
if ( debugEnabled ) {
LOG.debugf( "Order SQL inserts for batching: %s", enabledDisabled(orderInserts) );
}
@ -230,13 +230,13 @@ public class SettingsFactory implements Serializable {
settings.setQueryTranslatorFactory( createQueryTranslatorFactory( properties, serviceRegistry ) );
Map querySubstitutions = ConfigurationHelper.toMap( Environment.QUERY_SUBSTITUTIONS, " ,=;:\n\t\r\f", properties );
Map querySubstitutions = ConfigurationHelper.toMap( AvailableSettings.QUERY_SUBSTITUTIONS, " ,=;:\n\t\r\f", properties );
if ( debugEnabled ) {
LOG.debugf( "Query language substitutions: %s", querySubstitutions );
}
settings.setQuerySubstitutions( querySubstitutions );
boolean jpaqlCompliance = ConfigurationHelper.getBoolean( Environment.JPAQL_STRICT_COMPLIANCE, properties, false );
boolean jpaqlCompliance = ConfigurationHelper.getBoolean( AvailableSettings.JPAQL_STRICT_COMPLIANCE, properties, false );
if ( debugEnabled ) {
LOG.debugf( "JPA-QL strict compliance: %s", enabledDisabled(jpaqlCompliance) );
}
@ -244,13 +244,13 @@ public class SettingsFactory implements Serializable {
// Second-level / query cache:
boolean useSecondLevelCache = ConfigurationHelper.getBoolean( Environment.USE_SECOND_LEVEL_CACHE, properties, true );
boolean useSecondLevelCache = ConfigurationHelper.getBoolean( AvailableSettings.USE_SECOND_LEVEL_CACHE, properties, true );
if ( debugEnabled ) {
LOG.debugf( "Second-level cache: %s", enabledDisabled(useSecondLevelCache) );
}
settings.setSecondLevelCacheEnabled( useSecondLevelCache );
boolean useQueryCache = ConfigurationHelper.getBoolean(Environment.USE_QUERY_CACHE, properties);
boolean useQueryCache = ConfigurationHelper.getBoolean(AvailableSettings.USE_QUERY_CACHE, properties);
if ( debugEnabled ) {
LOG.debugf( "Query cache: %s", enabledDisabled(useQueryCache) );
}
@ -264,14 +264,14 @@ public class SettingsFactory implements Serializable {
settings.setRegionFactory( createRegionFactory( properties, ( useSecondLevelCache || useQueryCache ), serviceRegistry ) );
boolean useMinimalPuts = ConfigurationHelper.getBoolean(
Environment.USE_MINIMAL_PUTS, properties, settings.getRegionFactory().isMinimalPutsEnabledByDefault()
AvailableSettings.USE_MINIMAL_PUTS, properties, settings.getRegionFactory().isMinimalPutsEnabledByDefault()
);
if ( debugEnabled ) {
LOG.debugf( "Optimize cache for minimal puts: %s", enabledDisabled(useMinimalPuts) );
}
settings.setMinimalPutsEnabled( useMinimalPuts );
String prefix = properties.getProperty( Environment.CACHE_REGION_PREFIX );
String prefix = properties.getProperty( AvailableSettings.CACHE_REGION_PREFIX );
if ( StringHelper.isEmpty(prefix) ) {
prefix=null;
}
@ -280,7 +280,7 @@ public class SettingsFactory implements Serializable {
}
settings.setCacheRegionPrefix( prefix );
boolean useStructuredCacheEntries = ConfigurationHelper.getBoolean( Environment.USE_STRUCTURED_CACHE, properties, false );
boolean useStructuredCacheEntries = ConfigurationHelper.getBoolean( AvailableSettings.USE_STRUCTURED_CACHE, properties, false );
if ( debugEnabled ) {
LOG.debugf( "Structured second-level cache entries: %s", enabledDisabled(useStructuredCacheEntries) );
}
@ -289,13 +289,13 @@ public class SettingsFactory implements Serializable {
//Statistics and logging:
boolean useStatistics = ConfigurationHelper.getBoolean( Environment.GENERATE_STATISTICS, properties );
boolean useStatistics = ConfigurationHelper.getBoolean( AvailableSettings.GENERATE_STATISTICS, properties );
if ( debugEnabled ) {
LOG.debugf( "Statistics: %s", enabledDisabled(useStatistics) );
}
settings.setStatisticsEnabled( useStatistics );
boolean useIdentifierRollback = ConfigurationHelper.getBoolean( Environment.USE_IDENTIFIER_ROLLBACK, properties );
boolean useIdentifierRollback = ConfigurationHelper.getBoolean( AvailableSettings.USE_IDENTIFIER_ROLLBACK, properties );
if ( debugEnabled ) {
LOG.debugf( "Deleted entity synthetic identifier rollback: %s", enabledDisabled(useIdentifierRollback) );
}
@ -303,7 +303,7 @@ public class SettingsFactory implements Serializable {
//Schema export:
String autoSchemaExport = properties.getProperty( Environment.HBM2DDL_AUTO );
String autoSchemaExport = properties.getProperty( AvailableSettings.HBM2DDL_AUTO );
if ( "validate".equals(autoSchemaExport) ) {
settings.setAutoValidateSchema( true );
}
@ -317,21 +317,21 @@ public class SettingsFactory implements Serializable {
settings.setAutoCreateSchema( true );
settings.setAutoDropSchema( true );
}
settings.setImportFiles( properties.getProperty( Environment.HBM2DDL_IMPORT_FILES ) );
settings.setImportFiles( properties.getProperty( AvailableSettings.HBM2DDL_IMPORT_FILES ) );
EntityMode defaultEntityMode = EntityMode.parse( properties.getProperty( Environment.DEFAULT_ENTITY_MODE ) );
EntityMode defaultEntityMode = EntityMode.parse( properties.getProperty( AvailableSettings.DEFAULT_ENTITY_MODE ) );
if ( debugEnabled ) {
LOG.debugf( "Default entity-mode: %s", defaultEntityMode );
}
settings.setDefaultEntityMode( defaultEntityMode );
boolean namedQueryChecking = ConfigurationHelper.getBoolean( Environment.QUERY_STARTUP_CHECKING, properties, true );
boolean namedQueryChecking = ConfigurationHelper.getBoolean( AvailableSettings.QUERY_STARTUP_CHECKING, properties, true );
if ( debugEnabled ) {
LOG.debugf( "Named query checking : %s", enabledDisabled(namedQueryChecking) );
}
settings.setNamedQueryStartupCheckingEnabled( namedQueryChecking );
boolean checkNullability = ConfigurationHelper.getBoolean(Environment.CHECK_NULLABILITY, properties, true);
boolean checkNullability = ConfigurationHelper.getBoolean(AvailableSettings.CHECK_NULLABILITY, properties, true);
if ( debugEnabled ) {
LOG.debugf( "Check Nullability in Core (should be disabled when Bean Validation is on): %s", enabledDisabled(checkNullability) );
}
@ -340,11 +340,21 @@ public class SettingsFactory implements Serializable {
// TODO: Does EntityTuplizerFactory really need to be configurable? revisit for HHH-6383
settings.setEntityTuplizerFactory( new EntityTuplizerFactory() );
// String provider = properties.getProperty( Environment.BYTECODE_PROVIDER );
// String provider = properties.getProperty( AvailableSettings.BYTECODE_PROVIDER );
// log.info( "Bytecode provider name : " + provider );
// BytecodeProvider bytecodeProvider = buildBytecodeProvider( provider );
// settings.setBytecodeProvider( bytecodeProvider );
boolean initializeLazyStateOutsideTransactionsEnabled = ConfigurationHelper.getBoolean(
AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS,
properties,
false
);
if ( debugEnabled ) {
LOG.debugf( "Allow initialization of lazy state outside session : : %s", enabledDisabled( initializeLazyStateOutsideTransactionsEnabled ) );
}
settings.setInitializeLazyStateOutsideTransactions( initializeLazyStateOutsideTransactionsEnabled );
return settings;
}
@ -365,7 +375,7 @@ public class SettingsFactory implements Serializable {
protected QueryCacheFactory createQueryCacheFactory(Properties properties, ServiceRegistry serviceRegistry) {
String queryCacheFactoryClassName = ConfigurationHelper.getString(
Environment.QUERY_CACHE_FACTORY, properties, StandardQueryCacheFactory.class.getName()
AvailableSettings.QUERY_CACHE_FACTORY, properties, StandardQueryCacheFactory.class.getName()
);
LOG.debugf( "Query cache factory: %s", queryCacheFactoryClassName );
try {
@ -381,7 +391,7 @@ public class SettingsFactory implements Serializable {
private static RegionFactory createRegionFactory(Properties properties, boolean cachingEnabled, ServiceRegistry serviceRegistry) {
String regionFactoryClassName = RegionFactoryInitiator.mapLegacyNames(
ConfigurationHelper.getString(
Environment.CACHE_REGION_FACTORY, properties, null
AvailableSettings.CACHE_REGION_FACTORY, properties, null
)
);
if ( regionFactoryClassName == null || !cachingEnabled) {
@ -415,7 +425,7 @@ public class SettingsFactory implements Serializable {
// todo : REMOVE! THIS IS TOTALLY A TEMPORARY HACK FOR org.hibernate.cfg.AnnotationBinder which will be going away
String regionFactoryClassName = RegionFactoryInitiator.mapLegacyNames(
ConfigurationHelper.getString(
Environment.CACHE_REGION_FACTORY, properties, null
AvailableSettings.CACHE_REGION_FACTORY, properties, null
)
);
if ( regionFactoryClassName == null ) {
@ -445,7 +455,7 @@ public class SettingsFactory implements Serializable {
protected QueryTranslatorFactory createQueryTranslatorFactory(Properties properties, ServiceRegistry serviceRegistry) {
String className = ConfigurationHelper.getString(
Environment.QUERY_TRANSLATOR, properties, "org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory"
AvailableSettings.QUERY_TRANSLATOR, properties, "org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory"
);
LOG.debugf( "Query translator: %s", className );
try {

View File

@ -39,7 +39,6 @@ import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.LazyInitializationException;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.spi.CollectionEntry;
@ -586,11 +585,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
protected void prepareForPossibleSpecialSpecjInitialization() {
if ( session != null ) {
specjLazyLoad = Boolean.parseBoolean(
session.getFactory()
.getProperties()
.getProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS )
);
specjLazyLoad = session.getFactory().getSettings().isInitializeLazyStateOutsideTransactionsEnabled();
if ( specjLazyLoad && sessionFactoryUuid == null ) {
try {

View File

@ -33,7 +33,6 @@ import org.hibernate.LazyInitializationException;
import org.hibernate.Session;
import org.hibernate.SessionException;
import org.hibernate.TransientObjectException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
@ -224,12 +223,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
protected void prepareForPossibleSpecialSpecjInitialization() {
if ( session != null ) {
specjLazyLoad =
Boolean.parseBoolean(
session.getFactory()
.getProperties()
.getProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS )
);
specjLazyLoad = session.getFactory().getSettings().isInitializeLazyStateOutsideTransactionsEnabled();
if ( specjLazyLoad && sessionFactoryUuid == null ) {
try {