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:
  • Field Details

    • elementRemoved

      protected boolean elementRemoved
    • UNKNOWN

      protected static final Object UNKNOWN
  • Constructor Details

    • AbstractPersistentCollection

      public AbstractPersistentCollection()
      Not called by Hibernate, but used by non-JDK serialization, eg. SOAP libraries.
    • AbstractPersistentCollection

      protected AbstractPersistentCollection(SharedSessionContractImplementor session)
  • Method Details

    • getRole

      public final @Nullable String getRole()
      Description copied from interface: PersistentCollection
      Get the current role name
      Specified by:
      getRole in interface PersistentCollection<E>
      Returns:
      the collection role name
    • getKey

      public final @Nullable Object getKey()
      Description copied from interface: PersistentCollection
      Get the current collection key value
      Specified by:
      getKey in interface PersistentCollection<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 interface PersistentCollection<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 interface PersistentCollection<E>
      Returns:
      true if the collection is dirty
    • isElementRemoved

      public boolean isElementRemoved()
      Specified by:
      isElementRemoved in interface PersistentCollection<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 interface PersistentCollection<E>
    • dirty

      public final void dirty()
      Description copied from interface: PersistentCollection
      Mark the collection as dirty
      Specified by:
      dirty in interface PersistentCollection<E>
    • getStoredSnapshot

      public final @Nullable Serializable getStoredSnapshot()
      Description copied from interface: PersistentCollection
      Get the snapshot cached by the collection instance
      Specified by:
      getStoredSnapshot in interface PersistentCollection<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 interface PersistentCollection<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 the Collection.size() method
    • getSize

      public int getSize()
      Description copied from interface: PersistentCollection
      Obtain the size of this collection without initializing it
      Specified by:
      getSize in interface PersistentCollection<E>
    • readIndexExistence

      protected Boolean readIndexExistence(Object index)
    • readElementExistence

      protected Boolean readElementExistence(Object element)
    • elementExists

      public boolean elementExists(Object element)
      Description copied from interface: PersistentCollection
      Determine if the given element belongs to this collection without initializing it
      Specified by:
      elementExists in interface PersistentCollection<E>
    • readElementByIndex

      protected Object readElementByIndex(Object index)
    • elementByIndex

      public Object elementByIndex(Object index)
      Description copied from interface: PersistentCollection
      Obtain the element os this collection associated with the given index without initializing it
      Specified by:
      elementByIndex in interface PersistentCollection<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 in copyCache.
      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: PersistentCollection
      After flushing, re-init snapshot state.
      Specified by:
      setSnapshot in interface PersistentCollection<E>
      Parameters:
      key - The collection instance key (fk value).
      role - The collection role
      snapshot - 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 interface PersistentCollection<E>
    • clearOperationQueue

      public final void clearOperationQueue()
    • getValue

      public Object getValue()
      Description copied from interface: PersistentCollection
      Return the user-visible collection (or array) instance
      Specified by:
      getValue in interface PersistentCollection<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 with PersistentCollection.endRead()
      Specified by:
      beginRead in interface PersistentCollection<E>
    • endRead

      public boolean endRead()
      Description copied from interface: PersistentCollection
      Called after reading all rows from the JDBC result set. Pairs with PersistentCollection.beginRead()
      Specified by:
      endRead in interface PersistentCollection<E>
      See Also:
    • beforeInitialize

      public void beforeInitialize(CollectionPersister persister, int anticipatedSize)
      Description copied from interface: PersistentCollection
      Called prior to the initialization of this yet-uninitialized collection. Pairs with PersistentCollection.afterInitialize()
      Specified by:
      beforeInitialize in interface PersistentCollection<E>
    • afterInitialize

      public boolean afterInitialize()
      Description copied from interface: PersistentCollection
      Called after initialization is complete. Pairs with PersistentCollection.beforeInitialize(CollectionPersister, int)
      Specified by:
      afterInitialize in interface PersistentCollection<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

      public static void checkPersister(PersistentCollection<?> collection, CollectionPersister persister)
    • 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 interface PersistentCollection<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 interface PersistentCollection<E>
      Returns:
      true indicates that the application might have access to the underlying collection/array.
    • unsetSession

      public final boolean unsetSession(SharedSessionContractImplementor currentSession)
      Description copied from interface: PersistentCollection
      Disassociate this collection from the given session.
      Specified by:
      unsetSession in interface PersistentCollection<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: PersistentCollection
      Associate the collection with the given session.
      Specified by:
      setCurrentSession in interface PersistentCollection<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: PersistentCollection
      Do we need to completely recreate this collection when it changes?
      Specified by:
      needsRecreate in interface PersistentCollection<E>
      Parameters:
      persister - The collection persister
      Returns:
      true if a change requires a recreate.
    • forceInitialization

      public final void forceInitialization() throws HibernateException
      Description copied from interface: LazyInitializable
      To be called internally by the session, forcing immediate initialization.
      Specified by:
      forceInitialization in interface LazyInitializable
      Throws:
      HibernateException
      See Also:
    • getSnapshot

      protected final Serializable 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 interface LazyInitializable
      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 interface PersistentCollection<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 interface PersistentCollection<E>
      Returns:
      true indicates there are pending, queued, delayed operations
    • queuedAdditionIterator

      public final Iterator<?> queuedAdditionIterator()
      Description copied from interface: PersistentCollection
      Iterator over the "queued" additions
      Specified by:
      queuedAdditionIterator in interface PersistentCollection<E>
      Returns:
      The iterator
    • getQueuedOrphans

      public final Collection<E> getQueuedOrphans(String entityName)
      Description copied from interface: PersistentCollection
      Get the "queued" orphans
      Specified by:
      getQueuedOrphans in interface PersistentCollection<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: PersistentCollection
      Called before inserting rows, to ensure that any surrogate keys are fully generated
      Specified by:
      preInsert in interface PersistentCollection<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 interface PersistentCollection<E>
      Parameters:
      persister - The collection persister
      entry - The collection element just inserted
      i - 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 interface PersistentCollection<E>
      Parameters:
      snapshot - The snapshot state
      entityName - The name of the entity that are the elements of the collection
      Returns:
      The orphans
      Throws:
      HibernateException
    • getSession

      public final SharedSessionContractImplementor getSession()
      Description copied from interface: PersistentCollection
      Get the session currently associated with this collection. Declared here for use by Hibernate Reactive.
      Specified by:
      getSession in interface PersistentCollection<E>
    • 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 instances
      entityInstance - The entity instance to match elements.
      entityName - The entity name
      session - The session
    • getIdentifier

      public Object getIdentifier(Object entry, int i)
      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 the idbag collection.
      Specified by:
      getIdentifier in interface PersistentCollection<E>
      Parameters:
      entry - The collection entry/element
      i - The assumed identifier (?)
      Returns:
      The identifier value
    • getOwner

      public @Nullable Object 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 interface PersistentCollection<E>
      Returns:
      The owner
    • setOwner

      public void setOwner(Object owner)
      Description copied from interface: PersistentCollection
      Set the reference to the owning entity
      Specified by:
      setOwner in interface PersistentCollection<E>
      Parameters:
      owner - The owner
    • $$_hibernate_getInstanceId

      public int $$_hibernate_getInstanceId()
      Description copied from interface: InstanceIdentity
      Retrieve the unique identifier of this instance
      Specified by:
      $$_hibernate_getInstanceId in interface InstanceIdentity
      Returns:
      the unique instance identifier
    • $$_hibernate_setInstanceId

      public void $$_hibernate_setInstanceId(int instanceId)
      Description copied from interface: InstanceIdentity
      Set the value of the unique identifier for this instance
      Specified by:
      $$_hibernate_setInstanceId in interface InstanceIdentity
      Parameters:
      instanceId - the unique identifier value to set