Package org.hibernate.collection.spi
Class PersistentIdentifierBag<E>
java.lang.Object
org.hibernate.collection.spi.AbstractPersistentCollection<E>
org.hibernate.collection.spi.PersistentIdentifierBag<E>
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,List<E>
,LazyInitializable
,PersistentCollection<E>
@Incubating
public class PersistentIdentifierBag<E>
extends AbstractPersistentCollection<E>
implements List<E>
An "identifier bag" implements "bag" semantics more efficiently than a
regular bag by adding a synthetic identifier column to the table. This
identifier is unique over all rows in the table, allowing very efficient
updates and deletes. The value of the identifier is never exposed to the
application.
Identifier bags may not be used for a many-to-one association.
Furthermore, there is no reason to use inverse="true"
.
- See Also:
- API Note:
- Incubating in terms of making this non-internal. These contracts will be getting cleaned up in following releases.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
AbstractPersistentCollection.AbstractValueDelayedOperation, AbstractPersistentCollection.DelayedOperation<E>, AbstractPersistentCollection.IteratorProxy<E>, AbstractPersistentCollection.LazyInitializationWork<T>, AbstractPersistentCollection.ListIteratorProxy, AbstractPersistentCollection.ListProxy, AbstractPersistentCollection.SetProxy<E>, AbstractPersistentCollection.ValueDelayedOperation<E>
-
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
elementRemoved, UNKNOWN
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a PersistentIdentifierBag.Constructs a PersistentIdentifierBag.PersistentIdentifierBag
(SharedSessionContractImplementor session, Collection<E> coll) Constructs a PersistentIdentifierBag. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) void
afterRowInsert
(CollectionPersister persister, Object entry, int i) Called after inserting a row, to fetch the natively generated idvoid
clear()
boolean
boolean
containsAll
(Collection<?> c) disassemble
(CollectionPersister persister) Disassemble the collection to get it ready for the cacheboolean
empty()
Is the collection empty? (don't try to initialize the collection)entries
(CollectionPersister persister) Iterate all collection entries, during update of the databaseboolean
entryExists
(Object entry, int i) Does the given element/entry exist in the collection?boolean
equalsSnapshot
(CollectionPersister persister) Does the current state exactly match the snapshot?get
(int index) Iterator<?>
getDeletes
(CollectionPersister persister, boolean indexIsFormula) Get all the elements that need deletinggetElement
(Object entry) Get the value of the given collection entry.getIdentifier
(Object entry, int i) Get the identifier of the given collection entry.getIndex
(Object entry, int i, CollectionPersister persister) Get the index of the given collection entrygetOrphans
(Serializable snapshot, String entityName) get all "orphaned" elementsgetSnapshot
(CollectionPersister persister) Return a new snapshot of the current state of the collectiongetSnapshotElement
(Object entry, int i) Get the snapshot value of the given collection entryint
void
initializeEmptyCollection
(CollectionPersister persister) void
initializeFromCache
(CollectionPersister persister, Object disassembled, Object owner) Read the state of the collection from a disassembled cached valuevoid
injectLoadedState
(PluralAttributeMapping attributeMapping, List<?> loadingState) Inject the state loaded for a collection instance.boolean
isDirectlyProvidedCollection
(Object collection) Wascollection
provided directly to this PersistentCollection (i.e., provided as an argument to a constructor)?boolean
isEmpty()
boolean
isSnapshotEmpty
(Serializable snapshot) Is the snapshot empty?boolean
Is this the wrapper for the given collection instance?iterator()
int
listIterator
(int index) boolean
needsInserting
(Object entry, int i, Type elemType) Do we need to insert this element?boolean
needsUpdating
(Object entry, int i, Type elemType) Do we need to update this element?void
preInsert
(CollectionPersister persister) Called before inserting rows, to ensure that any surrogate keys are fully generatedremove
(int index) boolean
boolean
boolean
retainAll
(Collection<?> c) int
size()
subList
(int fromIndex, int toIndex) Object[]
toArray()
<A> A[]
toArray
(A[] a) Methods inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
afterInitialize, beforeInitialize, beginRead, clearDirty, clearOperationQueue, dirty, elementByIndex, elementExists, endRead, forceInitialization, getCachedSize, getKey, getOrphans, getOwner, getQueuedOrphans, getRole, getSession, getSize, getSnapshot, getStoredSnapshot, getValue, hasQueuedOperations, identityRemove, initialize, isClearQueueEnabled, isConnectedToSession, isDirectlyAccessible, isDirty, isElementRemoved, isInitialized, isInitializing, isInverseCollection, isInverseCollectionNoOrphanDelete, isInverseOneToManyOrNoOrphanDelete, isOperationQueueEnabled, isPutQueueEnabled, isRowUpdatePossible, isUnreferenced, needsRecreate, performQueuedOperations, postAction, prepareForPossibleLoadingOutsideTransaction, queuedAdditionIterator, queueOperation, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, replaceQueuedOperationValues, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
Methods inherited from interface org.hibernate.collection.spi.PersistentCollection
includeInInsert, includeInRecreate, isNewlyInstantiated, needsUpdating, render
-
Field Details
-
values
-
identifiers
-
-
Constructor Details
-
PersistentIdentifierBag
public PersistentIdentifierBag()Constructs a PersistentIdentifierBag. This form needed for SOAP libraries, etc
-
-
Method Details
-
initializeFromCache
public void initializeFromCache(CollectionPersister persister, Object disassembled, Object owner) throws HibernateException Description copied from interface:PersistentCollection
Read the state of the collection from a disassembled cached value- Specified by:
initializeFromCache
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persisterdisassembled
- The disassembled cached stateowner
- The collection owner- Throws:
HibernateException
-
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>
- Overrides:
getIdentifier
in classAbstractPersistentCollection<E>
- Parameters:
entry
- The collection entry/elementi
- The assumed identifier (?)- Returns:
- The identifier value
-
isWrapper
Description copied from interface:PersistentCollection
Is this the wrapper for the given collection instance?- Specified by:
isWrapper
in interfacePersistentCollection<E>
- Parameters:
collection
- The collection to check whether this is wrapping it- Returns:
true
if this is a wrapper around that given collection instance.
-
isDirectlyProvidedCollection
Description copied from interface:PersistentCollection
Wascollection
provided directly to this PersistentCollection (i.e., provided as an argument to a constructor)?Implementors that can copy elements out of a directly provided collection into the wrapped collection should override this method.
- Specified by:
isDirectlyProvidedCollection
in interfacePersistentCollection<E>
- Parameters:
collection
- The collection- Returns:
- true, if
collection
was provided directly to this PersistentCollection; false, otherwise.
-
add
-
clear
public void clear() -
contains
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
-
isEmpty
public boolean isEmpty() -
iterator
-
remove
-
removeAll
-
retainAll
-
size
public int size() -
toArray
-
toArray
public <A> A[] toArray(A[] a) -
disassemble
Description copied from interface:PersistentCollection
Disassemble the collection to get it ready for the cache- Specified by:
disassemble
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persister- Returns:
- The disassembled state
-
empty
public boolean empty()Description copied from interface:PersistentCollection
Is the collection empty? (don't try to initialize the collection)- Specified by:
empty
in interfacePersistentCollection<E>
- Specified by:
empty
in classAbstractPersistentCollection<E>
- Returns:
false
if the collection is non-empty;true
otherwise.
-
entries
Description copied from interface:PersistentCollection
Iterate all collection entries, during update of the database- Specified by:
entries
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persister.- Returns:
- The iterator
-
entryExists
Description copied from interface:PersistentCollection
Does the given element/entry exist in the collection?- Specified by:
entryExists
in interfacePersistentCollection<E>
- Parameters:
entry
- The object to check if it exists as a collection elementi
- Unused- Returns:
true
if the given entry is a collection element
-
equalsSnapshot
Description copied from interface:PersistentCollection
Does the current state exactly match the snapshot?- Specified by:
equalsSnapshot
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persister- Returns:
true
if the current state and the snapshot state match.- Throws:
HibernateException
-
isSnapshotEmpty
Description copied from interface:PersistentCollection
Is the snapshot empty?- Specified by:
isSnapshotEmpty
in interfacePersistentCollection<E>
- Parameters:
snapshot
- The snapshot to check- Returns:
true
if the given snapshot is empty
-
getDeletes
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException Description copied from interface:PersistentCollection
Get all the elements that need deleting- Specified by:
getDeletes
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persisterindexIsFormula
- For indexed collections, tells whether the index is a formula (calculated value) mapping- Returns:
- An iterator over the elements to delete
- Throws:
HibernateException
-
getIndex
Description copied from interface:PersistentCollection
Get the index of the given collection entry- Specified by:
getIndex
in interfacePersistentCollection<E>
- Parameters:
entry
- The collection entry/elementi
- The assumed indexpersister
- it was more elegant before we added this...- Returns:
- The index value
-
getElement
Description copied from interface:PersistentCollection
Get the value of the given collection entry. Generally the given entry parameter value will just be returned. Might get a different value for a duplicate entries in a Set.- Specified by:
getElement
in interfacePersistentCollection<E>
- Parameters:
entry
- The object instance for which to get the collection element instance.- Returns:
- The corresponding object that is part of the collection elements.
-
getSnapshotElement
Description copied from interface:PersistentCollection
Get the snapshot value of the given collection entry- Specified by:
getSnapshotElement
in interfacePersistentCollection<E>
- Parameters:
entry
- The entryi
- The index- Returns:
- The snapshot state for that element
-
needsInserting
Description copied from interface:PersistentCollection
Do we need to insert this element?- Specified by:
needsInserting
in interfacePersistentCollection<E>
- Parameters:
entry
- The collection element to checki
- The index (for indexed collections)elemType
- The type for the element- Returns:
true
if the element needs inserting- Throws:
HibernateException
-
needsUpdating
Description copied from interface:PersistentCollection
Do we need to update this element?- Specified by:
needsUpdating
in interfacePersistentCollection<E>
- Parameters:
entry
- The collection element to checki
- The index (for indexed collections)elemType
- The type for the element- Returns:
true
if the element needs updating- Throws:
HibernateException
-
getSnapshot
Description copied from interface:PersistentCollection
Return a new snapshot of the current state of the collection- Specified by:
getSnapshot
in interfacePersistentCollection<E>
- Parameters:
persister
- The collection persister- Returns:
- The snapshot
- Throws:
HibernateException
-
getOrphans
Description copied from interface:PersistentCollection
get all "orphaned" elements- Specified by:
getOrphans
in interfacePersistentCollection<E>
- Specified by:
getOrphans
in classAbstractPersistentCollection<E>
- Parameters:
snapshot
- The snapshot stateentityName
- The name of the entity that are the elements of the collection- Returns:
- The orphans
- Throws:
HibernateException
-
initializeEmptyCollection
- Specified by:
initializeEmptyCollection
in interfacePersistentCollection<E>
-
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>
- Overrides:
preInsert
in classAbstractPersistentCollection<E>
- Parameters:
persister
- The collection persister- Throws:
HibernateException
-
add
-
addAll
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
remove
-
set
-
subList
-
addAll
-
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>
- Overrides:
afterRowInsert
in classAbstractPersistentCollection<E>
- Parameters:
persister
- The collection persisterentry
- The collection element just insertedi
- The element position/index- Throws:
HibernateException
-
injectLoadedState
Description copied from interface:PersistentCollection
Inject the state loaded for a collection instance.- Specified by:
injectLoadedState
in interfacePersistentCollection<E>
-