Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.hibernate.engine.StatefulPersistenceContext
Field Summary | |
static Object |
Constructor Summary | |
|
Method Summary | |
void |
|
EntityEntry |
|
void | |
void |
|
EntityEntry |
|
CollectionEntry |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
int | |
static StatefulPersistenceContext |
|
BatchFetchQueue |
|
Object[] |
|
int |
|
PersistentCollection |
|
Map | |
CollectionEntry |
|
CollectionEntry |
|
PersistentCollection |
|
Object |
|
Map | |
Object[] |
|
Map | |
Object | |
Object |
|
Map | |
EntityEntry |
|
Object |
|
LoadContexts | |
Serializable |
|
Object |
|
Object[] |
|
HashSet |
|
Serializable |
|
Object | |
SessionImplementor | |
Serializable |
|
boolean | |
int | |
void |
|
boolean |
|
boolean | |
boolean |
|
boolean | |
Object |
|
Object |
|
Object |
|
boolean |
|
void |
|
PersistentCollection |
|
Object |
|
EntityEntry |
|
Object |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
Object |
|
Object |
|
PersistentCollection |
public StatefulPersistenceContext(SessionImplementor session)
Constructs a PersistentContext, bound to the given session.
- Parameters:
session
- The session "owning" this context.
public void addCollectionHolder(PersistentCollection holder)
Register a PersistentCollection object for an array. Associates a holder with an array - MUST be called after loading array, since the array instance is not created until endLoad().
- Specified by:
- addCollectionHolder in interface PersistenceContext
public EntityEntry addEntity(Object entity, Status status, Object[] loadedState, EntityKey entityKey, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)
Adds an entity to the internal caches.
- Specified by:
- addEntity in interface PersistenceContext
public void addEntity(EntityKey key, Object entity)
- Specified by:
- addEntity in interface PersistenceContext
public void addEntity(EntityUniqueKey euk, Object entity)
Add an entity to the cache by unique key
- Specified by:
- addEntity in interface PersistenceContext
public EntityEntry addEntry(Object entity, Status status, Object[] loadedState, Object rowId, Serializable id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)
Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.
- Specified by:
- addEntry in interface PersistenceContext
public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) throws HibernateException
add a collection we just pulled out of the cache (does not need initializing)
- Specified by:
- addInitializedCollection in interface PersistenceContext
public void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection) throws HibernateException
add an (initialized) collection that was created by another session and passed into update() (ie. one with a snapshot and existing state on the database)
- Specified by:
- addInitializedDetachedCollection in interface PersistenceContext
public void addNewCollection(CollectionPersister persister, PersistentCollection collection) throws HibernateException
Add a new collection (ie. a newly created one, just instantiated by the application, with no database state or snapshot)
- Specified by:
- addNewCollection in interface PersistenceContext
- Parameters:
collection
- The collection to be associated with the persistence context
public void addNonLazyCollection(PersistentCollection collection)
Register a collection for non-lazy loading at the end of the two-phase load
- Specified by:
- addNonLazyCollection in interface PersistenceContext
public void addNullProperty(EntityKey ownerKey, String propertyName)
Record the fact that the association belonging to the keyed entity is null.
- Specified by:
- addNullProperty in interface PersistenceContext
public void addProxy(EntityKey key, Object proxy)
Add a proxy to the session cache
- Specified by:
- addProxy in interface PersistenceContext
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)
add a collection we just loaded up (still needs initializing)
- Specified by:
- addUninitializedCollection in interface PersistenceContext
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection)
add a detached uninitialized collection
- Specified by:
- addUninitializedDetachedCollection in interface PersistenceContext
public void addUnownedCollection(CollectionKey key, PersistentCollection collection)
- Specified by:
- addUnownedCollection in interface PersistenceContext
public void afterLoad()
Call this after finishing a two-phase load
- Specified by:
- afterLoad in interface PersistenceContext
public void afterTransactionCompletion()
- Specified by:
- afterTransactionCompletion in interface PersistenceContext
public void beforeLoad()
Call this before begining a two-phase load
- Specified by:
- beforeLoad in interface PersistenceContext
public void checkUniqueness(EntityKey key, Object object) throws HibernateException
Attempts to check whether the given key represents an entity already loaded within the current session.
- Specified by:
- checkUniqueness in interface PersistenceContext
- Parameters:
object
- The entity reference against which to perform the uniqueness check.
- Throws:
HibernateException
-
public boolean containsCollection(PersistentCollection collection)
- Specified by:
- containsCollection in interface PersistenceContext
public boolean containsEntity(EntityKey key)
- Specified by:
- containsEntity in interface PersistenceContext
public boolean containsProxy(Object entity)
- Specified by:
- containsProxy in interface PersistenceContext
public int decrementCascadeLevel()
- Specified by:
- decrementCascadeLevel in interface PersistenceContext
public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException
public BatchFetchQueue getBatchFetchQueue()
Get the BatchFetchQueue, instantiating one if necessary.
- Specified by:
- getBatchFetchQueue in interface PersistenceContext
public Object[] getCachedDatabaseSnapshot(EntityKey key)
Retrieve the cached database snapshot for the requested entity key. This differs fromgetDatabaseSnapshot(Serializable,EntityPersister)
is two important respects:
- no snapshot is obtained from the database if not already cached
- an entry of
NO_ROW
here is interpretet as an exception
- Specified by:
- getCachedDatabaseSnapshot in interface PersistenceContext
- Parameters:
key
- The entity key for which to retrieve the cached snapshot
- Returns:
- The cached snapshot
public int getCascadeLevel()
Do we already know that the entity does not exist in the database?
- Specified by:
- getCascadeLevel in interface PersistenceContext
public PersistentCollection getCollection(CollectionKey collectionKey)
Get the collection instance associated with the CollectionKey
- Specified by:
- getCollection in interface PersistenceContext
public Map getCollectionEntries()
- Specified by:
- getCollectionEntries in interface PersistenceContext
public CollectionEntry getCollectionEntry(PersistentCollection coll)
Get the collection entry for a persistent collection
- Specified by:
- getCollectionEntry in interface PersistenceContext
public CollectionEntry getCollectionEntryOrNull(Object collection)
Get the collection entry for a collection passed to filter, which might be a collection wrapper, an array, or an unwrapped collection. Return null if there is no entry.
- Specified by:
- getCollectionEntryOrNull in interface PersistenceContext
public PersistentCollection getCollectionHolder(Object array)
Get the PersistentCollection object for an array
- Specified by:
- getCollectionHolder in interface PersistenceContext
public Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister) throws MappingException
Get the entity that owns this persistent collection
- Specified by:
- getCollectionOwner in interface PersistenceContext
public Map getCollectionsByKey()
- Specified by:
- getCollectionsByKey in interface PersistenceContext
public Object[] getDatabaseSnapshot(Serializable id, EntityPersister persister) throws HibernateException
Get the current state of the entity as known to the underlying database, or null if there is no corresponding row
- Specified by:
- getDatabaseSnapshot in interface PersistenceContext
public Map getEntitiesByKey()
- Specified by:
- getEntitiesByKey in interface PersistenceContext
public Object getEntity(EntityKey key)
Get the entity instance associated with the given EntityKey
- Specified by:
- getEntity in interface PersistenceContext
public Object getEntity(EntityUniqueKey euk)
Get an entity cached by unique key
- Specified by:
- getEntity in interface PersistenceContext
public Map getEntityEntries()
- Specified by:
- getEntityEntries in interface PersistenceContext
public EntityEntry getEntry(Object entity)
Retreive the EntityEntry representation of the given entity.
- Specified by:
- getEntry in interface PersistenceContext
- Parameters:
entity
- The entity for which to locate the EntityEntry.
- Returns:
- The EntityEntry for the given entity.
public Object getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap)
Search the persistence context for an index of the child object, given a collection role
- Specified by:
- getIndexInOwner in interface PersistenceContext
public LoadContexts getLoadContexts()
- Specified by:
- getLoadContexts in interface PersistenceContext
public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)
Get the ID for the entity that owned this persistent collection when it was loaded
- Specified by:
- getLoadedCollectionOwnerIdOrNull in interface PersistenceContext
- Parameters:
collection
- The persistent collection
- Returns:
- the owner ID if available from the collection's loaded key; otherwise, returns null
public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection)
Get the entity that owned this persistent collection when it was loaded
- Specified by:
- getLoadedCollectionOwnerOrNull in interface PersistenceContext
- Parameters:
collection
- The persistent collection
- 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
public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister) throws HibernateException
- Specified by:
- getNaturalIdSnapshot in interface PersistenceContext
public HashSet getNullifiableEntityKeys()
Retrieve the set of EntityKeys representing nullifiable references
- Specified by:
- getNullifiableEntityKeys in interface PersistenceContext
public Serializable getOwnerId(String entityName, String propertyName, Object childEntity, Map mergeMap)
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. This is performed in the scenario of a uni-directional, non-inverse one-to-many collection (which means that the collection elements do not maintain a direct reference to the owner). As such, the processing here is basically to loop over every entity currently associated with this persistence context and for those of the correct entity (sub) type to extract its collection role property value and see if the child is contained within that collection. If so, we have found the owner; if not, we go on. Also need to account for mergeMap which acts as a local copy cache managed for the duration of a merge operation. It represents a map of the detached entity instances pointing to the corresponding managed instance.
- Specified by:
- getOwnerId in interface PersistenceContext
- Parameters:
entityName
- The entity name for the entity type which would own the childpropertyName
- The name of the property on the owning entity type which would name this child association.childEntity
- The child entity instance for which to locate the owner instance id.mergeMap
- A map of non-persistent instances from an on-going merge operation (possibly null).
- Returns:
- The id of the entityName instance which is said to own the child; null if an appropriate owner not located.
public Object getProxy(EntityKey key)
Get an existing proxy by key
- Specified by:
- getProxy in interface PersistenceContext
public SessionImplementor getSession()
- Specified by:
- getSession in interface PersistenceContext
public Serializable getSnapshot(PersistentCollection coll)
Get the snapshot of the pre-flush collection state
- Specified by:
- getSnapshot in interface PersistenceContext
public boolean hasNonReadOnlyEntities()
- Specified by:
- hasNonReadOnlyEntities in interface PersistenceContext
public int incrementCascadeLevel()
- Specified by:
- incrementCascadeLevel in interface PersistenceContext
public void initializeNonLazyCollections() throws HibernateException
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)
- Specified by:
- initializeNonLazyCollections in interface PersistenceContext
public boolean isEntryFor(Object entity)
Is there an EntityEntry for this instance?
- Specified by:
- isEntryFor in interface PersistenceContext
public boolean isPropertyNull(EntityKey ownerKey, String propertyName)
Is the association property belonging to the keyed entity null?
- Specified by:
- isPropertyNull in interface PersistenceContext
public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object) throws HibernateException
If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one. This breaks == and occurs only for "class" proxies rather than "interface" proxies. Also init the proxy to point to the given target implementation if necessary.
- Specified by:
- narrowProxy in interface PersistenceContext
- Parameters:
proxy
- The proxy instance to be narrowed.persister
- The persister for the proxied entity.key
- The internal cache key for the proxied entity.object
- (optional) the actual proxied entity instance.
- Returns:
- An appropriately narrowed instance.
- Throws:
HibernateException
-
public Object proxyFor(Object impl) throws HibernateException
Return the existing proxy associated with the given EntityKey, or the argument (the entity associated with the key) if no proxy exists. (slower than the form above)
- Specified by:
- proxyFor in interface PersistenceContext
public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException
Return the existing proxy associated with the given EntityKey, or the third argument (the entity associated with the key) if no proxy exists. Init the proxy to the target implementation, if necessary.
- Specified by:
- proxyFor in interface PersistenceContext
public boolean reassociateIfUninitializedProxy(Object value) throws MappingException
Takes the given object and, if it represents a proxy, reassociates it with this event source.
- Specified by:
- reassociateIfUninitializedProxy in interface PersistenceContext
- Parameters:
value
- The possible proxy to be reassociated.
- Returns:
- Whether the passed value represented an actual proxy which got initialized.
- Throws:
MappingException
-
public void reassociateProxy(Object value, Serializable id) throws MappingException
If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy
- Specified by:
- reassociateProxy in interface PersistenceContext
public PersistentCollection removeCollectionHolder(Object array)
- Specified by:
- removeCollectionHolder in interface PersistenceContext
public Object removeEntity(EntityKey key)
Remove an entity from the session cache, also clear up other state associated with the entity, all except for the EntityEntry
- Specified by:
- removeEntity in interface PersistenceContext
public EntityEntry removeEntry(Object entity)
Remove an entity entry from the session cache
- Specified by:
- removeEntry in interface PersistenceContext
public Object removeProxy(EntityKey key)
Remove a proxy from the session cache. Additionally, ensure that any load optimization references such as batch or subselect loading get cleaned up as well.
- Specified by:
- removeProxy in interface PersistenceContext
- Parameters:
key
- The key of the entity proxy to be removed
- Returns:
- The proxy reference.
public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId)
- Specified by:
- replaceDelayedEntityIdentityInsertKeys in interface PersistenceContext
public void serialize(ObjectOutputStream oos) throws IOException
Used by the owning session to explicitly control serialization of the persistence context.
- Parameters:
oos
- The stream to which the persistence context should get written
public void setEntryStatus(EntityEntry entry, Status status)
- Specified by:
- setEntryStatus in interface PersistenceContext
public void setFlushing(boolean flushing)
- Specified by:
- setFlushing in interface PersistenceContext
public void setReadOnly(Object entity, boolean readOnly)
- Specified by:
- setReadOnly in interface PersistenceContext
public String toString()
Returns a string representation of the object.
- Specified by:
- toString in interface PersistenceContext
- Returns:
- a string representation of the object.
public Object unproxy(Object maybeProxy) throws HibernateException
Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized. If the given object is not a proxy, simply return the argument.
- Specified by:
- unproxy in interface PersistenceContext
public Object unproxyAndReassociate(Object maybeProxy) throws HibernateException
Possibly unproxy the given reference and reassociate it with the current session.
- Specified by:
- unproxyAndReassociate in interface PersistenceContext
- Parameters:
maybeProxy
- The reference to be unproxied if it currently represents a proxy.
- Returns:
- The unproxied instance.
- Throws:
HibernateException
-
public PersistentCollection useUnownedCollection(CollectionKey key)
- Specified by:
- useUnownedCollection in interface PersistenceContext