Package org.hibernate.collection.spi
Class PersistentBag<E>
java.lang.Object
org.hibernate.collection.spi.AbstractPersistentCollection<E>
org.hibernate.collection.spi.PersistentBag<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,List<E>,SequencedCollection<E>,LazyInitializable,PersistentCollection<E>,InstanceIdentity
@Incubating
public class PersistentBag<E>
extends AbstractPersistentCollection<E>
implements List<E>
An unordered, un-keyed collection that can contain the same element
multiple times. The Java Collections Framework, curiously, has no
Bag interface. It is, however, common to use Lists
to represent a collection with bag semantics, so Hibernate follows
this practice.- 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 TypeFieldDescriptionDeprecated, for removal: This API element is subject to removal in a future version.protected Collection<E> The actual bag.Fields inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
elementRemoved, UNKNOWN -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a PersistentBag.Constructs a PersistentBagPersistentBag(SharedSessionContractImplementor session, Collection<E> coll) Constructs a PersistentBag -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int i, Collection<? extends E> c) booleanaddAll(Collection<? extends E> values) voidclear()booleanbooleancontainsAll(Collection<?> c) disassemble(CollectionPersister persister) Disassemble the collection to get it ready for the cachebooleanempty()Is the collection empty? (don't try to initialize the collection)entries(CollectionPersister persister) Iterate all collection entries, during update of the databasebooleanentryExists(Object entry, int i) Does the given element/entry exist in the collection?booleanFor efficiency, bag does not respect the semantics ofList.equals(Object)as specified by the supertypeList.booleanequalsSnapshot(CollectionPersister persister) Does the current state exactly match the snapshot?get(int i) Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) Get all the elements that need deletinggetElement(Object entry) Get the value 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 entrybooleanhasDeletes(CollectionPersister persister) Does this collection have any elements which must be deleted?inthashCode()intvoidinitializeEmptyCollection(CollectionPersister persister) voidinitializeFromCache(CollectionPersister collectionDescriptor, Object disassembled, Object owner) Read the state of the collection from a disassembled cached valuevoidinjectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState) Inject the state loaded for a collection instance.booleanisEmpty()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.booleanisSnapshotEmpty(Serializable snapshot) Is the snapshot empty?booleanIs this the wrapper for the given collection instance?iterator()intlistIterator(int i) booleanneedsInserting(Object entry, int i, Type elemType) Do we need to insert this element?booleanneedsRecreate(CollectionPersister persister) Do we need to completely recreate this collection when it changes?booleanneedsUpdating(Object entry, int i, Type elemType) Do we need to update this element?intCount how many times the given object occurs in the elementsremove(int i) booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()subList(int start, int end) Object[]toArray()<A> A[]toArray(A[] a) toString()Methods inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
$$_hibernate_getInstanceId, $$_hibernate_setInstanceId, afterInitialize, afterRowInsert, beforeInitialize, beginRead, checkPersister, clearDirty, clearOperationQueue, dirty, elementByIndex, elementExists, endRead, forceInitialization, getCachedSize, getIdentifier, 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, isUnreferenced, performQueuedOperations, postAction, preInsert, prepareForPossibleLoadingOutsideTransaction, queuedAdditionIterator, queueOperation, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, replaceQueuedOperationValues, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, writeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface org.hibernate.collection.spi.PersistentCollection
includeInInsert, includeInRecreate, isDirectlyProvidedCollection, isNewlyInstantiated, needsUpdating, render
-
Field Details
-
bag
Deprecated, for removal: This API element is subject to removal in a future version.UsebagAsList()orcollectioninstead. -
collection
-
-
Constructor Details
-
PersistentBag
public PersistentBag()Constructs a PersistentBag. Needed for SOAP libraries, etc
-
-
Method Details
-
bagAsList
-
isWrapper
Description copied from interface:PersistentCollectionIs this the wrapper for the given collection instance?- Specified by:
isWrapperin interfacePersistentCollection<E>- Parameters:
collection- The collection to check whether this is wrapping it- Returns:
trueif this is a wrapper around that given collection instance.
-
empty
public boolean empty()Description copied from interface:PersistentCollectionIs the collection empty? (don't try to initialize the collection)- Specified by:
emptyin interfacePersistentCollection<E>- Specified by:
emptyin classAbstractPersistentCollection<E>- Returns:
falseif the collection is non-empty;trueotherwise.
-
entries
Description copied from interface:PersistentCollectionIterate all collection entries, during update of the database- Specified by:
entriesin interfacePersistentCollection<E>- Parameters:
persister- The collection persister.- Returns:
- The iterator
-
injectLoadedState
Description copied from interface:PersistentCollectionInject the state loaded for a collection instance.- Specified by:
injectLoadedStatein interfacePersistentCollection<E>
-
equalsSnapshot
Description copied from interface:PersistentCollectionDoes the current state exactly match the snapshot?- Specified by:
equalsSnapshotin interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
trueif the current state and the snapshot state match.- Throws:
HibernateException
-
isSnapshotEmpty
Description copied from interface:PersistentCollectionIs the snapshot empty?- Specified by:
isSnapshotEmptyin interfacePersistentCollection<E>- Parameters:
snapshot- The snapshot to check- Returns:
trueif the given snapshot is empty
-
getSnapshot
Description copied from interface:PersistentCollectionReturn a new snapshot of the current state of the collection- Specified by:
getSnapshotin interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
- The snapshot
- Throws:
HibernateException
-
getOrphans
Description copied from interface:PersistentCollectionget all "orphaned" elements- Specified by:
getOrphansin interfacePersistentCollection<E>- Specified by:
getOrphansin 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:
initializeEmptyCollectionin interfacePersistentCollection<E>
-
disassemble
Description copied from interface:PersistentCollectionDisassemble the collection to get it ready for the cache- Specified by:
disassemblein interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
- The disassembled state
-
initializeFromCache
public void initializeFromCache(CollectionPersister collectionDescriptor, Object disassembled, Object owner) throws HibernateException Description copied from interface:PersistentCollectionRead the state of the collection from a disassembled cached value- Specified by:
initializeFromCachein interfacePersistentCollection<E>- Parameters:
collectionDescriptor- The collection persisterdisassembled- The disassembled cached stateowner- The collection owner- Throws:
HibernateException
-
needsRecreate
Description copied from interface:PersistentCollectionDo we need to completely recreate this collection when it changes?- Specified by:
needsRecreatein interfacePersistentCollection<E>- Overrides:
needsRecreatein classAbstractPersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
trueif a change requires a recreate.
-
getDeletes
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException Description copied from interface:PersistentCollectionGet all the elements that need deleting- Specified by:
getDeletesin 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
-
hasDeletes
Description copied from interface:PersistentCollectionDoes this collection have any elements which must be deleted?- Specified by:
hasDeletesin interfacePersistentCollection<E>- Parameters:
persister- The collection persister- Returns:
trueif elements were removed
-
needsInserting
Description copied from interface:PersistentCollectionDo we need to insert this element?- Specified by:
needsInsertingin interfacePersistentCollection<E>- Parameters:
entry- The collection element to checki- The index (for indexed collections)elemType- The type for the element- Returns:
trueif the element needs inserting- Throws:
HibernateException
-
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>- Overrides:
isRowUpdatePossiblein classAbstractPersistentCollection<E>- Returns:
trueif the row for each element is known
-
needsUpdating
Description copied from interface:PersistentCollectionDo we need to update this element?- Specified by:
needsUpdatingin interfacePersistentCollection<E>- Parameters:
entry- The collection element to checki- The index (for indexed collections)elemType- The type for the element- Returns:
trueif the element needs updating
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <A> A[] toArray(A[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
getIndex
Description copied from interface:PersistentCollectionGet the index of the given collection entry- Specified by:
getIndexin 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:PersistentCollectionGet 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:
getElementin 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:PersistentCollectionGet the snapshot value of the given collection entry- Specified by:
getSnapshotElementin interfacePersistentCollection<E>- Parameters:
entry- The entryi- The index- Returns:
- The snapshot state for that element
-
occurrences
Count how many times the given object occurs in the elements- Parameters:
o- The object to check- Returns:
- The number of occurrences.
-
add
-
addAll
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
remove
-
set
-
subList
-
entryExists
Description copied from interface:PersistentCollectionDoes the given element/entry exist in the collection?- Specified by:
entryExistsin interfacePersistentCollection<E>- Parameters:
entry- The object to check if it exists as a collection elementi- Unused- Returns:
trueif the given entry is a collection element
-
toString
-
equals
For efficiency, bag does not respect the semantics ofList.equals(Object)as specified by the supertypeList. Instead, instance equality is used, to avoid the need to fetch the elements of the bag. -
hashCode
public int hashCode()
-
bagAsList()orcollectioninstead.