## org.hibernate.collection
Class AbstractPersistentCollection

    java.lang.Object
      org.hibernate.collection.AbstractPersistentCollection

All Implemented Interfaces:
  Serializable, PersistentCollection

Direct Known Subclasses:
  PersistentArrayHolder, PersistentBag, PersistentElementHolder, PersistentIdentifierBag, PersistentIndexedElementHolder, PersistentList, PersistentMap, PersistentSet

    public abstract class AbstractPersistentCollection

extends Object
implements Serializable, PersistentCollection

Base class implementing `PersistentCollection`

Author:
  Gavin King
See Also:
  Serialized Form

Nested Class Summary
`protected static interface` `AbstractPersistentCollection.DelayedOperation`

Field Summary
`protected static Object` `UNKNOWN`

Constructor Summary
`` `AbstractPersistentCollection()` Not called by Hibernate, but used by non-JDK serialization, eg.
`protected` `AbstractPersistentCollection(SessionImplementor session)`

Method Summary
`boolean` `afterInitialize()` Called after initializing from cache
`void` `afterRowInsert(CollectionPersister persister, Object entry, int i)` Called after inserting a row, to fetch the natively generated id
`void` `beginRead()` Called just before reading any rows from the JDBC result set
`void` `clearDirty()` Clear the dirty flag, after flushing changes to the database.
`void` `dirty()` Mark the collection as dirty
`abstract boolean` `empty()` Is the initialized collection empty?
`boolean` `endRead()` Called after reading all rows from the JDBC result set
`void` `forceInitialization()` To be called internally by the session, forcing immediate initialization.
`protected int` `getCachedSize()`
`Object` `getIdentifier(Object entry, int i)` Get the index of the given collection entry
`Serializable` `getKey()` Get the current collection key value
`protected static Collection` `getOrphans(Collection oldElements, Collection currentElements, String entityName, SessionImplementor 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
`abstract Collection` `getOrphans(Serializable snapshot, String entityName)` get all "orphaned" elements
`Object` `getOwner()` Get the owning entity.
`Collection` `getQueuedOrphans(String entityName)` Iterate the "queued" additions
`String` `getRole()` Get the current role name
`SessionImplementor` `getSession()` Get the current session
`protected Serializable` `getSnapshot()` Get the current snapshot from the session
`Serializable` `getStoredSnapshot()` Get the snapshot cached by the collection instance
`Object` `getValue()` return the user-visible collection (or array) instance
`boolean` `hasQueuedOperations()` Does this instance have any "queued" additions?
`protected void` `initialize(boolean writing)` Initialize the collection, if possible, wrapping any exceptions in a runtime exception
`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.
`boolean` `isDirectlyAccessible()` Could the application possibly have a direct reference to the underlying collection implementation?
`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.
`protected boolean` `isOperationQueueEnabled()` Is this collection in a state that would allow us to "queue" operations?
`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.
`boolean` `isRowUpdatePossible()`
`boolean` `isUnreferenced()` Is the collection unreferenced?
`boolean` `needsRecreate(CollectionPersister persister)` Do we need to completely recreate this collection when it changes?
`protected void` `performQueuedOperations()` After reading all existing elements from the database, add the queued elements to the underlying collection.
`void` `postAction()` 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 generated
`Iterator` `queuedAdditionIterator()` Iterate the "queued" additions
`protected void` `queueOperation(Object element)` Queue an addition
`protected void` `read()` Called by any read-only method of the collection interface
`protected Object` `readElementByIndex(Object index)`
`protected Boolean` `readElementExistence(Object element)`
`protected Boolean` `readIndexExistence(Object index)`
`protected boolean` `readSize()` Called by the `size()` method
`boolean` `setCurrentSession(SessionImplementor session)` Associate the collection with the given session.
`protected void` `setDirectlyAccessible(boolean directlyAccessible)`
`protected void` `setInitialized()`
`void` `setOwner(Object owner)` Set the reference to the owning entity
`void` `setSnapshot(Serializable key, String role, Serializable snapshot)` After flushing, re-init snapshot state.
`boolean` `unsetSession(SessionImplementor currentSession)` Disassociate this collection from the given session.
`boolean` `wasInitialized()` Is this instance initialized?
`protected void` `write()` 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.PersistentCollection
`beforeInitialize, disassemble, entries, entryExists, equalsSnapshot, getDeletes, getElement, getIndex, getSnapshot, getSnapshotElement, initializeFromCache, isSnapshotEmpty, isWrapper, needsInserting, needsUpdating, readFrom`

Field Detail

### 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(SessionImplementor session)

Method Detail

### getRole

    public final String getRole()

  Description copied from interface: `PersistentCollection`
  Get the current role name

  Specified by:
    `getRole` in interface `PersistentCollection`

### getKey

    public final Serializable getKey()

  Description copied from interface: `PersistentCollection`
  Get the current collection key value

  Specified by:
    `getKey` in interface `PersistentCollection`

### isUnreferenced

    public final boolean isUnreferenced()

  Description copied from interface: `PersistentCollection`
  Is the collection unreferenced?

  Specified by:
    `isUnreferenced` in interface `PersistentCollection`

### 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`

### 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`

### dirty

    public final void dirty()

  Description copied from interface: `PersistentCollection`
  Mark the collection as dirty

  Specified by:
    `dirty` in interface `PersistentCollection`

