Top Description Fields Constructors Methods
org.hibernate.engine

public Class StatefulPersistenceContext

extends Object
implements PersistenceContext
Class Inheritance
All Implemented Interfaces
org.hibernate.engine.PersistenceContext
Imports
java.io.IOException, .InvalidObjectException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.ArrayList, .HashMap, .HashSet, .Iterator, .List, .Map, org.apache.commons.collections.map.ReferenceMap, org.slf4j.Logger, .LoggerFactory, org.hibernate.AssertionFailure, .Hibernate, .HibernateException, .LockMode, .MappingException, .NonUniqueObjectException, .PersistentObjectException, .TransientObjectException, org.hibernate.engine.loading.LoadContexts, org.hibernate.pretty.MessageHelper, org.hibernate.collection.PersistentCollection, org.hibernate.persister.collection.CollectionPersister, org.hibernate.persister.entity.EntityPersister, org.hibernate.proxy.HibernateProxy, .LazyInitializer, org.hibernate.tuple.ElementWrapper, org.hibernate.util.IdentityMap, .MarkerObject

A PersistenceContext represents the state of persistent "stuff" which Hibernate is tracking. This includes persistent entities, collections, as well as proxies generated.

There is meant to be a one-to-one correspondence between a SessionImpl and a PersistentContext. The SessionImpl uses the PersistentContext to track the current state of its context. Event-listeners then use the PersistentContext to drive their processing.
Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private Map<K, V>
private BatchFetchQueue
private int
private Map<K, V>
private Map<K, V>
private boolean
private Map<K, V>
private Map<K, V>
private Map<K, V>
private Map<K, V>
private boolean
private boolean
private static final int
private HashMap<String, List<Serializable>>
private LoadContexts
private int
private static final Logger
public static final Object
private List<E>
private HashSet<E>
private HashSet<E>
private Map<K, V>
private Map<K, V>
private static final Logger
private SessionImplementor
private Map<K, V>

Constructor Summary

AccessConstructor and Description
public
StatefulPersistenceContext(SessionImplementor
The session "owning" this context.
session
)

Constructs a PersistentContext, bound to the given session.

Method Summary

Modifier and TypeMethod and Description
public void
addChildParent(Object child, Object parent)

Implements org.hibernate.engine.PersistenceContext.addChildParent.

Put child/parent relation to cache for cascading op
private void
addCollection(PersistentCollection
The collection for which we are adding an entry.
coll
,
CollectionEntry
The entry representing the collection.
entry
,
Serializable
The key of the collection's entry.
key
)

Add an collection to the cache, with a given collection entry.

private void
addCollection(PersistentCollection
The collection for which we are adding an entry.
collection
,
CollectionPersister
The collection persister
persister
)

Add a collection to the cache, creating a new collection entry for it

public void
addCollectionHolder(PersistentCollection holder)

Implements org.hibernate.engine.PersistenceContext.addCollectionHolder.

Register a PersistentCollection object for an array.
public void
addEntity(EntityKey key, Object entity)

Implements org.hibernate.engine.PersistenceContext.addEntity.

Add a canonical mapping from entity key to entity instance
public void
addEntity(EntityUniqueKey euk, Object entity)

Implements org.hibernate.engine.PersistenceContext.addEntity.

Add an entity to the cache by unique key
public EntityEntry
addEntity(final Object entity, final Status status, final Object[] loadedState, final EntityKey entityKey, final Object version, final LockMode lockMode, final boolean existsInDatabase, final EntityPersister persister, final boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)

Implements org.hibernate.engine.PersistenceContext.addEntity.

Adds an entity to the internal caches.
public EntityEntry
addEntry(final Object entity, final Status status, final Object[] loadedState, final Object rowId, final Serializable id, final Object version, final LockMode lockMode, final boolean existsInDatabase, final EntityPersister persister, final boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)

Implements org.hibernate.engine.PersistenceContext.addEntry.

Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.
public CollectionEntry
addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)

Implements org.hibernate.engine.PersistenceContext.addInitializedCollection.

add a collection we just pulled out of the cache (does not need initializing)
public void
addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection)

Implements org.hibernate.engine.PersistenceContext.addInitializedDetachedCollection.

