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 implementing
PersistentCollection
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
protected static interface
Contract for operations which are part of a collection's operation queue.protected final class
static interface
TBH not sure why this is publicprotected final class
protected final class
protected class
protected static interface
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionNot called by Hibernate, but used by non-JDK serialization, eg.protected
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Called after initialization is complete.void
afterRowInsert
(CollectionPersister persister, Object entry, int i) Called after inserting a row, to fetch the natively generated idvoid
beforeInitialize
(CollectionPersister persister, int anticipatedSize) Called prior to the initialization of this yet-uninitialized collection.void
Called just before reading any rows from the JDBC result set.final void
Clear the dirty flag, after flushing changes to the database.final void
final void
dirty()
Mark the collection as dirtyelementByIndex
(Object index) Obtain the element os this collection associated with the given index without initializing itboolean
elementExists
(Object element) Determine if the given element belongs to this collection without initializing itabstract boolean
empty()
Is the collection empty? (don't try to initialize the collection)boolean
endRead()
Called after reading all rows from the JDBC result set.final void
To be called internally by the session, forcing immediate initialization.protected int
getIdentifier
(Object entry, int i) Get the identifier of the given collection entry.final @Nullable Object
getKey()
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 Object
getOwner()
Get the owning entity.final Collection<E>
getQueuedOrphans
(String entityName) Get the "queued" orphansfinal @Nullable String
getRole()
Get the current role nameGet the session currently associated with this collection.int
getSize()
Obtain the size of this collection without initializing itprotected final Serializable
Get the current snapshot from the sessionfinal @Nullable Serializable
Get the snapshot cached by the collection instancegetValue()
Return the user-visible collection (or array) instancefinal boolean
Does this instance have any "queued" operations?static void
identityRemove
(Collection<?> list, Object entityInstance, String entityName, SharedSessionContractImplementor session) Removes entity entries that have an equal identifier with the incoming entity instanceprotected final void
initialize
(boolean writing) Initialize the collection, if possible, wrapping any exceptions in a runtime exceptionprotected boolean
Is this collection in a state that would allow us to "queue" clear? This is a special case, because of orphan delete.protected boolean
boolean
Could the application possibly have a direct reference to the underlying collection implementation?final 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.boolean
protected boolean
boolean
Is this PersistentCollection in the process of being initialized?protected boolean
Is this the "inverse" end of a bidirectional association?protected boolean
Is this the "inverse" end of a bidirectional association with no orphan delete enabled?protected boolean
Is this the "inverse" end of a bidirectional one-to-many, or of a collection with no orphan delete?protected boolean
Is this collection in a state that would allow us to "queue" operations?protected boolean
Is this collection in a state that would allow us to "queue" puts? This is a special case, because of orphan delete.boolean
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.final boolean
Is the collection unreferenced?boolean
needsRecreate
(CollectionPersister persister) Do we need to completely recreate this collection when it changes?protected final void
After reading all existing elements from the database, add the queued elements to the underlying collection.void
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 generatedprotected void
Iterator over the "queued" additionsprotected final void
Queue an additionprotected final void
read()
Called by any read-only method of the collection interfaceprotected Object
readElementByIndex
(Object index) protected Boolean
readElementExistence
(Object element) protected Boolean
readIndexExistence
(Object index) protected boolean
readSize()
Called by theCollection.size()
methodfinal void
replaceQueuedOperationValues
(CollectionPersister persister, Map<Object, Object> copyCache) Replace entity instances with copy incopyCache
.final boolean
Associate the collection with the given session.protected final void
setDirectlyAccessible
(boolean directlyAccessible) protected final void
void
Set the reference to the owning entityvoid
setSnapshot
(Object key, String role, Serializable snapshot) After flushing, re-init snapshot state.final boolean
unsetSession
(SharedSessionContractImplementor currentSession) Disassociate this collection from the given session.final boolean
Is this instance initialized?protected final void
write()
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, 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 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:PersistentCollection
Get the current role name- Specified by:
getRole
in interfacePersistentCollection<E>
- Returns:
- the collection role name
-
getKey
Description copied from interface:PersistentCollection
Get the current collection key value- Specified by:
getKey
in interfacePersistentCollection<E>
- Returns:
- the current collection key value
-
isUnreferenced
public final boolean isUnreferenced()Description copied from interface:PersistentCollection
Is the collection unreferenced?- Specified by:
isUnreferenced
in interfacePersistentCollection<E>
- Returns:
true
if the collection is no longer referenced by an owner
-
isDirty
public final boolean isDirty()Description copied from interface:PersistentCollection
Is 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:
isDirty
in interfacePersistentCollection<E>
- Returns:
true
if the collection is dirty
-
isElementRemoved
public boolean isElementRemoved()- Specified by:
isElementRemoved
in interfacePersistentCollection<E>
-
clearDirty
public final void clearDirty()Description copied from interface:PersistentCollection
Clear the dirty flag, after flushing changes to the database.- Specified by:
clearDirty
in interfacePersistentCollection<E>
-
dirty
public final void dirty()Description copied from interface:PersistentCollection
Mark the collection as dirty- Specified by:
dirty
in interfacePersistentCollection<E>
-
getStoredSnapshot
Description copied from interface:PersistentCollection
Get the snapshot cached by the collection instance- Specified by:
getStoredSnapshot
in interfacePersistentCollection<E>
- Returns:
- The internally stored snapshot state
-
empty
public abstract boolean empty()Description copied from interface:PersistentCollection
Is the collection empty? (don't try to initialize the collection)- Specified by:
empty
in interfacePersistentCollection<E>
- Returns:
false
if the collection is non-empty;true
otherwise.
-
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:PersistentCollection
Obtain the size of this collection without initializing it- Specified by:
getSize
in interfacePersistentCollection<E>
-
readIndexExistence
-
readElementExistence
-
elementExists
Description copied from interface:PersistentCollection
Determine if the given element belongs to this collection without initializing it- Specified by:
elementExists
in interfacePersistentCollection<E>
-
readElementByIndex
-
elementByIndex
Description copied from interface:PersistentCollection
Obtain the element os this collection associated with the given index without initializing it- Specified by:
elementByIndex
in 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:PersistentCollection
After flushing, re-init snapshot state.- Specified by:
setSnapshot
in 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:PersistentCollection
After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.- Specified by:
postAction
in interfacePersistentCollection<E>
-
clearOperationQueue
public final void clearOperationQueue() -
getValue
Description copied from interface:PersistentCollection
Return the user-visible collection (or array) instance- Specified by:
getValue
in interfacePersistentCollection<E>
- Returns:
- The underlying collection/array
-
beginRead
public void beginRead()Description copied from interface:PersistentCollection
Called just before reading any rows from the JDBC result set. Pairs withPersistentCollection.endRead()
- Specified by:
beginRead
in interfacePersistentCollection<E>
-
endRead
public boolean endRead()Description copied from interface:PersistentCollection
Called after reading all rows from the JDBC result set. Pairs withPersistentCollection.beginRead()
- Specified by:
endRead
in interfacePersistentCollection<E>
- See Also:
-
beforeInitialize
Description copied from interface:PersistentCollection
Called prior to the initialization of this yet-uninitialized collection. Pairs withPersistentCollection.afterInitialize()
- Specified by:
beforeInitialize
in interfacePersistentCollection<E>
-
afterInitialize
public boolean afterInitialize()Description copied from interface:PersistentCollection
Called after initialization is complete. Pairs withPersistentCollection.beforeInitialize(org.hibernate.persister.collection.CollectionPersister, int)
- Specified by:
afterInitialize
in 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:PersistentCollection
Is this PersistentCollection in the process of being initialized?- Specified by:
isInitializing
in interfacePersistentCollection<E>
-
setDirectlyAccessible
protected final void setDirectlyAccessible(boolean directlyAccessible) -
isDirectlyAccessible
public boolean isDirectlyAccessible()Description copied from interface:PersistentCollection
Could the application possibly have a direct reference to the underlying collection implementation?- Specified by:
isDirectlyAccessible
in interfacePersistentCollection<E>
- Returns:
true
indicates that the application might have access to the underlying collection/array.
-
prepareForPossibleLoadingOutsideTransaction
protected void prepareForPossibleLoadingOutsideTransaction() -
needsRecreate
Description copied from interface:PersistentCollection
Do we need to completely recreate this collection when it changes?- Specified by:
needsRecreate
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persister- Returns:
true
if a change requires a recreate.
-
forceInitialization
Description copied from interface:LazyInitializable
To be called internally by the session, forcing immediate initialization.- Specified by:
forceInitialization
in interfaceLazyInitializable
- Throws:
HibernateException
- See Also:
-
getSnapshot
Get the current snapshot from the session -
wasInitialized
public final boolean wasInitialized()Description copied from interface:LazyInitializable
Is this instance initialized?- Specified by:
wasInitialized
in interfaceLazyInitializable
- Returns:
- Was this collection initialized? Or is its data still not (fully) loaded?
- See Also:
-
isRowUpdatePossible
public boolean isRowUpdatePossible()Description copied from interface:PersistentCollection
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.- Specified by:
isRowUpdatePossible
in interfacePersistentCollection<E>
- Returns:
true
if the row for each element is known
-
hasQueuedOperations
public final boolean hasQueuedOperations()Description copied from interface:PersistentCollection
Does this instance have any "queued" operations?- Specified by:
hasQueuedOperations
in interfacePersistentCollection<E>
- Returns:
true
indicates there are pending, queued, delayed operations
-
queuedAdditionIterator
Description copied from interface:PersistentCollection
Iterator over the "queued" additions- Specified by:
queuedAdditionIterator
in interfacePersistentCollection<E>
- Returns:
- The iterator
-
getQueuedOrphans
Description copied from interface:PersistentCollection
Get the "queued" orphans- Specified by:
getQueuedOrphans
in interfacePersistentCollection<E>
- Parameters:
entityName
- The name of the entity that makes up the elements- Returns:
- The orphaned elements
-
preInsert
Description copied from interface:PersistentCollection
Called before inserting rows, to ensure that any surrogate keys are fully generated- Specified by:
preInsert
in 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:PersistentCollection
Called after inserting a row, to fetch the natively generated id- Specified by:
afterRowInsert
in 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:PersistentCollection
get all "orphaned" elements- Specified by:
getOrphans
in 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
Get the session currently associated with this collection.- Returns:
- The session
-
getIdentifier
Description copied from interface:PersistentCollection
Get 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 theidbag
collection.- Specified by:
getIdentifier
in interfacePersistentCollection<E>
- Parameters:
entry
- The collection entry/elementi
- The assumed identifier (?)- Returns:
- The identifier value
-
getOwner
Description copied from interface:PersistentCollection
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.- Specified by:
getOwner
in interfacePersistentCollection<E>
- Returns:
- The owner
-
setOwner
Description copied from interface:PersistentCollection
Set the reference to the owning entity- Specified by:
setOwner
in interfacePersistentCollection<E>
- Parameters:
owner
- The owner
-