Home » Hibernate-3.3.2.GA » org.hibernate » engine » [javadoc | source]
public class: StatefulPersistenceContext [javadoc | source]

All Implemented Interfaces:

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
public static final  Object NO_ROW     
 public StatefulPersistenceContext(SessionImplementor session) 
    Constructs a PersistentContext, bound to the given session.
    session - The session "owning" this context.
Method from org.hibernate.engine.StatefulPersistenceContext Summary:
addCollectionHolder,   addEntity,   addEntity,   addEntity,   addEntry,   addInitializedCollection,   addInitializedDetachedCollection,   addNewCollection,   addNonLazyCollection,   addNullProperty,   addProxy,   addUninitializedCollection,   addUninitializedDetachedCollection,   addUnownedCollection,   afterLoad,   afterTransactionCompletion,   beforeLoad,   checkUniqueness,   clear,   containsCollection,   containsEntity,   containsProxy,   decrementCascadeLevel,   deserialize,   getBatchFetchQueue,   getCachedDatabaseSnapshot,   getCascadeLevel,   getCollection,   getCollectionEntries,   getCollectionEntry,   getCollectionEntryOrNull,   getCollectionHolder,   getCollectionOwner,   getCollectionsByKey,   getDatabaseSnapshot,   getEntitiesByKey,   getEntity,   getEntity,   getEntityEntries,   getEntry,   getIndexInOwner,   getLoadContexts,   getLoadedCollectionOwnerIdOrNull,   getLoadedCollectionOwnerOrNull,   getNaturalIdSnapshot,   getNullifiableEntityKeys,   getOwnerId,   getProxy,   getSession,   getSnapshot,   hasNonReadOnlyEntities,   incrementCascadeLevel,   initializeNonLazyCollections,   isEntryFor,   isFlushing,   isPropertyNull,   isStateless,   narrowProxy,   proxyFor,   proxyFor,   reassociateIfUninitializedProxy,   reassociateProxy,   removeCollectionHolder,   removeEntity,   removeEntry,   removeProxy,   replaceDelayedEntityIdentityInsertKeys,   serialize,   setEntryStatus,   setFlushing,   setReadOnly,   toString,   unproxy,   unproxyAndReassociate,   useUnownedCollection
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.hibernate.engine.StatefulPersistenceContext Detail:
 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().
 public  void addEntity(EntityKey key,
    Object entity) 
 public  void addEntity(EntityUniqueKey euk,
    Object entity) 
    Add an entity to the cache by unique key
 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.
 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.
 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)
 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)
 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)
 public  void addNonLazyCollection(PersistentCollection collection) 
    Register a collection for non-lazy loading at the end of the two-phase load
 public  void addNullProperty(EntityKey ownerKey,
    String propertyName) 
    Record the fact that the association belonging to the keyed entity is null.
 public  void addProxy(EntityKey key,
    Object proxy) 
    Add a proxy to the session cache
 public  void addUninitializedCollection(CollectionPersister persister,
    PersistentCollection collection,
    Serializable id) 
    add a collection we just loaded up (still needs initializing)
 public  void addUninitializedDetachedCollection(CollectionPersister persister,
    PersistentCollection collection) 
    add a detached uninitialized collection
 public  void addUnownedCollection(CollectionKey key,
    PersistentCollection collection) 
 public  void afterLoad() 
    Call this after finishing a two-phase load
 public  void afterTransactionCompletion() 
 public  void beforeLoad() 
    Call this before begining a two-phase load
 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.
 public  void clear() 
 public boolean containsCollection(PersistentCollection collection) 
 public boolean containsEntity(EntityKey key) 
 public boolean containsProxy(Object entity) 
 public int decrementCascadeLevel() 
 public static StatefulPersistenceContext deserialize(ObjectInputStream ois,
    SessionImplementor session) throws IOException, ClassNotFoundException 
 public BatchFetchQueue getBatchFetchQueue() 
    Get the BatchFetchQueue, instantiating one if necessary.
 public Object[] getCachedDatabaseSnapshot(EntityKey key) 
    Retrieve the cached database snapshot for the requested entity key.

    This differs from #getDatabaseSnapshot is two important respects:

    1. no snapshot is obtained from the database if not already cached
    2. an entry of #NO_ROW here is interpretet as an exception
 public int getCascadeLevel() 
    Do we already know that the entity does not exist in the database?
 public PersistentCollection getCollection(CollectionKey collectionKey) 
    Get the collection instance associated with the CollectionKey
 public Map getCollectionEntries() 
 public CollectionEntry getCollectionEntry(PersistentCollection coll) 
    Get the collection entry for a persistent collection
 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.
 public PersistentCollection getCollectionHolder(Object array) 
    Get the PersistentCollection object for an array
 public Object getCollectionOwner(Serializable key,
    CollectionPersister collectionPersister) throws MappingException 
    Get the entity that owns this persistent collection
 public Map getCollectionsByKey() 
 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
 public Map getEntitiesByKey() 
 public Object getEntity(EntityKey key) 
    Get the entity instance associated with the given EntityKey
 public Object getEntity(EntityUniqueKey euk) 
    Get an entity cached by unique key
 public Map getEntityEntries() 
 public EntityEntry getEntry(Object entity) 
    Retreive the EntityEntry representation of 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
 public LoadContexts getLoadContexts() 
 public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection) 
    Get the ID for the entity that owned this persistent collection when it was loaded
 public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) 
    Get the entity that owned this persistent collection when it was loaded
 public Object[] getNaturalIdSnapshot(Serializable id,
    EntityPersister persister) throws HibernateException 
 public HashSet getNullifiableEntityKeys() 
    Retrieve the set of EntityKeys representing nullifiable references
 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.

 public Object getProxy(EntityKey key) 
    Get an existing proxy by key
 public SessionImplementor getSession() 
 public Serializable getSnapshot(PersistentCollection coll) 
    Get the snapshot of the pre-flush collection state
 public boolean hasNonReadOnlyEntities() 
 public int incrementCascadeLevel() 
 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)
 public boolean isEntryFor(Object entity) 
    Is there an EntityEntry for this instance?
 public boolean isFlushing() 
 public boolean isPropertyNull(EntityKey ownerKey,
    String propertyName) 
    Is the association property belonging to the keyed entity null?
 public boolean isStateless() 
 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.
 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)
 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.
 public boolean reassociateIfUninitializedProxy(Object value) throws MappingException 
    Takes the given object and, if it represents a proxy, reassociates it with this event source.
 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
 public PersistentCollection removeCollectionHolder(Object array) 
 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
 public EntityEntry removeEntry(Object entity) 
    Remove an entity entry from the session cache
 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.

 public  void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey,
    Serializable generatedId) 
 public  void serialize(ObjectOutputStream oos) throws IOException 
    Used by the owning session to explicitly control serialization of the persistence context.
 public  void setEntryStatus(EntityEntry entry,
    Status status) 
 public  void setFlushing(boolean flushing) 
 public  void setReadOnly(Object entity,
    boolean readOnly) 
 public String toString() 
    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.
 public Object unproxyAndReassociate(Object maybeProxy) throws HibernateException 
    Possibly unproxy the given reference and reassociate it with the current session.
 public PersistentCollection useUnownedCollection(CollectionKey key)