Top Description Fields Constructors Methods
org.hibernate.engine.loading

public Class LoadContexts

extends Object
Class Inheritance
Imports
java.sql.ResultSet, java.util.Map, .Set, .Iterator, .HashMap, java.io.Serializable, org.slf4j.Logger, .LoggerFactory, org.hibernate.util.IdentityMap, org.hibernate.engine.PersistenceContext, .CollectionKey, .SessionImplementor, org.hibernate.collection.PersistentCollection, org.hibernate.persister.collection.CollectionPersister, org.hibernate.pretty.MessageHelper, org.hibernate.EntityMode

Maps result-sets to specific contextual data related to processing that result-sets.

Implementation Note

internally an IdentityMap is used to maintain the mappings; IdentityMap was chosen because I'd rather not be dependent upon potentially bad ResultSet#equals and {ResultSet#hashCode} implementations.

Considering the JDBC-redesign work, would further like this contextual info not mapped seperately, but available based on the result set being processed. This would also allow maintaining a single mapping as we could reliably get notification of the result-set closing...

Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private Map<K, V>
private Map<K, V>
private static final Logger
private final PersistenceContext
private Map<K, V>

Constructor Summary

AccessConstructor and Description
public
LoadContexts(PersistenceContext
The persistence context to which this will be bound.
persistenceContext
)

Creates and binds this to the given persistence context.

Method Summary

Modifier and TypeMethod and Description
public void
cleanup(ResultSet
The result set for which it is ok to release associated resources.
resultSet
)

Release internal state associated with the given result set.

public void
cleanup()

Release internal state associated with *all* result sets.

pack-priv void
public CollectionLoadContext

Returns:

The processing context.
getCollectionLoadContext
(ResultSet
The result set for which to retrieve the context.
resultSet
)

Get the CollectionLoadContext associated with the given ResultSet, creating one if needed.

public EntityLoadContext
private EntityMode
pack-priv Map<K, V>
public PersistenceContext

Returns:

The persistence context to which this is bound.
getPersistenceContext
()

Retrieves the persistence context to which this is bound.

private SessionImplementor
public boolean

Returns:

True if we currently hold state pertaining to loading collections; false otherwise.
hasLoadingCollectionEntries
()

Do we currently have any internal entries corresponding to loading collections?

public boolean

Returns:

True if we currently hold state pertaining to a registered loading collections; false otherwise.
hasRegisteredLoadingCollectionEntries
()

Do we currently have any registered internal entries corresponding to loading collections?

public PersistentCollection

Returns:

The loading collection, or null if not found.
locateLoadingCollection
(CollectionPersister
The collection persister
persister
,
Serializable
The owner key
ownerKey
)

Attempt to locate the loading collection given the owner's key.

pack-priv LoadingCollectionEntry

Returns:

The located entry; or null.
locateLoadingCollectionEntry
(CollectionKey
The collection key.
key
)

Locate the LoadingCollectionEntry within *any* of the tracked CollectionLoadContexts.

pack-priv void
registerLoadingCollectionXRef(CollectionKey
The xref collection key
entryKey
,
LoadingCollectionEntry
The corresponding loading collection entry
entry
)

Register a loading collection xref.

pack-priv void
unregisterLoadingCollectionXRef(CollectionKey
The key of the collection we are done processing.
key
)

The inverse of registerLoadingCollectionXRef.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

collectionLoadContextsback to summary
private Map<K, V> collectionLoadContexts
entityLoadContextsback to summary
private Map<K, V> entityLoadContexts
logback to summary
private static final Logger log
persistenceContextback to summary
private final PersistenceContext persistenceContext
xrefLoadingCollectionEntriesback to summary
private Map<K, V> xrefLoadingCollectionEntries

Constructor Detail

LoadContextsback to summary
public LoadContexts(PersistenceContext persistenceContext)

Creates and binds this to the given persistence context.

Parameters
persistenceContext:PersistenceContext

The persistence context to which this will be bound.

Method Detail

