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

View File

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