HHH-6984 : Only increment statistics if statistics are enabled

This commit is contained in:
Gail Badner 2012-02-07 23:51:21 -06:00
parent 318805dad6
commit a9df94eb85
4 changed files with 35 additions and 46 deletions

View File

@ -23,24 +23,20 @@
*/
package org.hibernate.dialect.lock;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.hibernate.*;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.sql.Update;
import org.hibernate.LockMode;
import org.hibernate.HibernateException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.JDBCException;
import org.hibernate.PessimisticLockException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* A pessimistic locking strategy where the locks are obtained through update statements.
* <p/>
@ -109,7 +105,9 @@ public void lock(
int affected = st.executeUpdate();
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 );
}

View File

@ -23,24 +23,20 @@
*/
package org.hibernate.dialect.lock;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.hibernate.*;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.sql.Update;
import org.hibernate.LockMode;
import org.hibernate.HibernateException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.JDBCException;
import org.hibernate.PessimisticLockException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* A pessimistic locking strategy where the locks are obtained through update statements.
* <p/>
@ -109,7 +105,9 @@ public void lock(
int affected = st.executeUpdate();
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 );
}

View File

@ -23,10 +23,6 @@
*/
package org.hibernate.dialect.lock;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
@ -40,6 +36,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* A locking strategy where the locks are obtained through update statements.
* <p/>
@ -107,7 +107,9 @@ public void lock(
int affected = st.executeUpdate();
if ( affected < 0 ) {
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
if (factory.getStatistics().isStatisticsEnabled()) {
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
}
throw new StaleObjectStateException( lockable.getEntityName(), id );
}

View File

@ -24,30 +24,21 @@
*/
package org.hibernate.engine.loading;
import java.sql.ResultSet;
import java.io.Serializable;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import org.hibernate.CacheMode;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.cache.CacheKey;
import org.hibernate.cache.entry.CollectionCacheEntry;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.*;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.EntityMode;
import org.hibernate.CacheMode;
import org.hibernate.cache.entry.CollectionCacheEntry;
import org.hibernate.cache.CacheKey;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.engine.CollectionKey;
import org.hibernate.engine.Status;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.CollectionEntry;
import org.hibernate.engine.SessionFactoryImplementor;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.*;
/**
* Represents state associated with the processing of a given {@link ResultSet}