Package org.hibernate.collection.spi
Class AbstractPersistentCollection<E>
java.lang.Object
org.hibernate.collection.spi.AbstractPersistentCollection<E>
- All Implemented Interfaces:
Serializable,LazyInitializable,PersistentCollection<E>,InstanceIdentity
- Direct Known Subclasses:
PersistentArrayHolder,PersistentBag,PersistentIdentifierBag,PersistentList,PersistentMap,PersistentSet
public abstract class AbstractPersistentCollection<E>
extends Object
implements Serializable, PersistentCollection<E>
Base class implementing
PersistentCollection- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected static interfaceContract for operations which are part of a collection's operation queue.protected final classstatic interfaceTBH not sure why this is publicprotected final classprotected final classprotected classprotected static interface -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionNot called by Hibernate, but used by non-JDK serialization, eg.protected -
Method Summary
Modifier and TypeMethodDescriptionintRetrieve the unique identifier of this instancevoid$$_hibernate_setInstanceId(int instanceId) Set the value of the unique identifier for this instancebooleanCalled 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.voidCalled just before reading any rows from the JDBC result set.static voidcheckPersister(PersistentCollection collection, CollectionPersister persister) final voidClear the dirty flag, after flushing changes to the database.final voidfinal voiddirty()Mark the collection as dirtyelementByIndex(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.final voidTo be called internally by the session, forcing immediate initialization.protected intgetIdentifier(Object entry, int i) Get the identifier of the given collection entry.final @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.final Collection<E> getQueuedOrphans(String entityName) Get the "queued" orphansfinal @Nullable StringgetRole()Get the current role nameGet the session currently associated with this collection.intgetSize()Obtain the size of this collection without initializing itprotected final SerializableGet the current snapshot from the sessionfinal @Nullable SerializableGet the snapshot cached by the collection instancegetValue()Return the user-visible collection (or array) instancefinal booleanDoes 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 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.protected booleanbooleanCould 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.booleanprotected booleanbooleanIs this PersistentCollection in the process of being initialized?protected booleanIs this the "inverse" end of a bidirectional association?protected booleanIs this the "inverse" end of a bidirectional association with no orphan delete enabled?protected booleanIs this the "inverse" end of a bidirectional one-to-many, or of a collection with no orphan delete?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.booleanCan 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.final 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 generatedprotected voidfinal Iterator<?> Iterator over the "queued" additionsprotected final voidQueue 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 theCollection.size()methodfinal voidreplaceQueuedOperationValues(CollectionPersister persister, Map<Object, Object> copyCache) Replace entity instances with copy incopyCache.final booleanAssociate the collection with the given session.protected final voidsetDirectlyAccessible(boolean directlyAccessible) protected final voidvoidSet the reference to the owning entityvoidsetSnapshot(Object key, String role, Serializable snapshot) After flushing, re-init snapshot state.final booleanunsetSession(SharedSessionContractImplementor 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.spi.PersistentCollection
disassemble, entries, entryExists, equalsSnapshot, getDeletes, getElement, getIndex, getSnapshot, getSnapshotElement, hasDeletes, includeInInsert, includeInRecreate, initializeEmptyCollection, initializeFromCache, injectLoadedState, isDirectlyProvidedCollection, isNewlyInstantiated, isSnapshotEmpty, isWrapper, needsInserting, needsUpdating, needsUpdating, render
-
Field Details
-
elementRemoved
protected boolean elementRemoved -
UNKNOWN
-
-
Constructor Details
-
AbstractPersistentCollection
public AbstractPersistentCollection()Not called by Hibernate, but used by non-JDK serialization, eg. SOAP libraries.
-
-
Method Details
-
getRole
Description copied from interface:PersistentCollectionGet the current role name- Specified by:
getRolein interfacePersistentCollection<E>- Returns:
- the collection role name
-
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
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>
-
readIndexExistence
-
readElementExistence
-
elementExists
Description copied from interface:PersistentCollectionDetermine if the given element belongs to this collection without initializing it- Specified by:
elementExistsin interfacePersistentCollection<E>
-
readElementByIndex
-
elementByIndex
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
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
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
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:
-
beforeInitialize
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
-
checkPersister
-
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.
-
prepareForPossibleLoadingOutsideTransaction
protected void prepareForPossibleLoadingOutsideTransaction() -
needsRecreate
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
Description copied from interface:LazyInitializableTo be called internally by the session, forcing immediate initialization.- Specified by:
forceInitializationin interfaceLazyInitializable- Throws:
HibernateException- See Also:
-
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:
-
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
Description copied from interface:PersistentCollectionIterator over the "queued" additions- Specified by:
queuedAdditionIteratorin interfacePersistentCollection<E>- Returns:
- The iterator
-
getQueuedOrphans
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
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
Description copied from interface:PersistentCollectionGet the session currently associated with this collection. Declared here for use by Hibernate Reactive.- Specified by:
getSessionin interfacePersistentCollection<E>
-
getIdentifier
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
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
Description copied from interface:PersistentCollectionSet the reference to the owning entity- Specified by:
setOwnerin interfacePersistentCollection<E>- Parameters:
owner- The owner
-
$$_hibernate_getInstanceId
public int $$_hibernate_getInstanceId()Description copied from interface:InstanceIdentityRetrieve the unique identifier of this instance- Specified by:
$$_hibernate_getInstanceIdin interfaceInstanceIdentity- Returns:
- the unique instance identifier
-
$$_hibernate_setInstanceId
public void $$_hibernate_setInstanceId(int instanceId) Description copied from interface:InstanceIdentitySet the value of the unique identifier for this instance- Specified by:
$$_hibernate_setInstanceIdin interfaceInstanceIdentity- Parameters:
instanceId- the unique identifier value to set
-