HHH-8679 Relax synchronized block in Loader#wrapResultSetIfEnabled

This commit is contained in:
Sanne Grinovero 2013-11-13 14:44:48 +00:00 committed by Steve Ebersole
parent e64376eb2b
commit 15adff22ce
1 changed files with 10 additions and 9 deletions

View File

@ -40,7 +40,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockMode; 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.CacheHelper;
import org.hibernate.engine.internal.TwoPhaseLoad; import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.jdbc.ColumnNameCache; import org.hibernate.engine.jdbc.ColumnNameCache;
import org.hibernate.engine.jdbc.spi.ResultSetWrapper;
import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.EntityUniqueKey; import org.hibernate.engine.spi.EntityUniqueKey;
@ -116,7 +116,7 @@ public abstract class Loader {
protected static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Loader.class.getName()); protected static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Loader.class.getName());
protected static final boolean DEBUG_ENABLED = LOG.isDebugEnabled(); protected static final boolean DEBUG_ENABLED = LOG.isDebugEnabled();
private final SessionFactoryImplementor factory; private final SessionFactoryImplementor factory;
private ColumnNameCache columnNameCache; private volatile ColumnNameCache columnNameCache;
private final boolean referenceCachingEnabled; private final boolean referenceCachingEnabled;
@ -2085,9 +2085,7 @@ public abstract class Loader {
} }
private synchronized ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplementor session) { private 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.
if ( session.getFactory().getSettings().isWrapResultSetsEnabled() ) { if ( session.getFactory().getSettings().isWrapResultSetsEnabled() ) {
try { try {
LOG.debugf( "Wrapping result set [%s]", rs ); LOG.debugf( "Wrapping result set [%s]", rs );
@ -2105,12 +2103,15 @@ public abstract class Loader {
} }
} }
private ColumnNameCache retreiveColumnNameToIndexCache(ResultSet rs) throws SQLException { private ColumnNameCache retreiveColumnNameToIndexCache(final ResultSet rs) throws SQLException {
if ( columnNameCache == null ) { if ( columnNameCache == null ) {
LOG.trace( "Building columnName -> columnIndex cache" ); synchronized ( this ) {
columnNameCache = new ColumnNameCache( rs.getMetaData().getColumnCount() ); if ( columnNameCache == null ) {
LOG.trace( "Building columnName -> columnIndex cache" );
columnNameCache = new ColumnNameCache( rs.getMetaData().getColumnCount() );
}
}
} }
return columnNameCache; return columnNameCache;
} }