HHH-1775 - collection batch fetching

This commit is contained in:
Steve Ebersole 2012-10-26 14:19:02 -05:00
parent 85fa6bc141
commit 8dbe1b61dc
7 changed files with 29 additions and 1 deletions

View File

@ -896,6 +896,9 @@ private Serializable getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) {
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) { public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) {
CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing); CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
addCollection(collection, ce, id); addCollection(collection, ce, id);
if ( persister.getBatchSize() > 1 ) {
getBatchFetchQueue().addBatchLoadableCollection( collection, ce );
}
} }
/** /**
@ -905,6 +908,9 @@ public void addUninitializedCollection(CollectionPersister persister, Persistent
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) { public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) {
CollectionEntry ce = new CollectionEntry( persister, collection.getKey() ); CollectionEntry ce = new CollectionEntry( persister, collection.getKey() );
addCollection( collection, ce, collection.getKey() ); addCollection( collection, ce, collection.getKey() );
if ( persister.getBatchSize() > 1 ) {
getBatchFetchQueue().addBatchLoadableCollection( collection, ce );
}
} }
/** /**

View File

@ -34,6 +34,7 @@
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.collection.internal.AbstractPersistentCollection;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
@ -215,6 +216,12 @@ public void postInitialize(PersistentCollection collection) throws HibernateExce
collection.getSnapshot( getLoadedPersister() ) : collection.getSnapshot( getLoadedPersister() ) :
null; null;
collection.setSnapshot(loadedKey, role, snapshot); collection.setSnapshot(loadedKey, role, snapshot);
if ( getLoadedPersister().getBatchSize() > 1 ) {
( (AbstractPersistentCollection) collection ).getSession()
.getPersistenceContext()
.getBatchFetchQueue()
.removeBatchLoadableCollection( this );
}
} }
/** /**

View File

@ -83,6 +83,9 @@ private void evictCollection(PersistentCollection collection) {
ce.getLoadedKey(), ce.getLoadedKey(),
getSession() ) ); getSession() ) );
} }
if ( ce.getLoadedPersister() != null && ce.getLoadedPersister().getBatchSize() > 1 ) {
getSession().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection( ce );
}
if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) { if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) {
//TODO: is this 100% correct? //TODO: is this 100% correct?
getSession().getPersistenceContext().getCollectionsByKey().remove( getSession().getPersistenceContext().getCollectionsByKey().remove(

View File

@ -1913,6 +1913,11 @@ public CollectionInitializer getInitializer() {
return initializer; return initializer;
} }
@Override
public int getBatchSize() {
return batchSize;
}
private class StandardOrderByAliasResolver implements OrderByAliasResolver { private class StandardOrderByAliasResolver implements OrderByAliasResolver {
private final String rootAlias; private final String rootAlias;

View File

@ -307,4 +307,6 @@ public void insertRows(
public boolean indexExists(Serializable key, Object index, SessionImplementor session); public boolean indexExists(Serializable key, Object index, SessionImplementor session);
public boolean elementExists(Serializable key, Object element, SessionImplementor session); public boolean elementExists(Serializable key, Object element, SessionImplementor session);
public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner); public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner);
public int getBatchSize();
} }

View File

@ -169,7 +169,7 @@ private void scheduleBatchLoadIfNeeded(Serializable id, SessionImplementor sessi
if ( uniqueKeyPropertyName == null && id != null ) { if ( uniqueKeyPropertyName == null && id != null ) {
final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
final EntityKey entityKey = session.generateEntityKey( id, persister ); final EntityKey entityKey = session.generateEntityKey( id, persister );
if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { if ( entityKey.isBatchLoadable() && !session.getPersistenceContext().containsEntity( entityKey ) ) {
session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
} }
} }

View File

@ -802,5 +802,10 @@ public boolean elementExists(Serializable key, Object element, SessionImplemento
public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner) { public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner) {
return null; //To change body of implemented methods use File | Settings | File Templates. return null; //To change body of implemented methods use File | Settings | File Templates.
} }
@Override
public int getBatchSize() {
return 0;
}
} }
} }