Top Description Inners Fields Constructors Methods
org.hibernate.collection.internal

public Class PersistentBag

extends AbstractPersistentCollection
implements List
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Imports
java.io.Serializable, java.sql.ResultSet, .SQLException, java.util.ArrayList, .Collection, .Collections, .HashMap, .Iterator, .List, .ListIterator, .Map, org.hibernate.HibernateException, org.hibernate.engine.spi.SessionImplementor, .SharedSessionContractImplementor, org.hibernate.loader.CollectionAliases, org.hibernate.persister.collection.CollectionPersister, org.hibernate.type.Type

An unordered, unkeyed collection that can contain the same element multiple times. The Java collections API, curiously, has no Bag. Most developers seem to use Lists to represent bag semantics, so Hibernate follows this practice.
Author
Gavin King

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
protected List<E>
private Collection<E>
Inherited from org.hibernate.collection.internal.AbstractPersistentCollection:
elementRemovedUNKNOWN

Constructor Summary

AccessConstructor and Description
public
PersistentBag()

Constructs a PersistentBag.

public
PersistentBag(SharedSessionContractImplementor
The session
session
)

Constructs a PersistentBag

public
PersistentBag(SessionImplementor
The session
session
)

Deprecated PersistentBag(SharedSessionContractImplementor) should be used instead.
Constructs a PersistentBag
public
PersistentBag(SharedSessionContractImplementor
The session
session
,
Collection<E>
The base elements.
coll
)

Constructs a PersistentBag

public
PersistentBag(SessionImplementor
The session
session
,
Collection<E>
The base elements.
coll
)

Constructs a PersistentBag

Method Summary

