HHH-13565 Prepare the most commonly needed SessionBuilder instances in advance

This commit is contained in:
Sanne Grinovero 2019-08-20 21:59:16 +01:00
parent cc39f54717
commit 2de048fde5

View File

@ -198,6 +198,8 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
private final transient TypeHelper typeHelper; private final transient TypeHelper typeHelper;
private final transient FastSessionServices fastSessionServices; private final transient FastSessionServices fastSessionServices;
private final transient SessionBuilder defaultSessionOpenOptions;
private final transient SessionBuilder temporarySessionOpenOptions;
public SessionFactoryImpl( public SessionFactoryImpl(
final MetadataImplementor metadata, final MetadataImplementor metadata,
@ -377,6 +379,11 @@ public void sessionFactoryClosed(SessionFactory factory) {
fetchProfiles.put( fetchProfile.getName(), fetchProfile ); fetchProfiles.put( fetchProfile.getName(), fetchProfile );
} }
this.defaultSessionOpenOptions = withOptions();
this.temporarySessionOpenOptions = withOptions()
.autoClose( false )
.flushMode( FlushMode.MANUAL )
.connectionHandlingMode( PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT );
this.fastSessionServices = new FastSessionServices( this ); this.fastSessionServices = new FastSessionServices( this );
this.observer.sessionFactoryCreated( this ); this.observer.sessionFactoryCreated( this );
@ -474,15 +481,11 @@ private JdbcConnectionAccess buildLocalConnectionAccess() {
} }
public Session openSession() throws HibernateException { public Session openSession() throws HibernateException {
return withOptions().openSession(); return this.defaultSessionOpenOptions.openSession();
} }
public Session openTemporarySession() throws HibernateException { public Session openTemporarySession() throws HibernateException {
return withOptions() return this.temporarySessionOpenOptions.openSession();
.autoClose( false )
.flushMode( FlushMode.MANUAL )
.connectionHandlingMode( PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT )
.openSession();
} }
public Session getCurrentSession() throws HibernateException { public Session getCurrentSession() throws HibernateException {