Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.hibernate.collection
Class AbstractPersistentCollection  view AbstractPersistentCollection download AbstractPersistentCollection.java

java.lang.Object
  extended byorg.hibernate.collection.AbstractPersistentCollection
All Implemented Interfaces:
PersistentCollection, java.io.Serializable
Direct Known Subclasses:
PersistentArrayHolder, PersistentBag, PersistentElementHolder, PersistentIdentifierBag, PersistentIndexedElementHolder, PersistentList, PersistentMap, PersistentSet

public abstract class AbstractPersistentCollection
extends java.lang.Object
implements java.io.Serializable, PersistentCollection

Base class implementing PersistentCollection


Nested Class Summary
protected static interface AbstractPersistentCollection.DelayedOperation
           
(package private)  class AbstractPersistentCollection.IteratorProxy
           
(package private)  class AbstractPersistentCollection.ListIteratorProxy
           
(package private)  class AbstractPersistentCollection.ListProxy
           
(package private)  class AbstractPersistentCollection.SetProxy
           
 
Field Summary
private  int cachedSize
           
private  boolean directlyAccessible
           
private  boolean dirty
           
private  boolean initialized
           
private  boolean initializing
           
private  java.io.Serializable key
           
private  java.util.List operationQueue
           
private  java.lang.Object owner
           
private  java.lang.String role
           
private  org.hibernate.engine.SessionImplementor session
           
private  java.io.Serializable storedSnapshot
           
protected static java.lang.Object UNKNOWN
           
 
Constructor Summary
  AbstractPersistentCollection()
          Not called by Hibernate, but used by non-JDK serialization, eg.
protected AbstractPersistentCollection(org.hibernate.engine.SessionImplementor session)
           
 
Method Summary
 boolean afterInitialize()
          Called after initializing from cache
 void afterRowInsert(org.hibernate.persister.collection.CollectionPersister persister, java.lang.Object entry, int i)
          Called after inserting a row, to fetch the natively generated id
 void beginRead()
          Called just before reading any rows from the JDBC result set
 void clearDirty()
          Clear the dirty flag, after flushing changes to the database.
 void dirty()
          Mark the collection as dirty
abstract  boolean empty()
          Is the initialized collection empty?
 boolean endRead()
          Called after reading all rows from the JDBC result set
 void forceInitialization()
          To be called internally by the session, forcing immediate initialization.
protected  int getCachedSize()
           
 java.lang.Object getIdentifier(java.lang.Object entry, int i)
          Get the index of the given collection entry
 java.io.Serializable getKey()
          Get the current collection key value
protected static java.util.Collection getOrphans(java.util.Collection oldElements, java.util.Collection currentElements, java.lang.String entityName, org.hibernate.engine.SessionImplementor session)
          Given a collection of entity instances that used to belong to the collection, and a collection of instances that currently belong, return a collection of orphans
abstract  java.util.Collection getOrphans(java.io.Serializable snapshot, java.lang.String entityName)
          get all "orphaned" elements
 java.lang.Object getOwner()
          Get the owning entity.
 java.util.Collection getQueuedOrphans(java.lang.String entityName)
          Iterate the "queued" additions
 java.lang.String getRole()
          Get the current role name
protected  org.hibernate.engine.SessionImplementor getSession()
          Get the current session
protected  java.io.Serializable getSnapshot()
          Get the current snapshot from the session
 java.io.Serializable getStoredSnapshot()
          Get the snapshot cached by the collection instance
 java.lang.Object getValue()
          return the user-visible collection (or array) instance
 boolean hasQueuedOperations()
          Does this instance have any "queued" additions?
(package private) static void identityRemove(java.util.Collection list, java.lang.Object object, java.lang.String entityName, org.hibernate.engine.SessionImplementor session)
           
protected  void initialize(boolean writing)
          Initialize the collection, if possible, wrapping any exceptions in a runtime exception
protected  boolean isClearQueueEnabled()
          Is this collection in a state that would allow us to "queue" clear? This is a special case, because of orphan delete.
private  boolean isConnectedToSession()
          Is the collection currently connected to an open session?
 boolean isDirectlyAccessible()
          Could the application possibly have a direct reference to the underlying collection implementation?
 boolean isDirty()
          Is the collection dirty? Note that this is only reliable during the flush cycle, after the collection elements are dirty checked against the snapshot.
private  boolean isInverseCollection()
          Is this the "inverse" end of a bidirectional association?
private  boolean isInverseCollectionNoOrphanDelete()
          Is this the "inverse" end of a bidirectional association with no orphan delete enabled?
private  boolean isInverseOneToManyOrNoOrphanDelete()
          Is this the "inverse" end of a bidirectional one-to-many, or of a collection with no orphan delete?
protected  boolean isOperationQueueEnabled()
          Is this collection in a state that would allow us to "queue" operations?
protected  boolean isPutQueueEnabled()
          Is this collection in a state that would allow us to "queue" puts? This is a special case, because of orphan delete.
 boolean isRowUpdatePossible()
           
 boolean isUnreferenced()
          Is the collection unreferenced?
 boolean needsRecreate(org.hibernate.persister.collection.CollectionPersister persister)
          Do we need to completely recreate this collection when it changes?
protected  void performQueuedOperations()
          After reading all existing elements from the database, add the queued elements to the underlying collection.
 void postAction()
          After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.
 void preInsert(org.hibernate.persister.collection.CollectionPersister persister)
          Called before inserting rows, to ensure that any surrogate keys are fully generated
 java.util.Iterator queuedAdditionIterator()
          Iterate the "queued" additions
protected  void queueOperation(java.lang.Object element)
          Queue an addition
protected  void read()
          Called by any read-only method of the collection interface
protected  java.lang.Object readElementByIndex(java.lang.Object index)
           
protected  java.lang.Boolean readElementExistence(java.lang.Object element)
           
protected  java.lang.Boolean readIndexExistence(java.lang.Object index)
           
protected  boolean readSize()
          Called by the size() method
 boolean setCurrentSession(org.hibernate.engine.SessionImplementor session)
          Associate the collection with the given session.
protected  void setDirectlyAccessible(boolean directlyAccessible)
           
protected  void setInitialized()
           
 void setOwner(java.lang.Object owner)
          Set the reference to the owning entity
 void setSnapshot(java.io.Serializable key, java.lang.String role, java.io.Serializable snapshot)
          After flushing, re-init snapshot state.
private  void throwLazyInitializationException(java.lang.String message)
           
private  void throwLazyInitializationExceptionIfNotConnected()
           
 boolean unsetSession(org.hibernate.engine.SessionImplementor currentSession)
          Disassociate this collection from the given session.
 boolean wasInitialized()
          Is this instance initialized?
protected  void write()
          Called by any writer method of the collection interface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.collection.PersistentCollection
beforeInitialize, disassemble, entries, entryExists, equalsSnapshot, getDeletes, getElement, getIndex, getSnapshot, getSnapshotElement, initializeFromCache, isSnapshotEmpty, isWrapper, needsInserting, needsUpdating, readFrom
 

Field Detail

session

private transient org.hibernate.engine.SessionImplementor session

initialized

private boolean initialized

operationQueue

private transient java.util.List operationQueue

directlyAccessible

private transient boolean directlyAccessible

initializing

private transient boolean initializing

owner

private java.lang.Object owner

cachedSize

private int cachedSize

role

private java.lang.String role

key

private java.io.Serializable key

dirty

private boolean dirty

storedSnapshot

private java.io.Serializable storedSnapshot

UNKNOWN

protected static final java.lang.Object UNKNOWN
Constructor Detail

AbstractPersistentCollection

public AbstractPersistentCollection()
Not called by Hibernate, but used by non-JDK serialization, eg. SOAP libraries.


AbstractPersistentCollection

protected AbstractPersistentCollection(org.hibernate.engine.SessionImplementor session)
Method Detail

getRole

public final java.lang.String getRole()
Description copied from interface: PersistentCollection
Get the current role name

Specified by:
getRole in interface PersistentCollection

getKey

public final java.io.Serializable getKey()
Description copied from interface: PersistentCollection
Get the current collection key value

Specified by:
getKey in interface PersistentCollection

isUnreferenced

public final boolean isUnreferenced()
Description copied from interface: PersistentCollection
Is the collection unreferenced?

Specified by:
isUnreferenced in interface PersistentCollection

isDirty

public final boolean isDirty()
Description copied from interface: PersistentCollection
Is the collection dirty? Note that this is only reliable during the flush cycle, after the collection elements are dirty checked against the snapshot.

Specified by:
isDirty in interface PersistentCollection

clearDirty

public final void clearDirty()
Description copied from interface: PersistentCollection
Clear the dirty flag, after flushing changes to the database.

Specified by:
clearDirty in interface PersistentCollection

dirty

public final void dirty()
Description copied from interface: PersistentCollection
Mark the collection as dirty

Specified by:
dirty in interface PersistentCollection

getStoredSnapshot

public final java.io.Serializable getStoredSnapshot()
Description copied from interface: PersistentCollection
Get the snapshot cached by the collection instance

Specified by:
getStoredSnapshot in interface PersistentCollection

empty

public abstract boolean empty()
Is the initialized collection empty?

Specified by:
empty in interface PersistentCollection

read

protected final void read()
Called by any read-only method of the collection interface


readSize

protected boolean readSize()
Called by the size() method


readIndexExistence

protected java.lang.Boolean readIndexExistence(java.lang.Object index)

readElementExistence

protected java.lang.Boolean readElementExistence(java.lang.Object element)

readElementByIndex

protected java.lang.Object readElementByIndex(java.lang.Object index)

getCachedSize

protected int getCachedSize()

isConnectedToSession

private final boolean isConnectedToSession()
Is the collection currently connected to an open session?


write

protected final void write()
Called by any writer method of the collection interface


isOperationQueueEnabled

protected boolean isOperationQueueEnabled()
Is this collection in a state that would allow us to "queue" operations?


isPutQueueEnabled

protected boolean isPutQueueEnabled()
Is this collection in a state that would allow us to "queue" puts? This is a special case, because of orphan delete.


isClearQueueEnabled

protected boolean isClearQueueEnabled()
Is this collection in a state that would allow us to "queue" clear? This is a special case, because of orphan delete.


isInverseCollection

private boolean isInverseCollection()
Is this the "inverse" end of a bidirectional association?


isInverseCollectionNoOrphanDelete

private boolean isInverseCollectionNoOrphanDelete()
Is this the "inverse" end of a bidirectional association with no orphan delete enabled?


isInverseOneToManyOrNoOrphanDelete

private boolean isInverseOneToManyOrNoOrphanDelete()
Is this the "inverse" end of a bidirectional one-to-many, or of a collection with no orphan delete?


queueOperation

protected final void queueOperation(java.lang.Object element)
Queue an addition


performQueuedOperations

protected final void performQueuedOperations()
After reading all existing elements from the database, add the queued elements to the underlying collection.


setSnapshot

public void setSnapshot(java.io.Serializable key,
                        java.lang.String role,
                        java.io.Serializable snapshot)
After flushing, re-init snapshot state.

Specified by:
setSnapshot in interface PersistentCollection

postAction

public void postAction()
After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.

Specified by:
postAction in interface PersistentCollection

getValue

public java.lang.Object getValue()
return the user-visible collection (or array) instance

Specified by:
getValue in interface PersistentCollection

beginRead

public void beginRead()
Called just before reading any rows from the JDBC result set

Specified by:
beginRead in interface PersistentCollection

endRead

public boolean endRead()
Called after reading all rows from the JDBC result set

Specified by:
endRead in interface PersistentCollection

afterInitialize

public boolean afterInitialize()
Description copied from interface: PersistentCollection
Called after initializing from cache

Specified by:
afterInitialize in interface PersistentCollection

initialize

protected final void initialize(boolean writing)
Initialize the collection, if possible, wrapping any exceptions in a runtime exception


throwLazyInitializationExceptionIfNotConnected

private void throwLazyInitializationExceptionIfNotConnected()

throwLazyInitializationException

private void throwLazyInitializationException(java.lang.String message)

setInitialized

protected final void setInitialized()

setDirectlyAccessible

protected final void setDirectlyAccessible(boolean directlyAccessible)

