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