Package org.hibernate.collection.spi
Class AbstractPersistentCollection<E>
- java.lang.Object
-
- org.hibernate.collection.spi.AbstractPersistentCollection<E>
-
- All Implemented Interfaces:
Serializable,LazyInitializable,PersistentCollection<E>
- Direct Known Subclasses:
PersistentArrayHolder,PersistentBag,PersistentIdentifierBag,PersistentList,PersistentMap,PersistentSet
public abstract class AbstractPersistentCollection<E> extends Object implements Serializable, PersistentCollection<E>
Base class implementingPersistentCollection- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractPersistentCollection.AbstractValueDelayedOperationprotected static interfaceAbstractPersistentCollection.DelayedOperation<E>Contract for operations which are part of a collection's operation queue.protected classAbstractPersistentCollection.IteratorProxy<E>static interfaceAbstractPersistentCollection.LazyInitializationWork<T>TBH not sure why this is publicprotected classAbstractPersistentCollection.ListIteratorProxyprotected classAbstractPersistentCollection.ListProxyprotected classAbstractPersistentCollection.SetProxy<E>protected static interfaceAbstractPersistentCollection.ValueDelayedOperation<E>
-
Field Summary
Fields Modifier and Type Field Description protected booleanelementRemovedprotected static ObjectUNKNOWN
-
Constructor Summary
Constructors Modifier Constructor Description AbstractPersistentCollection()Not called by Hibernate, but used by non-JDK serialization, eg.protectedAbstractPersistentCollection(SharedSessionContractImplementor session)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanafterInitialize()Called after initialization is complete.voidafterRowInsert(CollectionPersister persister, Object entry, int i)Called after inserting a row, to fetch the natively generated idvoidbeforeInitialize(CollectionPersister persister, int anticipatedSize)Called prior to the initialization of this yet-uninitialized collection.voidbeginRead()Called just before reading any rows from the JDBC result set.voidclearDirty()Clear the dirty flag, after flushing changes to the database.voidclearOperationQueue()voiddirty()Mark the collection as dirtyObjectelementByIndex(Object index)Obtain the element os this collection associated with the given index without initializing itbooleanelementExists(Object element)Determine if the given element belongs to this collection without initializing itabstract booleanempty()Is the collection empty? (don't try to initialize the collection)booleanendRead()Called after reading all rows from the JDBC result set.voidforceInitialization()To be called internally by the session, forcing immediate initialization.protected intgetCachedSize()ObjectgetIdentifier(Object entry, int i)Get the identifier of the given collection entry.@Nullable ObjectgetKey()Get the current collection key valueabstract Collection<E>getOrphans(Serializable snapshot, String entityName)get all "orphaned" elementsprotected static <E> Collection<E>getOrphans(Collection<E> oldElements, Collection<E> currentElements, String entityName, SharedSessionContractImplementor 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@Nullable ObjectgetOwner()Get the owning entity.Collection<E>getQueuedOrphans(String entityName)Get the "queued" orphans@Nullable StringgetRole()Get the current role nameSharedSessionContractImplementorgetSession()Get the session currently associated with this collection.intgetSize()Obtain the size of this collection without initializing itprotected SerializablegetSnapshot()Get the current snapshot from the session@Nullable SerializablegetStoredSnapshot()Get the snapshot cached by the collection instanceObjectgetValue()Return the user-visible collection (or array) instancebooleanhasQueuedOperations()Does this instance have any "queued" operations?static voididentityRemove(Collection<?> list, Object entityInstance, String entityName, SharedSessionContractImplementor session)Removes entity entries that have an equal identifier with the incoming entity instanceprotected voidinitialize(boolean writing)Initialize the collection, if possible, wrapping any exceptions in a runtime exceptionprotected booleanisClearQueueEnabled()Is this collection in a state that would allow us to "queue" clear? This is a special case, because of orphan delete.protected booleanisConnectedToSession()booleanisDirectlyAccessible()Could 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.booleanisElementRemoved()protected booleanisInitialized()booleanisInitializing()Is this PersistentCollection in the process of being initialized?protected booleanisInverseCollection()Is this the "inverse" end of a bidirectional association?protected booleanisInverseCollectionNoOrphanDelete()Is this the "inverse" end of a bidirectional association with no orphan delete enabled?protected booleanisInverseOneToManyOrNoOrphanDelete()Is this the "inverse" end of a bidirectional one-to-many, or of a collection with no orphan delete?protected booleanisOperationQueueEnabled()Is this collection in a state that would allow us to "queue" operations?protected booleanisPutQueueEnabled()Is this collection in a state that would allow us to "queue" puts? This is a special case, because of orphan delete.booleanisRowUpdatePossible()Can each element in the collection be mapped unequivocally to a single row in the database? Generally bags and sets are the only collections that cannot be.booleanisUnreferenced()Is the collection unreferenced?booleanneedsRecreate(CollectionPersister persister)Do we need to completely recreate this collection when it changes?protected voidperformQueuedOperations()After reading all existing elements from the database, add the queued elements to the underlying collection.voidpostAction()After 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 generatedprotected voidprepareForPossibleLoadingOutsideTransaction()Iterator<E>queuedAdditionIterator()Iterator over the "queued" additionsprotected voidqueueOperation(AbstractPersistentCollection.DelayedOperation<E> operation)Queue an additionprotected 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 theCollection.size()methodvoidreplaceQueuedOperationValues(CollectionPersister persister, Map<Object,Object> copyCache)Replace entity instances with copy incopyCache/.booleansetCurrentSession(SharedSessionContractImplementor session)Associate the collection with the given session.protected voidsetDirectlyAccessible(boolean directlyAccessible)protected voidsetInitialized()voidsetOwner(Object owner)Set the reference to the owning entityvoidsetSnapshot(Object key, String role, Serializable snapshot)After flushing, re-init snapshot state.booleanunsetSession(SharedSessionContractImplementor currentSession)Disassociate this collection from the given session.booleanwasInitialized()Is this instance initialized?protected voidwrite()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.spi.PersistentCollection
disassemble, entries, entryExists, equalsSnapshot, getDeletes, getElement, getIndex, getSnapshot, getSnapshotElement, includeInInsert, includeInRecreate, initializeEmptyCollection, initializeFromCache, injectLoadedState, isDirectlyProvidedCollection, isNewlyInstantiated, isSnapshotEmpty, isWrapper, needsInserting, needsUpdating, needsUpdating, render
-
-
-
-
Field Detail
-
elementRemoved
protected boolean elementRemoved
-
UNKNOWN
protected static final Object UNKNOWN
-
-
Constructor Detail
-
AbstractPersistentCollection
public AbstractPersistentCollection()
Not called by Hibernate, but used by non-JDK serialization, eg. SOAP libraries.
-
AbstractPersistentCollection
protected AbstractPersistentCollection(SharedSessionContractImplementor session)
-
-
Method Detail
-
getRole
public final @Nullable String getRole()
Description copied from interface:PersistentCollectionGet the current role name- Specified by:
getRolein interfacePersistentCollection<E>- Returns:
- the collection role name
-
getKey
public final @Nullable Object getKey()
Description copied from interface:PersistentCollectionGet the current collection key value- Specified by:
getKeyin interfacePersistentCollection<E>- Returns:
- the current collection key value
-
isUnreferenced
public final boolean isUnreferenced()
Description copied from interface:PersistentCollectionIs the collection unreferenced?- Specified by:
isUnreferencedin interfacePersistentCollection<E>- Returns:
trueif the collection is no longer referenced by an owner
-
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<E>- Returns:
trueif the collection is dirty
-
isElementRemoved
public boolean isElementRemoved()
- Specified by:
isElementRemovedin interfacePersistentCollection<E>
-
clearDirty
public final void clearDirty()
Description copied from interface:PersistentCollectionClear the dirty flag, after flushing changes to the database.- Specified by:
clearDirtyin interfacePersistentCollection<E>
-
dirty
public final void dirty()
Description copied from interface:PersistentCollectionMark the collection as dirty- Specified by:
dirtyin interfacePersistentCollection<E>
-
getStoredSnapshot
public final @Nullable Serializable getStoredSnapshot()
Description copied from interface:PersistentCollectionGet the snapshot cached by the collection instance- Specified by:
getStoredSnapshotin interfacePersistentCollection<E>- Returns:
- The internally stored snapshot state
-
empty
public abstract boolean empty()
Description copied from interface:PersistentCollectionIs the collection empty? (don't try to initialize the collection)- Specified by:
emptyin interfacePersistentCollection<E>- Returns:
falseif the collection is non-empty;trueotherwise.
-
read
protected final void read()
Called by any read-only method of the collection interface
-
readSize
protected boolean readSize()
Called by theCollection.size()method
-
getSize
public int getSize()
Description copied from interface:PersistentCollectionObtain the size of this collection without initializing it- Specified by:
getSizein interfacePersistentCollection<E>
-
elementExists
public boolean elementExists(Object element)
Description copied from interface:PersistentCollectionDetermine if the given element belongs to this collection without initializing it- Specified by:
elementExistsin interfacePersistentCollection<E>
-
elementByIndex
public Object elementByIndex(Object index)
Description copied from interface:PersistentCollectionObtain the element os this collection associated with the given index without initializing it- Specified by:
elementByIndexin interfacePersistentCollection<E>
-
getCachedSize
protected int getCachedSize()
-
isConnectedToSession
protected boolean isConnectedToSession()
-
isInitialized
protected boolean isInitialized()
-
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
protected boolean isInverseCollection()
Is this the "inverse" end of a bidirectional association?
-
isInverseCollectionNoOrphanDelete
protected boolean isInverseCollectionNoOrphanDelete()
Is this the "inverse" end of a bidirectional association with no orphan delete enabled?
-
isInverseOneToManyOrNoOrphanDelete
protected 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(AbstractPersistentCollection.DelayedOperation<E> operation)
Queue an addition
-
replaceQueuedOperationValues
public final void replaceQueuedOperationValues(CollectionPersister persister, Map<Object,Object> copyCache)
Replace entity instances with copy incopyCache/.- Parameters:
copyCache- - mapping from entity in the process of being merged to managed copy.
-
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(Object key, String role, Serializable snapshot)
Description copied from interface:PersistentCollectionAfter flushing, re-init snapshot state.- Specified by:
setSnapshotin interfacePersistentCollection<E>- Parameters:
key- The collection instance key (fk value).role- The collection rolesnapshot- The snapshot state
-
postAction
public void postAction()
Description copied from interface:PersistentCollectionAfter flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.- Specified by:
postActionin interfacePersistentCollection<E>
-
clearOperationQueue
public final void clearOperationQueue()
-
getValue
public Object getValue()
Description copied from interface:PersistentCollectionReturn the user-visible collection (or array) instance- Specified by:
getValuein interfacePersistentCollection<E>- Returns:
- The underlying collection/array
-
beginRead
public void beginRead()
Description copied from interface:PersistentCollectionCalled just before reading any rows from the JDBC result set. Pairs withPersistentCollection.endRead()- Specified by:
beginReadin interfacePersistentCollection<E>
-
endRead
public boolean endRead()
Description copied from interface:PersistentCollectionCalled after reading all rows from the JDBC result set. Pairs withPersistentCollection.beginRead()- Specified by:
endReadin interfacePersistentCollection<E>- See Also:
PersistentCollection.injectLoadedState(org.hibernate.metamodel.mapping.PluralAttributeMapping, java.util.List<?>)
-
beforeInitialize
public void beforeInitialize(CollectionPersister persister, int anticipatedSize)
Description copied from interface:PersistentCollectionCalled prior to the initialization of this yet-uninitialized collection. Pairs withPersistentCollection.afterInitialize()- Specified by:
beforeInitializein interfacePersistentCollection<E>
-
afterInitialize
public boolean afterInitialize()
Description copied from interface:PersistentCollectionCalled after initialization is complete. Pairs withPersistentCollection.beforeInitialize(org.hibernate.persister.collection.CollectionPersister, int)- Specified by:
afterInitializein interfacePersistentCollection<E>
-
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()
-
isInitializing
public boolean isInitializing()
Description copied from interface:PersistentCollectionIs this PersistentCollection in the process of being initialized?- Specified by:
isInitializingin interfacePersistentCollection<E>
-
setDirectlyAccessible
protected final void setDirectlyAccessible(boolean directlyAccessible)
-
isDirectlyAccessible
public boolean isDirectlyAccessible()
Description copied from interface:PersistentCollectionCould the application possibly have a direct reference to the underlying collection implementation?- Specified by:
isDirectlyAccessiblein interfacePersistentCollection<E>- Returns:
trueindicates that the application might have access to the underlying collection/array.
-
unsetSession
public final boolean unsetSession(SharedSessionContractImplementor currentSession)
Description copied from interface:PersistentCollectionDisassociate this collection from the given session.- Specified by:
unsetSessionin interfacePersistentCollection<E>- Parameters:
currentSession- The session we are disassociating from. Used for validations.- Returns:
- true if this was currently associated with the given session
-
prepareForPossibleLoadingOutsideTransaction
protected void prepareForPossibleLoadingOutsideTransaction()
-
setCurrentSession
public final boolean setCurrentSession(SharedSessionContractImplementor session) throws HibernateException
Description copied from interface:PersistentCollectionAssociate the collection with the given session.- Specified by:
setCurrentSessionin interfacePersistentCollection<E>- Parameters:
session- The session to associate with- 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)
Description copied from interface:PersistentCollectionDo we need to completely recreate this collection when it changes?- Specified by:
needsRecreatein interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
trueif a change requires a recreate.
-
forceInitialization
public final void forceInitialization() throws HibernateExceptionDescription copied from interface:LazyInitializableTo be called internally by the session, forcing immediate initialization.- Specified by:
forceInitializationin interfaceLazyInitializable- Throws:
HibernateException- See Also:
Hibernate.initialize(Object)
-
getSnapshot
protected final Serializable getSnapshot()
Get the current snapshot from the session
-
wasInitialized
public final boolean wasInitialized()
Description copied from interface:LazyInitializableIs this instance initialized?- Specified by:
wasInitializedin interfaceLazyInitializable- Returns:
- Was this collection initialized? Or is its data still not (fully) loaded?
- See Also:
Hibernate.isInitialized(Object)
-
isRowUpdatePossible
public boolean isRowUpdatePossible()
Description copied from interface:PersistentCollectionCan each element in the collection be mapped unequivocally to a single row in the database? Generally bags and sets are the only collections that cannot be.- Specified by:
isRowUpdatePossiblein interfacePersistentCollection<E>- Returns:
trueif the row for each element is known
-
hasQueuedOperations
public final boolean hasQueuedOperations()
Description copied from interface:PersistentCollectionDoes this instance have any "queued" operations?- Specified by:
hasQueuedOperationsin interfacePersistentCollection<E>- Returns:
trueindicates there are pending, queued, delayed operations
-
queuedAdditionIterator
public final Iterator<E> queuedAdditionIterator()
Description copied from interface:PersistentCollectionIterator over the "queued" additions- Specified by:
queuedAdditionIteratorin interfacePersistentCollection<E>- Returns:
- The iterator
-
getQueuedOrphans
public final Collection<E> getQueuedOrphans(String entityName)
Description copied from interface:PersistentCollectionGet the "queued" orphans- Specified by:
getQueuedOrphansin interfacePersistentCollection<E>- Parameters:
entityName- The name of the entity that makes up the elements- Returns:
- The orphaned elements
-
preInsert
public void preInsert(CollectionPersister persister) throws HibernateException
Description copied from interface:PersistentCollectionCalled before inserting rows, to ensure that any surrogate keys are fully generated- Specified by:
preInsertin interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Throws:
HibernateException
-
afterRowInsert
public void afterRowInsert(CollectionPersister persister, Object entry, int i) throws HibernateException
Description copied from interface:PersistentCollectionCalled after inserting a row, to fetch the natively generated id- Specified by:
afterRowInsertin interfacePersistentCollection<E>- Parameters:
persister- The collection persisterentry- The collection element just insertedi- The element position/index- Throws:
HibernateException
-
getOrphans
public abstract Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException
Description copied from interface:PersistentCollectionget all "orphaned" elements- Specified by:
getOrphansin interfacePersistentCollection<E>- Parameters:
snapshot- The snapshot stateentityName- The name of the entity that are the elements of the collection- Returns:
- The orphans
- Throws:
HibernateException
-
getSession
public final SharedSessionContractImplementor getSession()
Get the session currently associated with this collection.- Returns:
- The session
-
getOrphans
protected static <E> Collection<E> getOrphans(Collection<E> oldElements, Collection<E> currentElements, String entityName, SharedSessionContractImplementor 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
-
identityRemove
public static void identityRemove(Collection<?> list, Object entityInstance, String entityName, SharedSessionContractImplementor session)
Removes entity entries that have an equal identifier with the incoming entity instance- Parameters:
list- The list containing the entity instancesentityInstance- The entity instance to match elements.entityName- The entity namesession- The session
-
getIdentifier
public Object getIdentifier(Object entry, int i)
Description copied from interface:PersistentCollectionGet the identifier of the given collection entry. This refers to the collection identifier, not the identifier of the (possibly) entity elements. This is only valid for invocation on theidbagcollection.- Specified by:
getIdentifierin interfacePersistentCollection<E>- Parameters:
entry- The collection entry/elementi- The assumed identifier (?)- Returns:
- The identifier value
-
getOwner
public @Nullable Object 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<E>- Returns:
- The owner
-
setOwner
public void setOwner(Object owner)
Description copied from interface:PersistentCollectionSet the reference to the owning entity- Specified by:
setOwnerin interfacePersistentCollection<E>- Parameters:
owner- The owner
-
-