isDirectlyAccessible

public boolean isDirectlyAccessible()
Could the application possibly have a direct reference to the underlying collection implementation?

Specified by:
isDirectlyAccessible in interface PersistentCollection

unsetSession

public final boolean unsetSession(org.hibernate.engine.SessionImplementor currentSession)
Disassociate this collection from the given session.

Specified by:
unsetSession in interface PersistentCollection

setCurrentSession

public final boolean setCurrentSession(org.hibernate.engine.SessionImplementor session)
                                throws org.hibernate.HibernateException
Associate the collection with the given session.

Specified by:
setCurrentSession in interface PersistentCollection

needsRecreate

public boolean needsRecreate(org.hibernate.persister.collection.CollectionPersister persister)
Do we need to completely recreate this collection when it changes?

Specified by:
needsRecreate in interface PersistentCollection

forceInitialization

public final void forceInitialization()
                               throws org.hibernate.HibernateException
To be called internally by the session, forcing immediate initialization.

Specified by:
forceInitialization in interface PersistentCollection

getSnapshot

protected final java.io.Serializable getSnapshot()
Get the current snapshot from the session


wasInitialized

public final boolean wasInitialized()
Is this instance initialized?

Specified by:
wasInitialized in interface PersistentCollection

isRowUpdatePossible

public boolean isRowUpdatePossible()
Specified by:
isRowUpdatePossible in interface PersistentCollection

hasQueuedOperations

public final boolean hasQueuedOperations()
Does this instance have any "queued" additions?

Specified by:
hasQueuedOperations in interface PersistentCollection

queuedAdditionIterator

public final java.util.Iterator queuedAdditionIterator()
Iterate the "queued" additions

Specified by:
queuedAdditionIterator in interface PersistentCollection

getQueuedOrphans

public final java.util.Collection getQueuedOrphans(java.lang.String entityName)
Iterate the "queued" additions

Specified by:
getQueuedOrphans in interface PersistentCollection

preInsert

public void preInsert(org.hibernate.persister.collection.CollectionPersister persister)
               throws org.hibernate.HibernateException
Called before inserting rows, to ensure that any surrogate keys are fully generated

Specified by:
preInsert in interface PersistentCollection

afterRowInsert

public void afterRowInsert(org.hibernate.persister.collection.CollectionPersister persister,
                           java.lang.Object entry,
                           int i)
                    throws org.hibernate.HibernateException
Called after inserting a row, to fetch the natively generated id

Specified by:
afterRowInsert in interface PersistentCollection

getOrphans

public abstract java.util.Collection getOrphans(java.io.Serializable snapshot,
                                                java.lang.String entityName)
                                         throws org.hibernate.HibernateException
get all "orphaned" elements

Specified by:
getOrphans in interface PersistentCollection

getSession

protected final org.hibernate.engine.SessionImplementor getSession()
Get the current session


getOrphans

protected static java.util.Collection getOrphans(java.util.Collection oldElements,
                                                 java.util.Collection currentElements,
                                                 java.lang.String entityName,
                                                 org.hibernate.engine.SessionImplementor session)
                                          throws org.hibernate.HibernateException
Given a collection of entity instances that used to belong to the collection, and a collection of instances that currently belong, return a collection of orphans


identityRemove

static void identityRemove(java.util.Collection list,
                           java.lang.Object object,
                           java.lang.String entityName,
                           org.hibernate.engine.SessionImplementor session)
                    throws org.hibernate.HibernateException

getIdentifier

public java.lang.Object getIdentifier(java.lang.Object entry,
                                      int i)
Description copied from interface: PersistentCollection
Get the index of the given collection entry

Specified by:
getIdentifier in interface PersistentCollection

getOwner

public java.lang.Object getOwner()
Description copied from interface: PersistentCollection
Get the owning entity. Note that the owner is only set during the flush cycle, and when a new collection wrapper is created while loading an entity.

Specified by:
getOwner in interface PersistentCollection

setOwner

public void setOwner(java.lang.Object owner)
Description copied from interface: PersistentCollection
Set the reference to the owning entity

Specified by:
setOwner in interface PersistentCollection