org.hibernate.collection

Class AbstractPersistentCollection

Implemented Interfaces:
Serializable, PersistentCollection
Known Direct Subclasses:
PersistentArrayHolder, PersistentBag, PersistentElementHolder, PersistentIdentifierBag, PersistentIndexedElementHolder, PersistentList, PersistentMap, PersistentSet

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

Base class implementing PersistentCollection
Author:
Gavin King

Nested Class Summary

protected static interface
AbstractPersistentCollection.DelayedOperation

Field Summary

protected static Object
UNKNOWN

Constructor Summary

AbstractPersistentCollection()
Not called by Hibernate, but used by non-JDK serialization, eg.
AbstractPersistentCollection(SessionImplementor session)

Method Summary

boolean
afterInitialize()
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
clearDirty()
void
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()
Object
getIdentifier(Object entry, int i)
Serializable
getKey()
protected static Collection
getOrphans(Collection oldElements, Collection currentElements, String entityName, 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 Collection
getOrphans(Serializable snapshot, String entityName)
get all "orphaned" elements
Object
getOwner()
Collection
getQueuedOrphans(String entityName)
Iterate the "queued" additions
String
getRole()
SessionImplementor
getSession()
Get the current session
protected Serializable
getSnapshot()
Get the current snapshot from the session
Serializable
getStoredSnapshot()
Object
getValue()
return the user-visible collection (or array) instance
boolean
hasQueuedOperations()
Does this instance have any "queued" additions?
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.
boolean
isDirectlyAccessible()
Could the application possibly have a direct reference to the underlying collection implementation?
boolean
isDirty()
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()
boolean
needsRecreate(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(CollectionPersister persister)
Called before inserting rows, to ensure that any surrogate keys are fully generated
protected void
queueOperation(Object element)
Queue an addition
Iterator
queuedAdditionIterator()
Iterate the "queued" additions
protected void
read()
Called by any read-only method of the collection interface
protected Object
readElementByIndex(Object index)
protected Boolean
readElementExistence(Object element)
protected Boolean
readIndexExistence(Object index)
protected boolean
readSize()
Called by the size() method
boolean
setCurrentSession(SessionImplementor session)
Associate the collection with the given session.
protected void
setDirectlyAccessible(boolean directlyAccessible)
protected void
setInitialized()
void
setOwner(Object owner)
void
setSnapshot(Serializable key, String role, Serializable snapshot)
After flushing, re-init snapshot 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

Field Details

UNKNOWN

protected static final Object UNKNOWN

Constructor Details

AbstractPersistentCollection

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

AbstractPersistentCollection

protected AbstractPersistentCollection(SessionImplementor session)

Method Details

afterInitialize

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

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

beginRead

public void beginRead()
Called just before reading any rows from the JDBC result set
Specified by:
beginRead in interface PersistentCollection

clearDirty

public final void clearDirty()
Specified by:
clearDirty in interface PersistentCollection

dirty

public final void dirty()
Specified by:
dirty in interface PersistentCollection

empty

public abstract boolean empty()
Is the initialized collection empty?
Specified by:
empty in interface PersistentCollection

endRead

public boolean endRead()
Called after reading all rows from the JDBC result set
Specified by:
endRead in interface PersistentCollection

forceInitialization

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

getCachedSize

protected int getCachedSize()

getIdentifier

public Object getIdentifier(Object entry,
                            int i)
Specified by:
getIdentifier in interface PersistentCollection

getKey

public final Serializable getKey()
Specified by:
getKey in interface PersistentCollection

getOrphans

protected static Collection getOrphans(Collection oldElements,
                                       Collection currentElements,
                                       String entityName,
                                       SessionImplementor session)
            throws 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

getOrphans

public abstract Collection getOrphans(Serializable snapshot,
                                      String entityName)
            throws HibernateException
get all "orphaned" elements
Specified by:
getOrphans in interface PersistentCollection

getOwner

public Object getOwner()
Specified by:
getOwner in interface PersistentCollection

getQueuedOrphans

public final Collection getQueuedOrphans(String entityName)
Iterate the "queued" additions
Specified by:
getQueuedOrphans in interface PersistentCollection

getRole

public final String getRole()
Specified by:
getRole in interface PersistentCollection

getSession

public final SessionImplementor getSession()
Get the current session

getSnapshot

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

getStoredSnapshot

public final Serializable getStoredSnapshot()
Specified by:
getStoredSnapshot in interface PersistentCollection

getValue

public Object getValue()
return the user-visible collection (or array) instance
Specified by:
getValue in interface PersistentCollection

hasQueuedOperations

public final boolean hasQueuedOperations()
Does this instance have any "queued" additions?
Specified by:
hasQueuedOperations 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

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.

isDirectlyAccessible

public boolean isDirectlyAccessible()
Could the application possibly have a direct reference to the underlying collection implementation?
Specified by:
isDirectlyAccessible in interface PersistentCollection

isDirty

public final boolean isDirty()
Specified by:
isDirty in interface PersistentCollection

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.

isRowUpdatePossible

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

isUnreferenced

public final boolean isUnreferenced()
Specified by:
isUnreferenced in interface PersistentCollection

needsRecreate

public boolean needsRecreate(CollectionPersister persister)
Do we need to completely recreate this collection when it changes?
Specified by:
needsRecreate in interface PersistentCollection

performQueuedOperations

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

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

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

queueOperation

protected final void queueOperation(Object element)
Queue an addition

queuedAdditionIterator

public final Iterator queuedAdditionIterator()
Iterate the "queued" additions
Specified by:
queuedAdditionIterator in interface PersistentCollection

read

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

readElementByIndex

protected Object readElementByIndex(Object index)

readElementExistence

protected Boolean readElementExistence(Object element)

readIndexExistence

protected Boolean readIndexExistence(Object index)

readSize

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

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

setDirectlyAccessible

protected final void setDirectlyAccessible(boolean directlyAccessible)

setInitialized

protected final void setInitialized()

setOwner

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

setSnapshot

public void setSnapshot(Serializable key,
                        String role,
                        Serializable snapshot)
After flushing, re-init snapshot state.
Specified by:
setSnapshot 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

wasInitialized

public final boolean wasInitialized()
Is this instance initialized?
Specified by:
wasInitialized in interface PersistentCollection

write

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