HHH-6984 only increment statistics if statistics are enabled
This commit is contained in:
parent
78d07a3400
commit
b49f847ab7
|
@ -27,12 +27,9 @@ import java.io.Serializable;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.PessimisticLockException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
@ -40,6 +37,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.hibernate.persister.entity.Lockable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.sql.Update;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* A pessimistic locking strategy where the locks are obtained through update statements.
|
||||
|
@ -107,7 +105,9 @@ public class PessimisticReadUpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
int affected = st.executeUpdate();
|
||||
if ( affected < 0 ) { // todo: should this instead check for exactly one row modified?
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
}
|
||||
throw new StaleObjectStateException( lockable.getEntityName(), id );
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,9 @@ import java.io.Serializable;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.PessimisticLockException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
@ -40,6 +37,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.hibernate.persister.entity.Lockable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.sql.Update;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* A pessimistic locking strategy where the locks are obtained through update statements.
|
||||
|
@ -106,7 +104,9 @@ public class PessimisticWriteUpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
int affected = st.executeUpdate();
|
||||
if ( affected < 0 ) { // todo: should this instead check for exactly one row modified?
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
}
|
||||
throw new StaleObjectStateException( lockable.getEntityName(), id );
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,9 @@ public class UpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
int affected = st.executeUpdate();
|
||||
if ( affected < 0 ) {
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
}
|
||||
throw new StaleObjectStateException( lockable.getEntityName(), id );
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,9 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
|
||||
final boolean success = JtaStatusHelper.isCommitted( status );
|
||||
|
||||
if (sessionFactory().getStatistics().isStatisticsEnabled()) {
|
||||
transactionEnvironment.getStatisticsImplementor().endTransaction( success );
|
||||
}
|
||||
|
||||
getJdbcCoordinator().afterTransaction();
|
||||
|
||||
|
|
|
@ -41,8 +41,10 @@ public class ConnectionObserverStatsBridge implements ConnectionObserver, Serial
|
|||
|
||||
@Override
|
||||
public void physicalConnectionObtained(Connection connection) {
|
||||
if (sessionFactory.getStatistics().isStatisticsEnabled()) {
|
||||
sessionFactory.getStatisticsImplementor().connect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void physicalConnectionReleased() {
|
||||
|
@ -54,6 +56,8 @@ public class ConnectionObserverStatsBridge implements ConnectionObserver, Serial
|
|||
|
||||
@Override
|
||||
public void statementPrepared() {
|
||||
if (sessionFactory.getStatistics().isStatisticsEnabled()) {
|
||||
sessionFactory.getStatisticsImplementor().prepareStatement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.test.common;
|
||||
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.transaction.spi.TransactionEnvironment;
|
||||
|
@ -39,14 +40,22 @@ import org.hibernate.stat.spi.StatisticsImplementor;
|
|||
public class TransactionEnvironmentImpl implements TransactionEnvironment {
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final ConcurrentStatisticsImpl statistics = new ConcurrentStatisticsImpl();
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
public static final String NAME = "TransactionEnvironmentImpl_testSF";
|
||||
|
||||
public TransactionEnvironmentImpl(ServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
||||
Configuration cfg = new Configuration()
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME )
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); // default is true
|
||||
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionFactoryImplementor getSessionFactory() {
|
||||
throw new NotYetImplementedException( "Not available in this context" );
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue