Package org.hibernate.collection
Class AbstractPersistentCollection
java.lang.Object
org.hibernate.collection.AbstractPersistentCollection
- All Implemented Interfaces:
Serializable,PersistentCollection
- Direct Known Subclasses:
PersistentArrayHolder,PersistentBag,PersistentElementHolder,PersistentIdentifierBag,PersistentIndexedElementHolder,PersistentList,PersistentMap,PersistentSet
public abstract class AbstractPersistentCollection
extends Object
implements Serializable, PersistentCollection
Base class implementing
PersistentCollection- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionNot called by Hibernate, but used by non-JDK serialization, eg.protected -
Method Summary
Modifier and TypeMethodDescriptionbooleanCalled after initializing from cachevoidafterRowInsert(CollectionPersister persister, Object entry, int i) Called after inserting a row, to fetch the natively generated idvoidCalled just before reading any rows from the JDBC result setfinal voidClear the dirty flag, after flushing changes to the database.final voiddirty()Mark the collection as dirtyabstract booleanempty()Is the initialized collection empty?booleanendRead()Called after reading all rows from the JDBC result setfinal voidTo be called internally by the session, forcing immediate initialization.protected intgetIdentifier(Object entry, int i) Get the index of the given collection entryfinal SerializablegetKey()Get the current collection key valueabstract CollectiongetOrphans(Serializable snapshot, String entityName) get all "orphaned" elementsprotected static CollectiongetOrphans(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 orphansgetOwner()Get the owning entity.final CollectiongetQueuedOrphans(String entityName) Iterate the "queued" additionsfinal StringgetRole()Get the current role namefinal SessionImplementorGet the current sessionprotected final SerializableGet the current snapshot from the sessionfinal SerializableGet the snapshot cached by the collection instancegetValue()return the user-visible collection (or array) instancefinal booleanDoes this instance have any "queued" additions?protected final voidinitialize(boolean writing) Initialize the collection, if possible, wrapping any exceptions in a runtime exceptionprotected booleanIs this collection in a state that would allow us to "queue" clear? This is a special case, because of orphan delete.booleanCould the application possibly have a direct reference to the underlying collection implementation?final booleanisDirty()Is the collection dirty? Note that this is only reliable during the flush cycle, after the collection elements are dirty checked against the snapshot.protected booleanIs this collection in a state that would allow us to "queue" operations?protected booleanIs this collection in a state that would allow us to "queue" puts? This is a special case, because of orphan delete.booleanfinal booleanIs the collection unreferenced?booleanneedsRecreate(CollectionPersister persister) Do we need to completely recreate this collection when it changes?protected final voidAfter reading all existing elements from the database, add the queued elements to the underlying collection.voidAfter flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.voidpreInsert(CollectionPersister persister) Called before inserting rows, to ensure that any surrogate keys are fully generatedfinal IteratorIterate the "queued" additionsprotected final voidqueueOperation(Object element) Queue an additionprotected final voidread()Called by any read-only method of the collection interfaceprotected ObjectreadElementByIndex(Object index) protected BooleanreadElementExistence(Object element) protected BooleanreadIndexExistence(Object index) protected booleanreadSize()Called by the size() methodfinal booleansetCurrentSession(SessionImplementor session) Associate the collection with the given session.protected final voidsetDirectlyAccessible(boolean directlyAccessible) protected final voidvoidSet the reference to the owning entityvoidsetSnapshot(Serializable key, String role, Serializable snapshot) After flushing, re-init snapshot state.final booleanunsetSession(SessionImplementor currentSession) Disassociate this collection from the given session.final booleanIs this instance initialized?protected final voidwrite()Called by any writer method of the collection interfaceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.collection.PersistentCollection
beforeInitialize, disassemble, entries, entryExists, equalsSnapshot, getDeletes, getElement, getIndex, getSnapshot, getSnapshotElement, initializeFromCache, isSnapshotEmpty, isWrapper, needsInserting, needsUpdating, readFrom
-
Field Details
-
UNKNOWN
-
-
Constructor Details
-
AbstractPersistentCollection
public AbstractPersistentCollection()Not called by Hibernate, but used by non-JDK serialization, eg. SOAP libraries. -
AbstractPersistentCollection
-
-
Method Details
-
getRole
Description copied from interface:PersistentCollectionGet the current role name- Specified by:
getRolein interfacePersistentCollection
-
getKey
Description copied from interface:PersistentCollectionGet the current collection key value- Specified by:
getKeyin interfacePersistentCollection
-
isUnreferenced
public final boolean isUnreferenced()Description copied from interface:PersistentCollectionIs the collection unreferenced?- Specified by:
isUnreferencedin interfacePersistentCollection
-
isDirty
public final boolean isDirty()Description copied from interface:PersistentCollectionIs 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:
isDirtyin interfacePersistentCollection
-
clearDirty
public final void clearDirty()Description copied from interface:PersistentCollectionClear the dirty flag, after flushing changes to the database.- Specified by:
clearDirtyin interfacePersistentCollection
-
dirty
public final void dirty()Description copied from interface:PersistentCollectionMark the collection as dirty- Specified by:
dirtyin interfacePersistentCollection
-
getStoredSnapshot
Description copied from interface:PersistentCollectionGet the snapshot cached by the collection instance- Specified by:
getStoredSnapshotin interfacePersistentCollection
-
empty
public abstract boolean empty()Is the initialized collection empty?- Specified by:
emptyin interfacePersistentCollection
-
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
-
readElementExistence
-
readElementByIndex
-
getCachedSize
protected int getCachedSize() -
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. -
queueOperation
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
After flushing, re-init snapshot state.- Specified by:
setSnapshotin interfacePersistentCollection
-
postAction
public void postAction()After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.- Specified by:
postActionin interfacePersistentCollection
-
getValue
return the user-visible collection (or array) instance- Specified by:
getValuein interfacePersistentCollection
-
beginRead
public void beginRead()Called just before reading any rows from the JDBC result set- Specified by:
beginReadin interfacePersistentCollection
-
endRead
public boolean endRead()Called after reading all rows from the JDBC result set- Specified by:
endReadin interfacePersistentCollection
-
afterInitialize
public boolean afterInitialize()Description copied from interface:PersistentCollectionCalled after initializing from cache- Specified by:
afterInitializein interfacePersistentCollection
-
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:
isDirectlyAccessiblein interfacePersistentCollection
-
unsetSession
Disassociate this collection from the given session.- Specified by:
unsetSessionin interfacePersistentCollection- Returns:
- true if this was currently associated with the given session
-
setCurrentSession
Associate the collection with the given session.- Specified by:
setCurrentSessionin interfacePersistentCollection- Returns:
- false if the collection was already associated with the session
- Throws:
HibernateException- if the collection was already associated with another open session
-
needsRecreate
Do we need to completely recreate this collection when it changes?- Specified by:
needsRecreatein interfacePersistentCollection
-
forceInitialization
To be called internally by the session, forcing immediate initialization.- Specified by:
forceInitializationin interfacePersistentCollection- Throws:
HibernateException
-
getSnapshot
Get the current snapshot from the session -
wasInitialized
public final boolean wasInitialized()Is this instance initialized?- Specified by:
wasInitializedin interfacePersistentCollection
-
isRowUpdatePossible
public boolean isRowUpdatePossible()- Specified by:
isRowUpdatePossiblein interfacePersistentCollection
-
hasQueuedOperations
public final boolean hasQueuedOperations()Does this instance have any "queued" additions?- Specified by:
hasQueuedOperationsin interfacePersistentCollection
-
queuedAdditionIterator
Iterate the "queued" additions- Specified by:
queuedAdditionIteratorin interfacePersistentCollection
-
getQueuedOrphans
Iterate the "queued" additions- Specified by:
getQueuedOrphansin interfacePersistentCollection
-
preInsert
Called before inserting rows, to ensure that any surrogate keys are fully generated- Specified by:
preInsertin interfacePersistentCollection- 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:
afterRowInsertin interfacePersistentCollection- Throws:
HibernateException
-
getOrphans
public abstract Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException get all "orphaned" elements- Specified by:
getOrphansin interfacePersistentCollection- Throws:
HibernateException
-
getSession
Get the current session -
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- Throws:
HibernateException
-
getIdentifier
Description copied from interface:PersistentCollectionGet the index of the given collection entry- Specified by:
getIdentifierin interfacePersistentCollection
-
getOwner
Description copied from interface:PersistentCollectionGet 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:
getOwnerin interfacePersistentCollection
-
setOwner
Description copied from interface:PersistentCollectionSet the reference to the owning entity- Specified by:
setOwnerin interfacePersistentCollection
-