### getStoredSnapshot

    public final Serializable getStoredSnapshot()

  Description copied from interface: `PersistentCollection`
  Get the snapshot cached by the collection instance

  Specified by:
    `getStoredSnapshot` in interface `PersistentCollection`

### empty

    public abstract boolean empty()

  Is the initialized collection empty?

  Specified by:
    `empty` in interface `PersistentCollection`

### read

    protected final void read()

  Called by any read-only method of the collection interface

### readSize

    protected boolean readSize()

  Called by the `size()` method

### readIndexExistence

    protected Boolean readIndexExistence(Object index)

### readElementExistence

    protected Boolean readElementExistence(Object element)

### readElementByIndex

    protected Object readElementByIndex(Object index)

### getCachedSize

    protected int getCachedSize()

### 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.

### queueOperation

    protected final void queueOperation(Object element)

  Queue an addition

### 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(Serializable key,
                            String role,
                            Serializable snapshot)

  After flushing, re-init snapshot state.

  Specified by:
    `setSnapshot` in interface `PersistentCollection`

### postAction

    public void postAction()

  After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.

  Specified by:
    `postAction` in interface `PersistentCollection`

### getValue

    public Object getValue()

  return the user-visible collection (or array) instance

  Specified by:
    `getValue` in interface `PersistentCollection`

### beginRead

    public void beginRead()

  Called just before reading any rows from the JDBC result set

  Specified by:
    `beginRead` in interface `PersistentCollection`

### endRead

    public boolean endRead()

  Called after reading all rows from the JDBC result set

  Specified by:
    `endRead` in interface `PersistentCollection`

### afterInitialize

    public boolean afterInitialize()

  Description copied from interface: `PersistentCollection`
  Called after initializing from cache

  Specified by:
    `afterInitialize` in interface `PersistentCollection`

### 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()

### setDirectlyAccessible

    protected final void setDirectlyAccessible(boolean directlyAccessible)

### isDirectlyAccessible

    public boolean isDirectlyAccessible()

  Could the application possibly have a direct reference to the underlying collection implementation?

  Specified by:
    `isDirectlyAccessible` in interface `PersistentCollection`

### unsetSession

    public final boolean unsetSession(SessionImplementor currentSession)

  Disassociate this collection from the given session.

  Specified by:
    `unsetSession` in interface `PersistentCollection`
  Returns:
    true if this was currently associated with the given session

### setCurrentSession

    public final boolean setCurrentSession(SessionImplementor session)
                                    throws HibernateException

  Associate the collection with the given session.

  Specified by:
    `setCurrentSession` in interface `PersistentCollection`
  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)

  Do we need to completely recreate this collection when it changes?

  Specified by:
    `needsRecreate` in interface `PersistentCollection`

### forceInitialization

    public final void forceInitialization()
                                   throws HibernateException

  To be called internally by the session, forcing immediate initialization.

  Specified by:
    `forceInitialization` in interface `PersistentCollection`
  Throws:
    `HibernateException`

### getSnapshot

    protected final Serializable getSnapshot()

  Get the current snapshot from the session

### wasInitialized

    public final boolean wasInitialized()

  Is this instance initialized?

  Specified by:
    `wasInitialized` in interface `PersistentCollection`

### isRowUpdatePossible

    public boolean isRowUpdatePossible()

  Specified by:
    `isRowUpdatePossible` in interface `PersistentCollection`

### hasQueuedOperations

    public final boolean hasQueuedOperations()

  Does this instance have any "queued" additions?

  Specified by:
    `hasQueuedOperations` in interface `PersistentCollection`

### queuedAdditionIterator

    public final Iterator queuedAdditionIterator()

  Iterate the "queued" additions

  Specified by:
    `queuedAdditionIterator` in interface `PersistentCollection`

### getQueuedOrphans

    public final Collection getQueuedOrphans(String entityName)

  Iterate the "queued" additions

  Specified by:
    `getQueuedOrphans` in interface `PersistentCollection`

### preInsert

    public void preInsert(CollectionPersister persister)
                   throws HibernateException

  Called before inserting rows, to ensure that any surrogate keys are fully generated

  Specified by:
    `preInsert` in interface `PersistentCollection`
  Throws:
    `HibernateException`

### afterRowInsert

    public void afterRowInsert(CollectionPersister persister,
                               Object entry,
                               int i)
                        throws HibernateException

  Called after inserting a row, to fetch the natively generated id

  Specified by:
    `afterRowInsert` in interface `PersistentCollection`
  Throws:
    `HibernateException`

### getOrphans

    public abstract Collection getOrphans(Serializable snapshot,
                                          String entityName)
                                   throws HibernateException

  get all "orphaned" elements

  Specified by:
    `getOrphans` in interface `PersistentCollection`
  Throws:
    `HibernateException`

### getSession

    public final SessionImplementor getSession()

  Get the current session

### getOrphans

    protected static Collection getOrphans(Collection oldElements,
                                           Collection currentElements,
                                           String entityName,
                                           SessionImplementor 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`

### getIdentifier

    public Object getIdentifier(Object entry,
                                int i)

  Description copied from interface: `PersistentCollection`
  Get the index of the given collection entry

  Specified by:
    `getIdentifier` in interface `PersistentCollection`

### getOwner

    public 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`

### setOwner

    public void setOwner(Object owner)

  Description copied from interface: `PersistentCollection`
  Set the reference to the owning entity

  Specified by:
    `setOwner` in interface `PersistentCollection`

Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.