diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java index 3c38be44c5..416181c08c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java @@ -129,11 +129,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator { final boolean success = JtaStatusHelper.isCommitted( status ); - // todo : handle stats as observer? - // as is this messes up unit tests which do not build a sf -// if ( sessionFactory().getStatistics().isStatisticsEnabled() ) { -// sessionFactory().getStatisticsImplementor().endTransaction( success ); -// } + transactionContext.getTransactionEnvironment().getStatisticsImplementor().endTransaction( success ); getJdbcCoordinator().afterTransaction(); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/spi/TransactionEnvironment.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/spi/TransactionEnvironment.java index b916a41b99..f45713c57b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/spi/TransactionEnvironment.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/spi/TransactionEnvironment.java @@ -26,6 +26,7 @@ package org.hibernate.engine.transaction.spi; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.service.jta.platform.spi.JtaPlatform; +import org.hibernate.stat.StatisticsImplementor; /** * Provides access to transactional services. @@ -60,4 +61,11 @@ public interface TransactionEnvironment { * @return The transaction factory */ public TransactionFactory getTransactionFactory(); + + /** + * Get access to the statistics collector + * + * @return The statistics collector + */ + public StatisticsImplementor getStatisticsImplementor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/impl/TransactionEnvironmentImpl.java b/hibernate-core/src/main/java/org/hibernate/impl/TransactionEnvironmentImpl.java index a3b67f7f5d..0049f1f0a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/impl/TransactionEnvironmentImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/impl/TransactionEnvironmentImpl.java @@ -23,13 +23,13 @@ */ package org.hibernate.impl; -import org.hibernate.ConnectionReleaseMode; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.transaction.spi.TransactionEnvironment; import org.hibernate.engine.transaction.spi.TransactionFactory; import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.spi.ServiceRegistry; +import org.hibernate.stat.StatisticsImplementor; /** * @author Steve Ebersole @@ -64,4 +64,9 @@ public class TransactionEnvironmentImpl implements TransactionEnvironment { public TransactionFactory getTransactionFactory() { return serviceRegistry().getService( TransactionFactory.class ); } + + @Override + public StatisticsImplementor getStatisticsImplementor() { + return sessionFactory.getStatisticsImplementor(); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/common/TransactionEnvironmentImpl.java b/hibernate-core/src/test/java/org/hibernate/test/common/TransactionEnvironmentImpl.java index 82a3b2ba5d..f1267b2698 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/common/TransactionEnvironmentImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/test/common/TransactionEnvironmentImpl.java @@ -30,12 +30,15 @@ import org.hibernate.engine.transaction.spi.TransactionEnvironment; import org.hibernate.engine.transaction.spi.TransactionFactory; import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.spi.ServiceRegistry; +import org.hibernate.stat.ConcurrentStatisticsImpl; +import org.hibernate.stat.StatisticsImplementor; /** * @author Steve Ebersole */ public class TransactionEnvironmentImpl implements TransactionEnvironment { private final ServiceRegistry serviceRegistry; + private final ConcurrentStatisticsImpl statistics = new ConcurrentStatisticsImpl(); public TransactionEnvironmentImpl(ServiceRegistry serviceRegistry) { this.serviceRegistry = serviceRegistry; @@ -60,4 +63,9 @@ public class TransactionEnvironmentImpl implements TransactionEnvironment { public TransactionFactory getTransactionFactory() { return serviceRegistry.getService( TransactionFactory.class ); } + + @Override + public StatisticsImplementor getStatisticsImplementor() { + return statistics; + } }