Package org.hibernate.collection
Interface PersistentCollection
- All Known Implementing Classes:
AbstractPersistentCollection,PersistentArrayHolder,PersistentBag,PersistentElementHolder,PersistentIdentifierBag,PersistentIndexedElementHolder,PersistentList,PersistentListElementHolder,PersistentMap,PersistentMapElementHolder,PersistentSet,PersistentSortedMap,PersistentSortedSet
public interface PersistentCollection
Persistent collections are treated as value objects by Hibernate.
ie. they have no independent existence beyond the object holding
a reference to them. Unlike instances of entity classes, they are
automatically deleted when unreferenced and automatically become
persistent when held by a persistent object. Collections can be
passed between different objects (change "roles") and this might
cause their elements to move from one database table to another.
Hibernate "wraps" a java collection in an instance of PersistentCollection. This mechanism is designed to support tracking of changes to the collection's persistent state and lazy instantiation of collection elements. The downside is that only certain abstract collection types are supported and any extra semantics are lost
Applications should never use classes in this package directly, unless extending the "framework" here.
Changes to structure of the collection are recorded by the collection calling back to the session. Changes to mutable elements (ie. composite elements) are discovered by cloning their state when the collection is initialized and comparing at flush time.
Hibernate "wraps" a java collection in an instance of PersistentCollection. This mechanism is designed to support tracking of changes to the collection's persistent state and lazy instantiation of collection elements. The downside is that only certain abstract collection types are supported and any extra semantics are lost
Applications should never use classes in this package directly, unless extending the "framework" here.
Changes to structure of the collection are recorded by the collection calling back to the session. Changes to mutable elements (ie. composite elements) are discovered by cloning their state when the collection is initialized and comparing at flush time.
-
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 idvoidbeforeInitialize(CollectionPersister persister, int anticipatedSize) Called before any elements are read into the collection, allowing appropriate initializations to occur.voidCalled just before reading any rows from the JDBC result setvoidClear the dirty flag, after flushing changes to the database.voiddirty()Mark the collection as dirtydisassemble(CollectionPersister persister) Disassemble the collection, ready for the cachebooleanempty()Is the collection empty? (don't try to initialize the collection)booleanendRead()Called after reading all rows from the JDBC result setentries(CollectionPersister persister) Iterate all collection entries, during update of the databasebooleanentryExists(Object entry, int i) Does an element exist at this entry in the collection?booleanequalsSnapshot(CollectionPersister persister) Does the current state exactly match the snapshot?voidTo be called internally by the session, forcing immediate initialization.getDeletes(CollectionPersister persister, boolean indexIsFormula) Get all the elements that need deletinggetElement(Object entry) Get the value of the given collection entrygetIdentifier(Object entry, int i) Get the index of the given collection entrygetIndex(Object entry, int i, CollectionPersister persister) Get the index of the given collection entrygetKey()Get the current collection key valuegetOrphans(Serializable snapshot, String entityName) get all "orphaned" elementsgetOwner()Get the owning entity.getQueuedOrphans(String entityName) Get the "queued" orphansgetRole()Get the current role namegetSnapshot(CollectionPersister persister) Return a new snapshot of the current state of the collectiongetSnapshotElement(Object entry, int i) Get the snapshot value of the given collection entryGet the snapshot cached by the collection instancegetValue()return the user-visible collection (or array) instancebooleanDoes this instance have any "queued" additions?voidinitializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) Read the state of the collection from a disassembled cached valuebooleanCould the application possibly have a direct reference to the underlying collection implementation?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.booleanbooleanisSnapshotEmpty(Serializable snapshot) Is the snapshot empty?booleanIs the collection unreferenced?booleanIs this the wrapper for the given underlying collection instance?booleanneedsInserting(Object entry, int i, Type elemType) Do we need to insert this element?booleanneedsRecreate(CollectionPersister persister) Do we need to completely recreate this collection when it changes?booleanneedsUpdating(Object entry, int i, Type elemType) Do we need to update this element?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 generatedIterate the "queued" additionsreadFrom(ResultSet rs, CollectionPersister role, CollectionAliases descriptor, Object owner) Read a row from the JDBC result setbooleansetCurrentSession(SessionImplementor session) Associate the collection with the given session.voidSet the reference to the owning entityvoidsetSnapshot(Serializable key, String role, Serializable snapshot) After flushing, re-init snapshot state.booleanunsetSession(SessionImplementor currentSession) Disassociate this collection from the given session.booleanIs this instance initialized?
-
Method Details
-
getOwner
Object getOwner()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. -
setOwner
Set the reference to the owning entity -
empty
boolean empty()Is the collection empty? (don't try to initialize the collection) -
setSnapshot
After flushing, re-init snapshot state. -
postAction
void postAction()After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state. -
getValue
Object getValue()return the user-visible collection (or array) instance -
beginRead
void beginRead()Called just before reading any rows from the JDBC result set -
endRead
boolean endRead()Called after reading all rows from the JDBC result set -
afterInitialize
boolean afterInitialize()Called after initializing from cache -
isDirectlyAccessible
boolean isDirectlyAccessible()Could the application possibly have a direct reference to the underlying collection implementation? -
unsetSession
Disassociate this collection from the given session.- Returns:
- true if this was currently associated with the given session
-
setCurrentSession
Associate the collection with the given session.- Returns:
- false if the collection was already associated with the session
- Throws:
HibernateException- if the collection was already associated with another open session
-
initializeFromCache
void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException Read the state of the collection from a disassembled cached value- Throws:
HibernateException
-
entries
Iterate all collection entries, during update of the database -
readFrom
Object readFrom(ResultSet rs, CollectionPersister role, CollectionAliases descriptor, Object owner) throws HibernateException, SQLException Read a row from the JDBC result set- Throws:
HibernateExceptionSQLException
-
getIdentifier
Get the index of the given collection entry -
getIndex
Get the index of the given collection entry- Parameters:
persister- it was more elegant before we added this...
-
getElement
Get the value of the given collection entry -
getSnapshotElement
Get the snapshot value of the given collection entry -
beforeInitialize
Called before any elements are read into the collection, allowing appropriate initializations to occur.- Parameters:
persister- The underlying collection persister.anticipatedSize- The anticipated size of the collection after initilization is complete.
-
equalsSnapshot
Does the current state exactly match the snapshot?- Throws:
HibernateException
-
isSnapshotEmpty
Is the snapshot empty? -
disassemble
Disassemble the collection, ready for the cache- Throws:
HibernateException
-
needsRecreate
Do we need to completely recreate this collection when it changes? -
getSnapshot
Return a new snapshot of the current state of the collection- Throws:
HibernateException
-
forceInitialization
To be called internally by the session, forcing immediate initialization.- Throws:
HibernateException
-
entryExists
Does an element exist at this entry in the collection? -
needsInserting
Do we need to insert this element?- Throws:
HibernateException
-
needsUpdating
Do we need to update this element?- Throws:
HibernateException
-
isRowUpdatePossible
boolean isRowUpdatePossible() -
getDeletes
Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException Get all the elements that need deleting- Throws:
HibernateException
-
isWrapper
Is this the wrapper for the given underlying collection instance? -
wasInitialized
boolean wasInitialized()Is this instance initialized? -
hasQueuedOperations
boolean hasQueuedOperations()Does this instance have any "queued" additions? -
queuedAdditionIterator
Iterator queuedAdditionIterator()Iterate the "queued" additions -
getQueuedOrphans
Get the "queued" orphans -
getKey
Serializable getKey()Get the current collection key value -
getRole
String getRole()Get the current role name -
isUnreferenced
boolean isUnreferenced()Is the collection unreferenced? -
isDirty
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. -
clearDirty
void clearDirty()Clear the dirty flag, after flushing changes to the database. -
getStoredSnapshot
Serializable getStoredSnapshot()Get the snapshot cached by the collection instance -
dirty
void dirty()Mark the collection as dirty -
preInsert
Called before inserting rows, to ensure that any surrogate keys are fully generated- Throws:
HibernateException
-
afterRowInsert
Called after inserting a row, to fetch the natively generated id- Throws:
HibernateException
-
getOrphans
get all "orphaned" elements- Throws:
HibernateException
-