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 @@ public class StatefulPersistenceContext implements PersistenceContext {
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) {
CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
addCollection(collection, ce, id);
if ( persister.getBatchSize() > 1 ) {
getBatchFetchQueue().addBatchLoadableCollection( collection, ce );
}
}
/**
@ -905,6 +908,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) {
CollectionEntry ce = new CollectionEntry( persister, collection.getKey() );
addCollection( collection, ce, collection.getKey() );
if ( persister.getBatchSize() > 1 ) {
getBatchFetchQueue().addBatchLoadableCollection( collection, ce );
}
}
/**

View File

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

View File

@ -83,6 +83,9 @@ public class EvictVisitor extends AbstractVisitor {
ce.getLoadedKey(),
getSession() ) );
}
if ( ce.getLoadedPersister() != null && ce.getLoadedPersister().getBatchSize() > 1 ) {
getSession().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection( ce );
}
if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) {
//TODO: is this 100% correct?
getSession().getPersistenceContext().getCollectionsByKey().remove(

View File

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

View File

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

View File

@ -169,7 +169,7 @@ public class ManyToOneType extends EntityType {
if ( uniqueKeyPropertyName == null && id != null ) {
final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
final EntityKey entityKey = session.generateEntityKey( id, persister );
if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {
if ( entityKey.isBatchLoadable() && !session.getPersistenceContext().containsEntity( entityKey ) ) {
session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
}
}

View File

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