add an (initialized) collection that was created by another session and passed into update() (ie.
public void
addNewCollection(CollectionPersister persister, PersistentCollection
The collection to be associated with the persistence context
collection
)

Implements org.hibernate.engine.PersistenceContext.addNewCollection.

Add a new collection (ie.
public void
addNonLazyCollection(PersistentCollection collection)

Implements org.hibernate.engine.PersistenceContext.addNonLazyCollection.

Register a collection for non-lazy loading at the end of the two-phase load
public void
addNullProperty(EntityKey ownerKey, String propertyName)

Implements org.hibernate.engine.PersistenceContext.addNullProperty.

Record the fact that the association belonging to the keyed entity is null.
public void
addProxy(EntityKey key, Object proxy)

Implements org.hibernate.engine.PersistenceContext.addProxy.

Add a proxy to the session cache
public void
addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)

Implements org.hibernate.engine.PersistenceContext.addUninitializedCollection.

add a collection we just loaded up (still needs initializing)
public void
public void
public void
afterLoad()

Implements org.hibernate.engine.PersistenceContext.afterLoad.

Call this after finishing a two-phase load
public void
public void
beforeLoad()

Implements org.hibernate.engine.PersistenceContext.beforeLoad.

Call this before begining a two-phase load
public void
checkUniqueness(EntityKey key, Object
The entity reference against which to perform the uniqueness check.
object
)

Implements org.hibernate.engine.PersistenceContext.checkUniqueness.

Attempts to check whether the given key represents an entity already loaded within the current session.
private void
public void
clear()

Implements org.hibernate.engine.PersistenceContext.clear.

Clear the state of the persistence context
private void
public boolean
containsCollection(PersistentCollection collection)

Implements org.hibernate.engine.PersistenceContext.containsCollection.

Is the given collection associated with this persistence context?
public boolean
containsEntity(EntityKey key)

Implements org.hibernate.engine.PersistenceContext.containsEntity.

Is there an entity with the given key in the persistence context
public boolean
containsProxy(Object entity)

Implements org.hibernate.engine.PersistenceContext.containsProxy.

Is the given proxy associated with this persistence context?
public int
public static StatefulPersistenceContext
public BatchFetchQueue
getBatchFetchQueue()

Implements org.hibernate.engine.PersistenceContext.getBatchFetchQueue.

Get the BatchFetchQueue, instantiating one if necessary.
public Object[]

Returns:

The cached snapshot
getCachedDatabaseSnapshot
(EntityKey
The entity key for which to retrieve the cached snapshot
key
)

Implements org.hibernate.engine.PersistenceContext.getCachedDatabaseSnapshot.

Retrieve the cached database snapshot for the requested entity key.
public int
getCascadeLevel()

Implements org.hibernate.engine.PersistenceContext.getCascadeLevel.

Do we already know that the entity does not exist in the database?
public PersistentCollection
getCollection(CollectionKey collectionKey)

Implements org.hibernate.engine.PersistenceContext.getCollection.

Get the collection instance associated with the CollectionKey
public Map<K, V>
getCollectionEntries()

Implements org.hibernate.engine.PersistenceContext.getCollectionEntries.

Get the mapping from collection instance to collection entry
public CollectionEntry
getCollectionEntry(PersistentCollection coll)

Implements org.hibernate.engine.PersistenceContext.getCollectionEntry.

Get the collection entry for a persistent collection
public CollectionEntry
getCollectionEntryOrNull(Object collection)

Implements org.hibernate.engine.PersistenceContext.getCollectionEntryOrNull.

Get the collection entry for a collection passed to filter, which might be a collection wrapper, an array, or an unwrapped collection.
public PersistentCollection
getCollectionHolder(Object array)

Implements org.hibernate.engine.PersistenceContext.getCollectionHolder.

Get the PersistentCollection object for an array
public Object
getCollectionOwner(Serializable key, CollectionPersister collectionPersister)

Implements org.hibernate.engine.PersistenceContext.getCollectionOwner.

Get the entity that owns this persistent collection
public Map<K, V>
getCollectionsByKey()

Implements org.hibernate.engine.PersistenceContext.getCollectionsByKey.

Get the mapping from collection key to collection instance
public Object[]
getDatabaseSnapshot(Serializable id, EntityPersister persister)

Implements org.hibernate.engine.PersistenceContext.getDatabaseSnapshot.

Get the current state of the entity as known to the underlying database, or null if there is no corresponding row
public Map<K, V>
getEntitiesByKey()

Implements org.hibernate.engine.PersistenceContext.getEntitiesByKey.

Get the mapping from key value to entity instance
public Object
getEntity(EntityKey key)

Implements org.hibernate.engine.PersistenceContext.getEntity.

Get the entity instance associated with the given EntityKey
public Object
getEntity(EntityUniqueKey euk)

Implements org.hibernate.engine.PersistenceContext.getEntity.

Get an entity cached by unique key
public Map<K, V>
getEntityEntries()

Implements org.hibernate.engine.PersistenceContext.getEntityEntries.

Get the mapping from entity instance to entity entry
public EntityEntry

Returns:

The EntityEntry for the given entity.
getEntry
(Object
The entity for which to locate the EntityEntry.
entity
)

Implements org.hibernate.engine.PersistenceContext.getEntry.

Retreive the EntityEntry representation of the given entity.
public Object
getIndexInOwner(String entity, String property, Object childEntity, Map<K, V> mergeMap)

Implements org.hibernate.engine.PersistenceContext.getIndexInOwner.

Search the persistence context for an index of the child object, given a collection role
private Object
getIndexInParent(String property, Object childEntity, EntityPersister persister, CollectionPersister collectionPersister, Object potentialParent)

public LoadContexts
getLoadContexts()

Implements org.hibernate.engine.PersistenceContext.getLoadContexts.

Retrieve this persistence context's managed load context.
public Serializable

Returns:

the owner ID if available from the collection's loaded key; otherwise, returns null
getLoadedCollectionOwnerIdOrNull
(PersistentCollection
The persistent collection
collection
)

Implements org.hibernate.engine.PersistenceContext.getLoadedCollectionOwnerIdOrNull.

Get the ID for the entity that owned this persistent collection when it was loaded
private Serializable

Returns:

the owner ID if available from the collection's loaded key; otherwise, returns null
getLoadedCollectionOwnerIdOrNull
(CollectionEntry
The collection entry
ce
)

Get the ID for the entity that owned this persistent collection when it was loaded

public Object

Returns:

the owner, if its entity ID is available from the collection's loaded key and the owner entity is in the persistence context; otherwise, returns null
getLoadedCollectionOwnerOrNull
(PersistentCollection
The persistent collection
collection
)

Implements org.hibernate.engine.PersistenceContext.getLoadedCollectionOwnerOrNull.

Get the entity that owned this persistent collection when it was loaded
public Object[]
getNaturalIdSnapshot(Serializable id, EntityPersister persister)

Implements org.hibernate.engine.PersistenceContext.getNaturalIdSnapshot.

Get the values of the natural id fields as known to the underlying database, or null if the entity has no natural id or there is no corresponding row.
public HashSet<E>
getNullifiableEntityKeys()

Implements org.hibernate.engine.PersistenceContext.getNullifiableEntityKeys.

Retrieve the set of EntityKeys representing nullifiable references
public Serializable

Returns:

The id of the entityName instance which is said to own the child; null if an appropriate owner not located.
getOwnerId
(String
The entity name for the entity type which would own the child
entityName
,
String
The name of the property on the owning entity type which would name this child association.
propertyName
,
Object
The child entity instance for which to locate the owner instance id.
childEntity
,
Map<K, V>
A map of non-persistent instances from an on-going merge operation (possibly null).
mergeMap
)

Implements org.hibernate.engine.PersistenceContext.getOwnerId.

Search this persistence context for an associated entity instance which is considered the "owner" of the given childEntity, and return that owner's id value.
public Map<K, V>
public Object
getProxy(EntityKey key)

Implements org.hibernate.engine.PersistenceContext.getProxy.

Get an existing proxy by key
public SessionImplementor
getSession()

Implements org.hibernate.engine.PersistenceContext.getSession.

Get the session to which this persistence context is bound.
public Serializable
getSnapshot(PersistentCollection coll)

Implements org.hibernate.engine.PersistenceContext.getSnapshot.

Get the snapshot of the pre-flush collection state
public boolean
public int
public void
initializeNonLazyCollections()

Implements org.hibernate.engine.PersistenceContext.initializeNonLazyCollections.

Force initialization of all non-lazy collections encountered during the current two-phase load (actually, this is a no-op, unless this is the "outermost" load)
private void
public boolean
isDefaultReadOnly()

Implements org.hibernate.engine.PersistenceContext.isDefaultReadOnly.

Will entities and proxies that are loaded into this persistence context be made read-only by default?
public boolean
isEntryFor(Object entity)

Implements org.hibernate.engine.PersistenceContext.isEntryFor.

Is there an EntityEntry for this instance?
public boolean
isFlushing()

Implements org.hibernate.engine.PersistenceContext.isFlushing.

Is a flush cycle currently in process?
private boolean
isFoundInParent(String property, Object childEntity, EntityPersister persister, CollectionPersister collectionPersister, Object potentialParent)

public boolean
public boolean
isPropertyNull(EntityKey ownerKey, String propertyName)

Implements org.hibernate.engine.PersistenceContext.isPropertyNull.

Is the association property belonging to the keyed entity null?
public boolean
isReadOnly(Object entityOrProxy)

Implements org.hibernate.engine.PersistenceContext.isReadOnly.

Is the entity or proxy read-only?
public boolean
public Object

Returns:

An appropriately narrowed instance.
narrowProxy
(Object
The proxy instance to be narrowed.
proxy
,
EntityPersister
The persister for the proxied entity.
persister
,
EntityKey
The internal cache key for the proxied entity.
key
,
Object
(optional) the actual proxied entity instance.
object
)

Implements org.hibernate.engine.PersistenceContext.narrowProxy.

If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one.
public Object
proxyFor(EntityPersister persister, EntityKey key, Object impl)

Implements org.hibernate.engine.PersistenceContext.proxyFor.

Return the existing proxy associated with the given EntityKey, or the third argument (the entity associated with the key) if no proxy exists.
public Object
proxyFor(Object impl)

Implements org.hibernate.engine.PersistenceContext.proxyFor.

Return the existing proxy associated with the given EntityKey, or the argument (the entity associated with the key) if no proxy exists.
public boolean

Returns:

Whether the passed value represented an actual proxy which got initialized.
reassociateIfUninitializedProxy
(Object
The possible proxy to be reassociated.
value
)

Implements org.hibernate.engine.PersistenceContext.reassociateIfUninitializedProxy.

Takes the given object and, if it represents a proxy, reassociates it with this event source.
public void
reassociateProxy(Object value, Serializable id)

Implements org.hibernate.engine.PersistenceContext.reassociateProxy.

If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy
private void
reassociateProxy(LazyInitializer
The proxy initializer.
li
,
HibernateProxy
The proxy to reassociate.
proxy
)

Associate a proxy that was instantiated by another session with this session

public void
registerInsertedKey(EntityPersister
The entity persister
persister
,
Serializable
The id
id
)

Implements org.hibernate.engine.PersistenceContext.registerInsertedKey.

Register keys inserted during the current transaction
public void
removeChildParent(Object child)

Implements org.hibernate.engine.PersistenceContext.removeChildParent.

Remove child/parent relation from cache
public PersistentCollection
removeCollectionHolder(Object array)

Implements org.hibernate.engine.PersistenceContext.removeCollectionHolder.

Remove the mapping of collection to holder during eviction of the owning entity
public Object
removeEntity(EntityKey key)

Implements org.hibernate.engine.PersistenceContext.removeEntity.

Remove an entity from the session cache, also clear up other state associated with the entity, all except for the EntityEntry
public EntityEntry
removeEntry(Object entity)

Implements org.hibernate.engine.PersistenceContext.removeEntry.

Remove an entity entry from the session cache
public Object

Returns:

The proxy reference.
removeProxy
(EntityKey
The key of the entity proxy to be removed
key
)

Implements org.hibernate.engine.PersistenceContext.removeProxy.

Remove a proxy from the session cache.
public void
public void
serialize(ObjectOutputStream
The stream to which the persistence context should get written
oos
)

Used by the owning session to explicitly control serialization of the persistence context.

public void
setDefaultReadOnly(boolean
true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable
defaultReadOnly
)

Implements org.hibernate.engine.PersistenceContext.setDefaultReadOnly.

Change the default for entities and proxies loaded into this persistence context from modifiable to read-only mode, or from modifiable to read-only mode.
private void
setEntityReadOnly(Object entity, boolean readOnly)

public void
setEntryStatus(EntityEntry entry, Status status)

Implements org.hibernate.engine.PersistenceContext.setEntryStatus.

Set the status of an entry
public void
setFlushing(boolean flushing)

Implements org.hibernate.engine.PersistenceContext.setFlushing.

Called before and after the flushcycle
private void
private void
setProxyReadOnly(HibernateProxy proxy, boolean readOnly)

public void
setReadOnly(Object
an entity or HibernateProxy
object
,
boolean
if true, the entity or proxy is made read-only; if false, the entity or proxy is made modifiable.
readOnly
)

Implements org.hibernate.engine.PersistenceContext.setReadOnly.

Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.
public String

Returns:

a string representation of the object.
toString
()

Overrides java.lang.Object.toString.

Implements org.hibernate.engine.PersistenceContext.toString.

Returns a string representation of the object.
public Object
unproxy(Object maybeProxy)

Implements org.hibernate.engine.PersistenceContext.unproxy.

Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized.
public Object

Returns:

The unproxied instance.
unproxyAndReassociate
(Object
The reference to be unproxied if it currently represents a proxy.
maybeProxy
)

Implements org.hibernate.engine.PersistenceContext.unproxyAndReassociate.

Possibly unproxy the given reference and reassociate it with the current session.
public PersistentCollection
useUnownedCollection(CollectionKey key)

Implements org.hibernate.engine.PersistenceContext.useUnownedCollection.

Get and remove a collection whose owner is not yet loaded, when its owner is being loaded
public boolean
wasInsertedDuringTransaction(EntityPersister
The entity persister
persister
,
Serializable
The id
id
)

Implements org.hibernate.engine.PersistenceContext.wasInsertedDuringTransaction.

Allows callers to check to see if the identified entity was inserted during the current transaction.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait