|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.hibernate.engine.StatefulPersistenceContext
public class StatefulPersistenceContext
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.
| Field Summary | |
|---|---|
static Object |
NO_ROW
|
| Constructor Summary | |
|---|---|
StatefulPersistenceContext(SessionImplementor session)
Constructs a PersistentContext, bound to the given session. |
|
| Method Summary | |
|---|---|
void |
addCollectionHolder(PersistentCollection holder)
Register a PersistentCollection object for an array. |
void |
addEntity(EntityKey key,
Object entity)
Add a canonical mapping from entity key to entity instance |
void |
addEntity(EntityUniqueKey euk,
Object entity)
Add an entity to the cache by unique key |
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. |
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. |
CollectionEntry |
addInitializedCollection(CollectionPersister persister,
PersistentCollection collection,
Serializable id)
add a collection we just pulled out of the cache (does not need initializing) |
void |
addInitializedDetachedCollection(CollectionPersister collectionPersister,
PersistentCollection collection)
add an (initialized) collection that was created by another session and passed into update() (ie. |
void |
addNewCollection(CollectionPersister persister,
PersistentCollection collection)
Add a new collection (ie. |
void |
addNonLazyCollection(PersistentCollection collection)
Register a collection for non-lazy loading at the end of the two-phase load |
void |
addNullProperty(EntityKey ownerKey,
String propertyName)
Record the fact that the association belonging to the keyed entity is null. |
void |
addProxy(EntityKey key,
Object proxy)
Add a proxy to the session cache |
void |
addUninitializedCollection(CollectionPersister persister,
PersistentCollection collection,
Serializable id)
add a collection we just loaded up (still needs initializing) |
void |
addUninitializedDetachedCollection(CollectionPersister persister,
PersistentCollection collection)
add a detached uninitialized collection |
void |
addUnownedCollection(CollectionKey key,
PersistentCollection collection)
Add a collection which has no owner loaded |
void |
afterLoad()
Call this after finishing a two-phase load |
void |
afterTransactionCompletion()
Called after transactions end |
void |
beforeLoad()
Call this before begining a two-phase load |
void |
checkUniqueness(EntityKey key,
Object object)
Attempts to check whether the given key represents an entity already loaded within the current session. |
void |
clear()
Clear the state of the persistence context |
boolean |
containsCollection(PersistentCollection collection)
Is the given collection associated with this persistence context? |
boolean |
containsEntity(EntityKey key)
Is there an entity with the given key in the persistence context |
boolean |
containsProxy(Object entity)
Is the given proxy associated with this persistence context? |
int |
decrementCascadeLevel()
Called after cascading |
static StatefulPersistenceContext |
deserialize(ObjectInputStream ois,
SessionImplementor session)
|
BatchFetchQueue |
getBatchFetchQueue()
Get the BatchFetchQueue, instantiating one if necessary. |
Object[] |
getCachedDatabaseSnapshot(EntityKey key)
Retrieve the cached database snapshot for the requested entity key. |
int |
getCascadeLevel()
Do we already know that the entity does not exist in the database? |
PersistentCollection |
getCollection(CollectionKey collectionKey)
Get the collection instance associated with the CollectionKey |
Map |
getCollectionEntries()
Get the mapping from collection instance to collection entry |
CollectionEntry |
getCollectionEntry(PersistentCollection coll)
Get the collection entry for a persistent collection |
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. |
PersistentCollection |
getCollectionHolder(Object array)
Get the PersistentCollection object for an array |
Object |
getCollectionOwner(Serializable key,
CollectionPersister collectionPersister)
Get the entity that owns this persistent collection |
Map |
getCollectionsByKey()
Get the mapping from collection key to collection instance |
Object[] |
getDatabaseSnapshot(Serializable id,
EntityPersister persister)
Get the current state of the entity as known to the underlying database, or null if there is no corresponding row |
Map |
getEntitiesByKey()
Get the mapping from key value to entity instance |
Object |
getEntity(EntityKey key)
Get the entity instance associated with the given EntityKey |
Object |
getEntity(EntityUniqueKey euk)
Get an entity cached by unique key |
Map |
getEntityEntries()
Get the mapping from entity instance to entity entry |
EntityEntry |
getEntry(Object entity)
Retreive the EntityEntry representation of the given entity. |
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 |
LoadContexts |
getLoadContexts()
Retrieve this persistence context's managed load context. |
Serializable |
getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)
Get the ID for the entity that owned this persistent collection when it was loaded |
Object |
getLoadedCollectionOwnerOrNull(PersistentCollection collection)
Get the entity that owned this persistent collection when it was loaded |
Object[] |
getNaturalIdSnapshot(Serializable id,
EntityPersister persister)
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. |
HashSet |
getNullifiableEntityKeys()
Retrieve the set of EntityKeys representing nullifiable references |
Serializable |
getOwnerId(String entity,
String property,
Object childEntity,
Map mergeMap)
Search the persistence context for an owner for the child object, given a collection role. |
Object |
getProxy(EntityKey key)
Get an existing proxy by key |
SessionImplementor |
getSession()
Get the session to which this persistence context is bound. |
Serializable |
getSnapshot(PersistentCollection coll)
Get the snapshot of the pre-flush collection state |
boolean |
hasNonReadOnlyEntities()
|
int |
incrementCascadeLevel()
Called before cascading |
void |
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) |
boolean |
isEntryFor(Object entity)
Is there an EntityEntry for this instance? |
boolean |
isFlushing()
Is a flush cycle currently in process? |
boolean |
isPropertyNull(EntityKey ownerKey,
String propertyName)
Is the association property belonging to the keyed entity null? |
boolean |
isStateless()
|
Object |
narrowProxy(Object proxy,
EntityPersister persister,
EntityKey key,
Object object)
If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one. |
Object |
proxyFor(EntityPersister persister,
EntityKey key,
Object impl)
Return the existing proxy associated with the given EntityKey, or the third argument (the entity associated with the key) if no proxy exists. |
Object |
proxyFor(Object impl)
Return the existing proxy associated with the given EntityKey, or the argument (the entity associated with the key) if no proxy exists. |
boolean |
reassociateIfUninitializedProxy(Object value)
Takes the given object and, if it represents a proxy, reassociates it with this event source. |
void |
reassociateProxy(Object value,
Serializable id)
If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy |
PersistentCollection |
removeCollectionHolder(Object array)
Remove the mapping of collection to holder during eviction of the owning entity |
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 |
EntityEntry |
removeEntry(Object entity)
Remove an entity entry from the session cache |
Object |
removeProxy(EntityKey key)
Remove a proxy from the session cache. |
void |
replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey,
Serializable generatedId)
|
void |
serialize(ObjectOutputStream oos)
Used by the owning session to explicitly control serialization of the persistence context. |
void |
setEntryStatus(EntityEntry entry,
Status status)
Set the status of an entry |
void |
setFlushing(boolean flushing)
Called before and after the flushcycle |
void |
setReadOnly(Object entity,
boolean readOnly)
Set the object to read only and discard it's snapshot |
String |
toString()
Returns a string representation of the object. |
Object |
unproxy(Object maybeProxy)
Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized. |
Object |
unproxyAndReassociate(Object maybeProxy)
Possibly unproxy the given reference and reassociate it with the current session. |
PersistentCollection |
useUnownedCollection(CollectionKey key)
Get and remove a collection whose owner is not yet loaded, when its owner is being loaded |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Object NO_ROW
| Constructor Detail |
|---|
public StatefulPersistenceContext(SessionImplementor session)
session - The session "owning" this context.| Method Detail |
|---|
public boolean isStateless()
isStateless in interface PersistenceContextpublic SessionImplementor getSession()
PersistenceContext
getSession in interface PersistenceContextpublic LoadContexts getLoadContexts()
PersistenceContext
getLoadContexts in interface PersistenceContext
public void addUnownedCollection(CollectionKey key,
PersistentCollection collection)
PersistenceContext
addUnownedCollection in interface PersistenceContextpublic PersistentCollection useUnownedCollection(CollectionKey key)
PersistenceContext
useUnownedCollection in interface PersistenceContextpublic BatchFetchQueue getBatchFetchQueue()
getBatchFetchQueue in interface PersistenceContextpublic void clear()
PersistenceContext
clear in interface PersistenceContextpublic boolean hasNonReadOnlyEntities()
hasNonReadOnlyEntities in interface PersistenceContext
public void setEntryStatus(EntityEntry entry,
Status status)
PersistenceContext
setEntryStatus in interface PersistenceContextpublic void afterTransactionCompletion()
PersistenceContext
afterTransactionCompletion in interface PersistenceContext
public Object[] getDatabaseSnapshot(Serializable id,
EntityPersister persister)
throws HibernateException
getDatabaseSnapshot in interface PersistenceContextHibernateException
public Object[] getNaturalIdSnapshot(Serializable id,
EntityPersister persister)
throws HibernateException
PersistenceContext
getNaturalIdSnapshot in interface PersistenceContextHibernateExceptionpublic Object[] getCachedDatabaseSnapshot(EntityKey key)
getDatabaseSnapshot(java.io.Serializable, org.hibernate.persister.entity.EntityPersister) is two important respects:NO_ROW here is interpretet as an exception
getCachedDatabaseSnapshot in interface PersistenceContextkey - The entity key for which to retrieve the cached snapshot
IllegalStateException - if the cached snapshot was == NO_ROW.
public void addEntity(EntityKey key,
Object entity)
PersistenceContext
addEntity in interface PersistenceContextpublic Object getEntity(EntityKey key)
getEntity in interface PersistenceContextpublic boolean containsEntity(EntityKey key)
PersistenceContext
containsEntity in interface PersistenceContextpublic Object removeEntity(EntityKey key)
removeEntity in interface PersistenceContextpublic Object getEntity(EntityUniqueKey euk)
getEntity in interface PersistenceContext
public void addEntity(EntityUniqueKey euk,
Object entity)
addEntity in interface PersistenceContextpublic EntityEntry getEntry(Object entity)
getEntry in interface PersistenceContextentity - The entity for which to locate the EntityEntry.
public EntityEntry removeEntry(Object entity)
removeEntry in interface PersistenceContextpublic boolean isEntryFor(Object entity)
isEntryFor in interface PersistenceContextpublic CollectionEntry getCollectionEntry(PersistentCollection coll)
getCollectionEntry 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)
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)
addEntry in interface PersistenceContextpublic boolean containsCollection(PersistentCollection collection)
PersistenceContext
containsCollection in interface PersistenceContextpublic boolean containsProxy(Object entity)
PersistenceContext
containsProxy in interface PersistenceContext
public boolean reassociateIfUninitializedProxy(Object value)
throws MappingException
reassociateIfUninitializedProxy in interface PersistenceContextvalue - The possible proxy to be reassociated.
MappingException
public void reassociateProxy(Object value,
Serializable id)
throws MappingException
reassociateProxy in interface PersistenceContextMappingException
public Object unproxy(Object maybeProxy)
throws HibernateException
unproxy in interface PersistenceContextHibernateException
public Object unproxyAndReassociate(Object maybeProxy)
throws HibernateException
unproxyAndReassociate in interface PersistenceContextmaybeProxy - The reference to be unproxied if it currently represents a proxy.
HibernateException
public void checkUniqueness(EntityKey key,
Object object)
throws HibernateException
checkUniqueness in interface PersistenceContextobject - The entity reference against which to perform the uniqueness check.
HibernateException
public Object narrowProxy(Object proxy,
EntityPersister persister,
EntityKey key,
Object object)
throws HibernateException
narrowProxy in interface PersistenceContextproxy - 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.
HibernateException
public Object proxyFor(EntityPersister persister,
EntityKey key,
Object impl)
throws HibernateException
proxyFor in interface PersistenceContextHibernateException
public Object proxyFor(Object impl)
throws HibernateException
proxyFor in interface PersistenceContextHibernateException
public Object getCollectionOwner(Serializable key,
CollectionPersister collectionPersister)
throws MappingException
getCollectionOwner in interface PersistenceContextMappingExceptionpublic Object getLoadedCollectionOwnerOrNull(PersistentCollection collection)
getLoadedCollectionOwnerOrNull in interface PersistenceContextcollection - The persistent collection
public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)
getLoadedCollectionOwnerIdOrNull in interface PersistenceContextcollection - The persistent collection
public void addUninitializedCollection(CollectionPersister persister,
PersistentCollection collection,
Serializable id)
addUninitializedCollection in interface PersistenceContext
public void addUninitializedDetachedCollection(CollectionPersister persister,
PersistentCollection collection)
addUninitializedDetachedCollection in interface PersistenceContext
public void addNewCollection(CollectionPersister persister,
PersistentCollection collection)
throws HibernateException
addNewCollection in interface PersistenceContextcollection - The collection to be associated with the persistence context
HibernateException
public void addInitializedDetachedCollection(CollectionPersister collectionPersister,
PersistentCollection collection)
throws HibernateException
addInitializedDetachedCollection in interface PersistenceContextHibernateException
public CollectionEntry addInitializedCollection(CollectionPersister persister,
PersistentCollection collection,
Serializable id)
throws HibernateException
addInitializedCollection in interface PersistenceContextHibernateExceptionpublic PersistentCollection getCollection(CollectionKey collectionKey)
getCollection in interface PersistenceContextpublic void addNonLazyCollection(PersistentCollection collection)
addNonLazyCollection in interface PersistenceContext
public void initializeNonLazyCollections()
throws HibernateException
initializeNonLazyCollections in interface PersistenceContextHibernateExceptionpublic PersistentCollection getCollectionHolder(Object array)
getCollectionHolder in interface PersistenceContextpublic void addCollectionHolder(PersistentCollection holder)
addCollectionHolder in interface PersistenceContextpublic PersistentCollection removeCollectionHolder(Object array)
PersistenceContext
removeCollectionHolder in interface PersistenceContextpublic Serializable getSnapshot(PersistentCollection coll)
getSnapshot in interface PersistenceContextpublic CollectionEntry getCollectionEntryOrNull(Object collection)
getCollectionEntryOrNull in interface PersistenceContextpublic Object getProxy(EntityKey key)
getProxy in interface PersistenceContext
public void addProxy(EntityKey key,
Object proxy)
addProxy in interface PersistenceContextpublic Object removeProxy(EntityKey key)
removeProxy in interface PersistenceContextkey - The key of the entity proxy to be removed
public HashSet getNullifiableEntityKeys()
getNullifiableEntityKeys in interface PersistenceContextpublic Map getEntitiesByKey()
PersistenceContext
getEntitiesByKey in interface PersistenceContextpublic Map getEntityEntries()
PersistenceContext
getEntityEntries in interface PersistenceContextpublic Map getCollectionEntries()
PersistenceContext
getCollectionEntries in interface PersistenceContextpublic Map getCollectionsByKey()
PersistenceContext
getCollectionsByKey in interface PersistenceContextpublic int getCascadeLevel()
getCascadeLevel in interface PersistenceContextpublic int incrementCascadeLevel()
PersistenceContext
incrementCascadeLevel in interface PersistenceContextpublic int decrementCascadeLevel()
PersistenceContext
decrementCascadeLevel in interface PersistenceContextpublic boolean isFlushing()
PersistenceContext
isFlushing in interface PersistenceContextpublic void setFlushing(boolean flushing)
PersistenceContext
setFlushing in interface PersistenceContextpublic void beforeLoad()
beforeLoad in interface PersistenceContextpublic void afterLoad()
afterLoad in interface PersistenceContextpublic String toString()
toString in interface PersistenceContexttoString in class Object
public Serializable getOwnerId(String entity,
String property,
Object childEntity,
Map mergeMap)
getOwnerId in interface PersistenceContext
public Object getIndexInOwner(String entity,
String property,
Object childEntity,
Map mergeMap)
getIndexInOwner in interface PersistenceContext
public void addNullProperty(EntityKey ownerKey,
String propertyName)
addNullProperty in interface PersistenceContext
public boolean isPropertyNull(EntityKey ownerKey,
String propertyName)
isPropertyNull in interface PersistenceContext
public void setReadOnly(Object entity,
boolean readOnly)
PersistenceContext
setReadOnly in interface PersistenceContext
public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey,
Serializable generatedId)
replaceDelayedEntityIdentityInsertKeys in interface PersistenceContext
public void serialize(ObjectOutputStream oos)
throws IOException
oos - The stream to which the persistence context should get written
IOException - serialization errors.
public static StatefulPersistenceContext deserialize(ObjectInputStream ois,
SessionImplementor session)
throws IOException,
ClassNotFoundException
IOException
ClassNotFoundException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||