cleanupback to summary
public void cleanup(ResultSet resultSet)

Release internal state associated with the given result set.

This should be called when we are done with processing said result set, ideally as the result set is being closed.

Parameters
resultSet:ResultSet

The result set for which it is ok to release associated resources.

cleanupback to summary
public void cleanup()

Release internal state associated with *all* result sets.

This is intended as a "failsafe" process to make sure we get everything cleaned up and released.

cleanupCollectionXRefsback to summary
pack-priv void cleanupCollectionXRefs(Set<E> entryKeys)
getCollectionLoadContextback to summary
public CollectionLoadContext getCollectionLoadContext(ResultSet resultSet)

Get the CollectionLoadContext associated with the given ResultSet, creating one if needed.

Parameters
resultSet:ResultSet

The result set for which to retrieve the context.

Returns:CollectionLoadContext

The processing context.

getEntityLoadContextback to summary
public EntityLoadContext getEntityLoadContext(ResultSet resultSet)
getEntityModeback to summary
private EntityMode getEntityMode()
getLoadingCollectionXRefsback to summary
pack-priv Map<K, V> getLoadingCollectionXRefs()
getPersistenceContextback to summary
public PersistenceContext getPersistenceContext()

Retrieves the persistence context to which this is bound.

Returns:PersistenceContext

The persistence context to which this is bound.

getSessionback to summary
private SessionImplementor getSession()
hasLoadingCollectionEntriesback to summary
public boolean hasLoadingCollectionEntries()

Do we currently have any internal entries corresponding to loading collections?

Returns:boolean

True if we currently hold state pertaining to loading collections; false otherwise.

hasRegisteredLoadingCollectionEntriesback to summary
public boolean hasRegisteredLoadingCollectionEntries()

Do we currently have any registered internal entries corresponding to loading collections?

Returns:boolean

True if we currently hold state pertaining to a registered loading collections; false otherwise.

locateLoadingCollectionback to summary
public PersistentCollection locateLoadingCollection(CollectionPersister persister, Serializable ownerKey)

Attempt to locate the loading collection given the owner's key. The lookup here occurs against all result-set contexts...

Parameters
persister:CollectionPersister

The collection persister

ownerKey:Serializable

The owner key

Returns:PersistentCollection

The loading collection, or null if not found.

locateLoadingCollectionEntryback to summary
pack-priv LoadingCollectionEntry locateLoadingCollectionEntry(CollectionKey key)

Locate the LoadingCollectionEntry within *any* of the tracked CollectionLoadContexts.

Implementation Note

package protected, as this is meant solely for use by CollectionLoadContext to be able to locate collections being loaded by other CollectionLoadContexts/ResultSets.

Parameters
key:CollectionKey

The collection key.

Returns:LoadingCollectionEntry

The located entry; or null.

registerLoadingCollectionXRefback to summary
pack-priv void registerLoadingCollectionXRef(CollectionKey entryKey, LoadingCollectionEntry entry)

Register a loading collection xref.

This xref map is used because sometimes a collection is in process of being loaded from one result set, but needs to be accessed from the context of another "nested" result set processing.

Implementation Note

package protected, as this is meant solely for use by CollectionLoadContext to be able to locate collections being loaded by other CollectionLoadContexts/ResultSets.

Parameters
entryKey:CollectionKey

The xref collection key

entry:LoadingCollectionEntry

The corresponding loading collection entry

unregisterLoadingCollectionXRefback to summary
pack-priv void unregisterLoadingCollectionXRef(CollectionKey key)

The inverse of registerLoadingCollectionXRef. Here, we are done processing the said collection entry, so we remove it from the load context.

The idea here is that other loading collections can now reference said collection directly from the PersistenceContext because it has completed its load cycle.

Implementation Note

package protected, as this is meant solely for use by CollectionLoadContext to be able to locate collections being loaded by other CollectionLoadContexts/ResultSets.

Parameters
key:CollectionKey

The key of the collection we are done processing.