Modifier and TypeMethod and Description
public boolean
add(Object
element to be appended to this list
object
)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).
public void
add(int
index at which the specified element is to be inserted
i
,
Object
element to be inserted
o
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(Collection<E>
collection containing elements to be added to this list
values
)

Implements java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
public boolean
addAll(int
index at which to insert the first element from the specified collection
i
,
Collection<E>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
public void
beforeInitialize(CollectionPersister
The underlying collection persister.
persister
,
int
The anticipated size of the collection after initialization is complete.
anticipatedSize
)

Implements org.hibernate.collection.spi.PersistentCollection.beforeInitialize.

Called before any elements are read into the collection, allowing appropriate initializations to occur.
public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).
public boolean
contains(Object
element whose presence in this list is to be tested
object
)

Implements java.util.List.contains.

Returns true if this list contains the specified element.
public boolean
containsAll(Collection<E>
collection to be checked for containment in this list
c
)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.
private int
countOccurrences(Object element, List<Object> list, Type elementType)

public Serializable
disassemble(CollectionPersister
The collection persister
persister
)

Implements org.hibernate.collection.spi.PersistentCollection.disassemble.

Disassemble the collection to get it ready for the cache
public boolean
public Iterator<E>
entries(CollectionPersister
The collection persister.
persister
)

Implements org.hibernate.collection.spi.PersistentCollection.entries.

Iterate all collection entries, during update of the database
public boolean
entryExists(Object
The object to check if it exists as a collection element
entry
,
int
Unused
i
)

Implements org.hibernate.collection.spi.PersistentCollection.entryExists.

Does the given element/entry exist in the collection?
public boolean
equals(Object
the object to be compared for equality with this list
obj
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals.

Bag does not respect the collection API and do an JVM instance comparison to do the equals.
public boolean
equalsSnapshot(CollectionPersister
The collection persister
persister
)

Implements org.hibernate.collection.spi.PersistentCollection.equalsSnapshot.

Does the current state exactly match the snapshot?
private boolean
expectOccurrences(Object element, List<Object> list, Type elementType, int expected)

public Object
get(int
index of the element to return
i
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
public Iterator<E>
getDeletes(CollectionPersister
The collection persister
persister
,
boolean
For indexed collections, tells whether the index is a formula (calculated value) mapping
indexIsFormula
)

Implements org.hibernate.collection.spi.PersistentCollection.getDeletes.

Get all the elements that need deleting
public Object
getElement(Object
The object instance for which to get the collection element instance.
entry
)

Implements org.hibernate.collection.spi.PersistentCollection.getElement.

Get the value of the given collection entry.
public Object
getIndex(Object
The collection entry/element
entry
,
int
The assumed index
i
,
CollectionPersister
it was more elegant before we added this...
persister
)

Implements org.hibernate.collection.spi.PersistentCollection.getIndex.

Get the index of the given collection entry
public Collection<E>
getOrphans(Serializable
The snapshot state
snapshot
,
String
The name of the entity that are the elements of the collection
entityName
)

Implements abstract org.hibernate.collection.internal.AbstractPersistentCollection.getOrphans.

Implements org.hibernate.collection.spi.PersistentCollection.getOrphans.

get all "orphaned" elements
public Serializable
getSnapshot(CollectionPersister
The collection persister
persister
)

Implements org.hibernate.collection.spi.PersistentCollection.getSnapshot.

Return a new snapshot of the current state of the collection
public Object
getSnapshotElement(Object
The entry
entry
,
int
The index
i
)

Implements org.hibernate.collection.spi.PersistentCollection.getSnapshotElement.

Get the snapshot value of the given collection entry
private Map<Integer, List<Object>>

Returns:

Map of "equality" hashCode to List of objects
groupByEqualityHash
(List<Object> searchedBag, Type elementType)

Groups items in searchedBag according to persistence "equality" as defined in Type.isSame and Type.getHashCode

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode.

Returns the hash code value for this list.
public int
indexOf(Object
element to search for
o
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public void
initializeFromCache(CollectionPersister
The collection persister
persister
,
Serializable
The disassembled cached state
disassembled
,
Object
The collection owner
owner
)

Implements org.hibernate.collection.spi.PersistentCollection.initializeFromCache.

Read the state of the collection from a disassembled cached value
public boolean
isDirectlyProvidedCollection(Object
The collection
collection
)

Overrides default org.hibernate.collection.spi.PersistentCollection.isDirectlyProvidedCollection.

Was collection provided directly to this PersistentCollection (i.e., provided as an argument to a constructor)?
public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.
public boolean
isRowUpdatePossible()

Overrides org.hibernate.collection.internal.AbstractPersistentCollection.isRowUpdatePossible.

Implements org.hibernate.collection.spi.PersistentCollection.isRowUpdatePossible.

Can each element in the collection be mapped unequivocally to a single row in the database?
public boolean
isSnapshotEmpty(Serializable
The snapshot to check
snapshot
)

Implements org.hibernate.collection.spi.PersistentCollection.isSnapshotEmpty.

Is the snapshot empty?
public boolean
isWrapper(Object
The collection to check whether this is wrapping it
collection
)

Implements org.hibernate.collection.spi.PersistentCollection.isWrapper.

Is this the wrapper for the given collection instance?
public Iterator<E>
iterator()

Implements java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.
public int
lastIndexOf(Object
element to search for
o
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<E>
listIterator(int
index of the first element to be returned from the list iterator (by a call to next)
i
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public boolean
needsInserting(Object
The collection element to check
entry
,
int
The index (for indexed collections)
i
,
Type
The type for the element
elemType
)

Implements org.hibernate.collection.spi.PersistentCollection.needsInserting.

Do we need to insert this element?
public boolean
needsRecreate(CollectionPersister
The collection persister
persister
)

Overrides org.hibernate.collection.internal.AbstractPersistentCollection.needsRecreate.

Implements org.hibernate.collection.spi.PersistentCollection.needsRecreate.

Do we need to completely recreate this collection when it changes?
public boolean
needsUpdating(Object
The collection element to check
entry
,
int
The index (for indexed collections)
i
,
Type
The type for the element
elemType
)

Implements org.hibernate.collection.spi.PersistentCollection.needsUpdating.

Do we need to update this element?
private Integer

Returns:

the default elementType hashcode of the object o, or null if the object is null
nullableHashCode
(Object o, Type elementType)

public int

Returns:

The number of occurrences.
occurrences
(Object
The object to check
o
)

Count how many times the given object occurs in the elements

public Object
readFrom(ResultSet
The JDBC ResultSet
rs
,
CollectionPersister
The collection role
persister
,
CollectionAliases
The aliases used for the columns making up the collection
descriptor
,
Object
The collection owner
owner
)

Implements org.hibernate.collection.spi.PersistentCollection.readFrom.

Read a row from the JDBC result set
public boolean
remove(Object
element to be removed from this list, if present
o
)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).
public Object
remove(int
the index of the element to be removed
i
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public boolean
removeAll(Collection<E>
collection containing elements to be removed from this list
c
)

Implements java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).
public boolean
retainAll(Collection<E>
collection containing elements to be retained in this list
c
)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).
public Object
set(int
index of the element to replace
i
,
Object
element to be stored at the specified position
o
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public int
size()

Implements java.util.List.size.

Returns the number of elements in this list.
public List<E>
subList(int
low endpoint (inclusive) of the subList
start
,
int
high endpoint (exclusive) of the subList
end
)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
public Object[]
toArray()

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).
public Object[]
toArray(Object[]
the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
a
)

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.hibernate.collection.internal.AbstractPersistentCollection:
afterInitializeafterRowInsertbeginReadclearDirtyclearOperationQueuedirtyendReadforceInitializationgetCachedSizegetIdentifiergetKeygetOrphansgetOwnergetQueuedOrphansgetRolegetSessiongetSnapshotgetStoredSnapshotgetValuehasQueuedOperationsidentityRemoveidentityRemoveinitializeisClearQueueEnabledisConnectedToSessionisDirectlyAccessibleisDirtyisElementRemovedisInitializedisInverseCollectionisInverseCollectionNoOrphanDeleteisInverseOneToManyOrNoOrphanDeleteisOperationQueueEnabledisPutQueueEnabledisUnreferencedperformQueuedOperationspostActionpreInsertprepareForPossibleLoadingOutsideTransactionqueuedAdditionIteratorqueueOperationreadreadElementByIndexreadElementExistencereadIndexExistencereadSizereplaceQueuedOperationValuessetCurrentSessionsetDirectlyAccessiblesetInitializedsetOwnersetSnapshotunsetSessionwasInitializedwrite