org.hibernate.collection
Class AbstractPersistentCollection

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

public abstract class AbstractPersistentCollection
extends Object
implements Serializable, PersistentCollection

Base class implementing PersistentCollection

Author:
Gavin King
See Also:
PersistentCollection, Serialized Form

Constructor Summary
  AbstractPersistentCollection()
          Not called by Hibernate, but used by non-JDK serialization, eg.
protected AbstractPersistentCollection(SessionImplementor session)
           
 
Method Summary
 boolean afterInitialize()
          Called after initializing from cache
 void afterRowInsert(CollectionPersister persister, 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 delayedAddAll(Collection coll)
          After reading all existing elements from the database, add the queued elements to the underlying collection.
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.
 CollectionSnapshot getCollectionSnapshot()
          Returns the collectionSnapshot.
 Object getIdentifier(Object entry, int i)
          Get the index of the given collection entry
protected static Collection getOrphans(Collection oldElements, Collection currentElements, String entityName, SessionImplementor session)
           
abstract  Collection getOrphans(Serializable snapshot, String entityName)
          get all "orphaned" elements
 Object getOwner()
           
protected  SessionImplementor getSession()
          Get the current session
protected  Serializable getSnapshot()
          Get the current snapshot from the session
 Serializable getSnapshot(CollectionPersister persister)
          Return a new snapshot of the current state of the collection, or null if no persister is passed
 Object getValue()
          return the user-visible collection (or array) instance
 boolean hasQueuedAdditions()
          Does this instance have any "queued" additions?
protected  void initialize(boolean writing)
          Initialize the collection, if possible, wrapping any exceptions in a runtime exception
 boolean isDirectlyAccessible()
          Could the application possibly have a direct reference to the underlying collection implementation?
 boolean isRowUpdatePossible()
           
 boolean needsRecreate(CollectionPersister persister)
          Do we need to completely recreate this collection when it changes?
 void postFlush()
          After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.
 void preInsert(CollectionPersister persister)
          Called before inserting rows, to ensure that any surrogate keys are fully generated
protected  boolean queueAdd(Object element)
          Queue an addition
protected  boolean queueAddAll(Collection coll)
          Queue additions
 Iterator queuedAdditionIterator()
          Iterate the "queued" additions
protected  void read()
          Called by any read-only method of the collection interface
 void setCollectionSnapshot(CollectionSnapshot collectionSnapshot)
          Sets the collectionSnapshot.
 boolean setCurrentSession(SessionImplementor session)
          Associate the collection with the given session.
protected  void setDirectlyAccessible(boolean directlyAccessible)
           
protected  void setInitialized()
           
 void setOwner(Object owner)
           
protected abstract  Serializable snapshot(CollectionPersister persister)
          Return a new snapshot of the current state
 boolean unsetSession(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, getSnapshotElement, initializeFromCache, isWrapper, needsInserting, needsUpdating, readFrom
 

Constructor Detail

AbstractPersistentCollection

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


AbstractPersistentCollection

protected AbstractPersistentCollection(SessionImplementor session)
Method Detail

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


write

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


queueAdd

protected final boolean queueAdd(Object element)
Queue an addition


queueAddAll

protected final boolean queueAddAll(Collection coll)
Queue additions


delayedAddAll

public void delayedAddAll(Collection coll)
After reading all existing elements from the database, add the queued elements to the underlying collection.


postFlush

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

Specified by:
postFlush in interface PersistentCollection

getValue

public 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

Parameters:
writing - currently obsolete
Throws:
LazyInitializationException - if we cannot initialize

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(SessionImplementor currentSession)
Disassociate this collection from the given session.

Specified by:
unsetSession in interface PersistentCollection
Returns:
true if this was currently associated with the given session

setCurrentSession

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

Specified by:
setCurrentSession in interface PersistentCollection
Returns:
false if the collection was already associated with the session
Throws:
HibernateException - if the collection was already associated with another open session

needsRecreate

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

Specified by:
needsRecreate in interface PersistentCollection

getSnapshot

public final Serializable getSnapshot(CollectionPersister persister)
                               throws HibernateException
Return a new snapshot of the current state of the collection, or null if no persister is passed

Specified by:
getSnapshot in interface PersistentCollection
Throws:
HibernateException

snapshot

protected abstract Serializable snapshot(CollectionPersister persister)
                                  throws HibernateException
Return a new snapshot of the current state

Throws:
HibernateException

forceInitialization

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

Specified by:
forceInitialization in interface PersistentCollection
Throws:
HibernateException

getSnapshot

protected final 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

hasQueuedAdditions

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

Specified by:
hasQueuedAdditions in interface PersistentCollection

queuedAdditionIterator

public final Iterator queuedAdditionIterator()
Iterate the "queued" additions

Specified by:
queuedAdditionIterator in interface PersistentCollection

getCollectionSnapshot

public CollectionSnapshot getCollectionSnapshot()
Returns the collectionSnapshot.

Specified by:
getCollectionSnapshot in interface PersistentCollection
Returns:
CollectionSnapshot

setCollectionSnapshot

public void setCollectionSnapshot(CollectionSnapshot collectionSnapshot)
Sets the collectionSnapshot.

Specified by:
setCollectionSnapshot in interface PersistentCollection
Parameters:
collectionSnapshot - The collectionSnapshot to set

preInsert

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

Specified by:
preInsert in interface PersistentCollection
Throws:
HibernateException

afterRowInsert

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

Specified by:
afterRowInsert in interface PersistentCollection
Throws:
HibernateException

getOrphans

public abstract Collection getOrphans(Serializable snapshot,
                                      String entityName)
                               throws HibernateException
get all "orphaned" elements

Specified by:
getOrphans in interface PersistentCollection
Parameters:
entityName - TODO
Throws:
HibernateException

getSession

protected final SessionImplementor getSession()
Get the current session


getOrphans

protected static Collection getOrphans(Collection oldElements,
                                       Collection currentElements,
                                       String entityName,
                                       SessionImplementor session)
                                throws HibernateException
Throws:
HibernateException

getIdentifier

public Object getIdentifier(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 Object getOwner()
Specified by:
getOwner in interface PersistentCollection

setOwner

public void setOwner(Object owner)
Specified by:
setOwner in interface PersistentCollection