HHH-13832 Optimise setting of default Flush Mode on a newly created Session

This commit is contained in:
Sanne Grinovero 2020-01-29 15:19:58 +00:00
parent 9b2a839ee4
commit 252ca9e98b
2 changed files with 16 additions and 1 deletions

View File

@ -39,6 +39,7 @@ import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.QueryHints;
import org.hibernate.jpa.internal.util.CacheModeHelper;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.LockOptionsHelper;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor;
@ -117,6 +118,7 @@ final class FastSessionServices {
final JdbcServices jdbcServices;
final boolean isJtaTransactionAccessible;
final CacheMode initialSessionCacheMode;
final FlushMode initialSessionFlushMode;
final boolean discardOnClose;
final BaselineSessionEventsListenerBuilder defaultSessionEventListeners;
final LockOptions defaultLockOptions;
@ -177,6 +179,12 @@ final class FastSessionServices {
this.defaultJdbcObservers = new ConnectionObserverStatsBridge( sf );
this.defaultSessionEventListeners = sessionFactoryOptions.getBaselineSessionEventsListenerBuilder();
this.defaultLockOptions = initializeDefaultLockOptions( defaultSessionProperties );
this.initialSessionFlushMode = initializeDefaultFlushMode( defaultSessionProperties );
}
private static FlushMode initializeDefaultFlushMode(Map<String, Object> defaultSessionProperties) {
Object setMode = defaultSessionProperties.get( AvailableSettings.FLUSH_MODE );
return ConfigurationHelper.getFlushMode( setMode, FlushMode.AUTO );
}
private static LockOptions initializeDefaultLockOptions(final Map<String, Object> defaultSessionProperties) {

View File

@ -256,7 +256,14 @@ public class SessionImpl
// NOTE : pulse() already handles auto-join-ability correctly
getTransactionCoordinator().pulse();
getSession().setHibernateFlushMode( ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO ) );
final FlushMode initialMode;
if ( this.properties == null ) {
initialMode = fastSessionServices.initialSessionFlushMode;
}
else {
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
}
getSession().setHibernateFlushMode( initialMode );
if ( log.isTraceEnabled() ) {
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );