From 185ef2edb7cae1c74f0f92ba91b79ef2b35e2042 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 9 Aug 2019 13:19:11 +0100 Subject: [PATCH] HHH-13565 Extract some hot ServiceRegistry services as well --- .../internal/AbstractSharedSessionContract.java | 13 +++++-------- .../hibernate/internal/FastSessionServices.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 3a92f8d5fd..7384264360 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -210,11 +210,8 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont else { this.isTransactionCoordinatorShared = false; this.autoJoinTransactions = options.shouldAutoJoinTransactions(); - this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this ); - this.transactionCoordinator = factory.getServiceRegistry() - .getService( TransactionCoordinatorBuilder.class ) - .buildTransactionCoordinator( jdbcCoordinator, this ); + this.transactionCoordinator = fastSessionServices.transactionCoordinatorBuilder.buildTransactionCoordinator( jdbcCoordinator, this ); } } @@ -510,17 +507,17 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public JdbcConnectionAccess getJdbcConnectionAccess() { // See class-level JavaDocs for a discussion of the concurrent-access safety of this method if ( jdbcConnectionAccess == null ) { - if ( !factory.getSettings().getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ) { + if ( ! fastSessionServices.requiresMultiTenantConnectionProvider ) { jdbcConnectionAccess = new NonContextualJdbcConnectionAccess( getEventListenerManager(), - factory.getServiceRegistry().getService( ConnectionProvider.class ) + fastSessionServices.connectionProvider ); } else { jdbcConnectionAccess = new ContextualJdbcConnectionAccess( getTenantIdentifier(), getEventListenerManager(), - factory.getServiceRegistry().getService( MultiTenantConnectionProvider.class ) + fastSessionServices.multiTenantConnectionProvider ); } } @@ -964,7 +961,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont final Class actualReturnedClass; final String entityClassName = ( (NativeSQLQueryRootReturn) nativeSQLQueryReturn ).getReturnEntityName(); try { - actualReturnedClass = getFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( entityClassName ); + actualReturnedClass = fastSessionServices.classLoaderService.classForName( entityClassName ); } catch ( ClassLoadingException e ) { throw new AssertionFailure( diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java index e7c7afe97d..bdda279fd7 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java @@ -6,8 +6,11 @@ */ package org.hibernate.internal; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.AutoFlushEventListener; @@ -26,6 +29,7 @@ import org.hibernate.event.spi.RefreshEventListener; import org.hibernate.event.spi.ReplicateEventListener; import org.hibernate.event.spi.ResolveNaturalIdEventListener; import org.hibernate.event.spi.SaveOrUpdateEventListener; +import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; @@ -77,7 +81,13 @@ final class FastSessionServices { //Intentionally Package private: final boolean disallowOutOfTransactionUpdateOperations; final boolean useStreamForLobBinding; + final boolean requiresMultiTenantConnectionProvider; + final ConnectionProvider connectionProvider; + final MultiTenantConnectionProvider multiTenantConnectionProvider; + final ClassLoaderService classLoaderService; + final TransactionCoordinatorBuilder transactionCoordinatorBuilder; + //Private fields: private final Dialect dialect; FastSessionServices(SessionFactoryImpl sf) { @@ -111,6 +121,13 @@ final class FastSessionServices { this.disallowOutOfTransactionUpdateOperations = !sf.getSessionFactoryOptions().isAllowOutOfTransactionUpdateOperations(); this.useStreamForLobBinding = Environment.useStreamsForBinary() || dialect.useInputStreamToInsertBlob(); + this.requiresMultiTenantConnectionProvider = sf.getSettings().getMultiTenancyStrategy().requiresMultiTenantConnectionProvider(); + + //Some "hot" services: + this.connectionProvider = requiresMultiTenantConnectionProvider ? null : sr.getService( ConnectionProvider.class ); + this.multiTenantConnectionProvider = requiresMultiTenantConnectionProvider ? sr.getService( MultiTenantConnectionProvider.class ) : null; + this.classLoaderService = sr.getService( ClassLoaderService.class ); + this.transactionCoordinatorBuilder = sr.getService( TransactionCoordinatorBuilder.class ); } Iterable getClearEventListeners() {