HHH-6258: Cached service registry classes in local variables to remove load from AbstractServiceRegistryImpl.locateServiceBinding(java.lang.Class). This resulted in a decent improvement in throughput.

This commit is contained in:
Andrig Miller 2011-05-25 17:00:11 -06:00 committed by Steve Ebersole
parent 8593cf91cd
commit abe51d5b35
2 changed files with 27 additions and 9 deletions

View File

@ -65,6 +65,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
private final transient TransactionContext transactionContext;
private final transient JdbcCoordinatorImpl jdbcCoordinator;
private final transient TransactionFactory transactionFactory;
private final transient TransactionEnvironment transactionEnvironment;
private final transient List<TransactionObserver> observers;
private final transient SynchronizationRegistryImpl synchronizationRegistry;
@ -82,6 +84,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
TransactionContext transactionContext) {
this.transactionContext = transactionContext;
this.jdbcCoordinator = new JdbcCoordinatorImpl( userSuppliedConnection, this );
this.transactionEnvironment = transactionContext.getTransactionEnvironment();
this.transactionFactory = this.transactionEnvironment.getTransactionFactory();
this.observers = new ArrayList<TransactionObserver>();
this.synchronizationRegistry = new SynchronizationRegistryImpl();
reset();
@ -100,6 +104,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
List<TransactionObserver> observers) {
this.transactionContext = transactionContext;
this.jdbcCoordinator = jdbcCoordinator;
this.transactionEnvironment = transactionContext.getTransactionEnvironment();
this.transactionFactory = this.transactionEnvironment.getTransactionFactory();
this.observers = observers;
this.synchronizationRegistry = new SynchronizationRegistryImpl();
reset();
@ -130,7 +136,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
final boolean success = JtaStatusHelper.isCommitted( status );
transactionContext.getTransactionEnvironment().getStatisticsImplementor().endTransaction( success );
transactionEnvironment.getStatisticsImplementor().endTransaction( success );
getJdbcCoordinator().afterTransaction();
@ -140,7 +146,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
}
private SessionFactoryImplementor sessionFactory() {
return transactionContext.getTransactionEnvironment().getSessionFactory();
return transactionEnvironment.getSessionFactory();
}
public boolean isSynchronizationRegistered() {
@ -164,11 +170,11 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
}
private TransactionFactory transactionFactory() {
return getTransactionEnvironment().getTransactionFactory();
return transactionFactory;
}
private TransactionEnvironment getTransactionEnvironment() {
return getTransactionContext().getTransactionEnvironment();
return transactionEnvironment;
}
@Override

View File

@ -37,8 +37,20 @@ import org.hibernate.stat.spi.StatisticsImplementor;
public class TransactionEnvironmentImpl implements TransactionEnvironment {
private final SessionFactoryImpl sessionFactory;
private final transient StatisticsImplementor statisticsImplementor;
private final transient ServiceRegistry serviceRegistry;
private final transient JdbcServices jdbcServices;
private final transient JtaPlatform jtaPlatform;
private final transient TransactionFactory transactionFactory;
public TransactionEnvironmentImpl(SessionFactoryImpl sessionFactory) {
this.sessionFactory = sessionFactory;
this.statisticsImplementor = sessionFactory.getStatisticsImplementor();
this.serviceRegistry = sessionFactory.getServiceRegistry();
this.jdbcServices = serviceRegistry.getService( JdbcServices.class );
this.jtaPlatform = serviceRegistry.getService( JtaPlatform.class );
this.transactionFactory = serviceRegistry.getService( TransactionFactory.class );
}
@Override
@ -47,26 +59,26 @@ public class TransactionEnvironmentImpl implements TransactionEnvironment {
}
protected ServiceRegistry serviceRegistry() {
return sessionFactory.getServiceRegistry();
return serviceRegistry;
}
@Override
public JdbcServices getJdbcServices() {
return serviceRegistry().getService( JdbcServices.class );
return jdbcServices;
}
@Override
public JtaPlatform getJtaPlatform() {
return serviceRegistry().getService( JtaPlatform.class );
return jtaPlatform;
}
@Override
public TransactionFactory getTransactionFactory() {
return serviceRegistry().getService( TransactionFactory.class );
return transactionFactory;
}
@Override
public StatisticsImplementor getStatisticsImplementor() {
return sessionFactory.getStatisticsImplementor();
return statisticsImplementor;
}
}