HHH-13442 CollectionType#getCollection() method improvements

This commit is contained in:
Andrea Boriero 2019-06-19 15:11:13 +01:00 committed by Sanne Grinovero
parent 2c1d862137
commit e13386769c
2 changed files with 20 additions and 18 deletions

View File

@ -159,20 +159,20 @@ public class LoadContexts {
}
/**
* Attempt to locate the loading collection given the owner's key. The lookup here
* Attempt to locate the loading collection given the CollectionKey obtained from the owner's key. The lookup here
* occurs against all result-set contexts...
*
* @param persister The collection persister
* @param ownerKey The owner key
* @param key The collection key
* @return The loading collection, or null if not found.
*/
public PersistentCollection locateLoadingCollection(CollectionPersister persister, Serializable ownerKey) {
final LoadingCollectionEntry lce = locateLoadingCollectionEntry( new CollectionKey( persister, ownerKey ) );
public PersistentCollection locateLoadingCollection(CollectionPersister persister, CollectionKey key) {
final LoadingCollectionEntry lce = locateLoadingCollectionEntry( key ) ;
if ( lce != null ) {
if ( LOG.isTraceEnabled() ) {
LOG.tracef(
"Returning loading collection: %s",
MessageHelper.collectionInfoString( persister, ownerKey, getSession().getFactory() )
MessageHelper.collectionInfoString( persister, key.getKey(), getSession().getFactory() )
);
}
return lce.getCollection();

View File

@ -769,21 +769,23 @@ public abstract class CollectionType extends AbstractType implements Association
*/
public Object getCollection(Serializable key, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) {
CollectionPersister persister = getPersister( session );
final CollectionPersister persister = getPersister( session );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
final CollectionKey collectionKey = new CollectionKey( persister, key );
// check if collection is currently being loaded
PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
PersistentCollection collection = persistenceContext.getLoadContexts()
.locateLoadingCollection( persister, collectionKey );
if ( collection == null ) {
// check if it is already completely loaded, but unowned
collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
collection = persistenceContext.useUnownedCollection( collectionKey );
if ( collection == null ) {
collection = persistenceContext.getCollection( new CollectionKey(persister, key, entityMode) );
collection = persistenceContext.getCollection( collectionKey );
if ( collection == null ) {
// create a new collection wrapper, to be initialized later
@ -805,19 +807,19 @@ public abstract class CollectionType extends AbstractType implements Association
if ( hasHolder() ) {
session.getPersistenceContext().addCollectionHolder( collection );
}
if ( LOG.isTraceEnabled() ) {
LOG.tracef( "Created collection wrapper: %s",
MessageHelper.collectionInfoString( persister, collection,
key, session ) );
}
// we have already set the owner so we can just return the value
return collection.getValue();
}
}
if ( LOG.isTraceEnabled() ) {
LOG.tracef( "Created collection wrapper: %s",
MessageHelper.collectionInfoString( persister, collection,
key, session ) );
}
}
collection.setOwner(owner);
collection.setOwner( owner );
return collection.getValue();
}