HHH-13496 Loop optimisations

This commit is contained in:
Sanne Grinovero 2019-07-08 18:19:09 +01:00
parent b2eaf4e88d
commit 433a7904c1
1 changed files with 12 additions and 7 deletions

View File

@ -48,6 +48,8 @@ import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.jdbc.ColumnNameCache;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.loading.internal.CollectionLoadContext;
import org.hibernate.engine.spi.BatchFetchQueue;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.EntityUniqueKey;
@ -998,8 +1000,9 @@ public abstract class Loader {
LOG.trace( "Processing result set" );
int count;
final boolean debugEnabled = LOG.isDebugEnabled();
for ( count = 0; count < maxRows && rs.next(); count++ ) {
if ( LOG.isDebugEnabled() ) {
if ( debugEnabled ) {
LOG.debugf( "Result set row: %s", count );
}
Object result = getRowFromResultSet(
@ -1071,6 +1074,7 @@ public abstract class Loader {
final String[] aliases = getAliases();
final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment( queryParameters );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final BatchFetchQueue batchFetchQueue = persistenceContext.getBatchFetchQueue();
for ( Object key : keys ) {
final EntityKey[] rowKeys = (EntityKey[]) key;
for ( int i = 0; i < rowKeys.length; i++ ) {
@ -1086,8 +1090,7 @@ public abstract class Loader {
namedParameterLocMap
);
persistenceContext
.getBatchFetchQueue()
batchFetchQueue
.addSubselect( rowKeys[i], subselectFetch );
}
@ -1458,19 +1461,21 @@ public abstract class Loader {
// that the collection is empty and has no rows in the result set
CollectionPersister[] collectionPersisters = getCollectionPersisters();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final boolean debugEnabled = LOG.isDebugEnabled();
final CollectionLoadContext collectionLoadContext = persistenceContext
.getLoadContexts()
.getCollectionLoadContext( (ResultSet) resultSetId );
for ( CollectionPersister collectionPersister : collectionPersisters ) {
for ( Serializable key : keys ) {
//handle empty collections
if ( LOG.isDebugEnabled() ) {
if ( debugEnabled ) {
LOG.debugf(
"Result set contains (possibly empty) collection: %s",
MessageHelper.collectionInfoString( collectionPersister, key, getFactory() )
);
}
persistenceContext
.getLoadContexts()
.getCollectionLoadContext( (ResultSet) resultSetId )
collectionLoadContext
.getLoadingCollection( collectionPersister, key );
}
}