HHH-8679 Relax synchronized block in Loader#wrapResultSetIfEnabled

(cherry picked from commit 8a0cf23f1f8a09dcec0c500f1504c33975f15ba4)
This commit is contained in:
Sanne Grinovero 2013-11-13 14:44:48 +00:00 committed by Steve Ebersole
parent 687b7718d9
commit 71d5a746e3
1 changed files with 10 additions and 9 deletions

View File

@ -40,7 +40,6 @@ import java.util.Map;
import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
@ -64,6 +63,7 @@ import org.hibernate.dialect.pagination.NoopLimitHandler;
import org.hibernate.engine.internal.CacheHelper;
import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.jdbc.ColumnNameCache;
import org.hibernate.engine.jdbc.spi.ResultSetWrapper;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.EntityUniqueKey;
@ -115,7 +115,7 @@ public abstract class Loader {
protected static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Loader.class.getName());
protected static final boolean DEBUG_ENABLED = LOG.isDebugEnabled();
private final SessionFactoryImplementor factory;
private ColumnNameCache columnNameCache;
private volatile ColumnNameCache columnNameCache;
private final boolean referenceCachingEnabled;
@ -2082,9 +2082,7 @@ public abstract class Loader {
}
private synchronized ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplementor session) {
// synchronized to avoid multi-thread access issues; defined as method synch to avoid
// potential deadlock issues due to nature of code.
private ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplementor session) {
if ( session.getFactory().getSettings().isWrapResultSetsEnabled() ) {
try {
LOG.debugf( "Wrapping result set [%s]", rs );
@ -2102,12 +2100,15 @@ public abstract class Loader {
}
}
private ColumnNameCache retreiveColumnNameToIndexCache(ResultSet rs) throws SQLException {
private ColumnNameCache retreiveColumnNameToIndexCache(final ResultSet rs) throws SQLException {
if ( columnNameCache == null ) {
synchronized ( this ) {
if ( columnNameCache == null ) {
LOG.trace( "Building columnName -> columnIndex cache" );
columnNameCache = new ColumnNameCache( rs.getMetaData().getColumnCount() );
}
}
}
return columnNameCache;
}