org.hibernate.collection

Class PersistentBag

Implemented Interfaces:
List, Serializable, PersistentCollection

public class PersistentBag
extends AbstractPersistentCollection
implements List

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 Class Summary

Nested classes/interfaces inherited from class org.hibernate.collection.AbstractPersistentCollection

AbstractPersistentCollection.DelayedOperation

Field Summary

protected List
bag

Fields inherited from class org.hibernate.collection.AbstractPersistentCollection

UNKNOWN

Constructor Summary

PersistentBag()
Not called by Hibernate, but used by non-JDK serialization, eg.
PersistentBag(SessionImplementor session)
PersistentBag(SessionImplementor session, Collection coll)

Method Summary

boolean
add(Object object)
void
add(int i, Object o)
boolean
addAll(Collection values)
boolean
addAll(int i, Collection c)
void
beforeInitialize(CollectionPersister persister, int anticipatedSize)
Called before any elements are read into the collection, allowing appropriate initializations to occur.
void
clear()
boolean
contains(Object object)
boolean
containsAll(Collection c)
Serializable
disassemble(CollectionPersister persister)
Disassemble the collection, ready for the cache
boolean
empty()
Is the initialized collection empty?
Iterator
entries(CollectionPersister persister)
Iterate all collection entries, during update of the database
boolean
entryExists(Object entry, int i)
Does an element exist at this entry in the collection?
boolean
equals(Object obj)
Bag does not respect the collection API and do an JVM instance comparison to do the equals.
boolean
equalsSnapshot(CollectionPersister persister)
Does the current state exactly match the snapshot?
Object
get(int i)
Iterator
getDeletes(CollectionPersister persister, boolean indexIsFormula)
Get all the elements that need deleting
Object
getElement(Object entry)
Get the value of the given collection entry
Object
getIndex(Object entry, int i, CollectionPersister persister)
Get the index of the given collection entry
Collection
getOrphans(Serializable snapshot, String entityName)
get all "orphaned" elements
Serializable
getSnapshot(CollectionPersister persister)
Return a new snapshot of the current state of the collection
Object
getSnapshotElement(Object entry, int i)
Get the snapshot value of the given collection entry
int
hashCode()
int
indexOf(Object o)
void
initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
Read the state of the collection from a disassembled cached value
boolean
isEmpty()
boolean
isRowUpdatePossible()
boolean
isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?
boolean
isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance?
Iterator
iterator()
int
lastIndexOf(Object o)
ListIterator
listIterator()
ListIterator
listIterator(int i)
boolean
needsInserting(Object entry, int i, Type elemType)
Do we need to insert this element?
boolean
needsRecreate(CollectionPersister persister)
Do we need to completely recreate this collection when it changes?
boolean
needsUpdating(Object entry, int i, Type elemType)
Do we need to update this element?
int
occurrences(Object o)
Object
readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
Read a row from the JDBC result set
boolean
remove(Object o)
Object
remove(int i)
boolean
removeAll(Collection c)
boolean
retainAll(Collection c)
Object
set(int i, Object o)
int
size()
List
subList(int start, int end)
Object[]
toArray()
Object[]
toArray(Object[] a)
String
toString()

Methods inherited from class org.hibernate.collection.AbstractPersistentCollection

afterInitialize, afterRowInsert, beginRead, clearDirty, dirty, empty, endRead, forceInitialization, getCachedSize, getIdentifier, getKey, getOrphans, getOrphans, getOwner, getQueuedOrphans, getRole, getSession, getSnapshot, getStoredSnapshot, getValue, hasQueuedOperations, initialize, isClearQueueEnabled, isDirectlyAccessible, isDirty, isOperationQueueEnabled, isPutQueueEnabled, isRowUpdatePossible, isUnreferenced, needsRecreate, performQueuedOperations, postAction, preInsert, queueOperation, queuedAdditionIterator, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, write

Field Details

bag

protected List bag

Constructor Details

PersistentBag

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

PersistentBag

public PersistentBag(SessionImplementor session)

PersistentBag

public PersistentBag(SessionImplementor session,
                     Collection coll)

Method Details

add

public boolean add(Object object)
See Also:
java.util.Collection.add(Object)

add

public void add(int i,
                Object o)
See Also:
java.util.List.add(int, Object)

addAll

public boolean addAll(Collection values)
See Also:
java.util.Collection.addAll(Collection)

addAll

public boolean addAll(int i,
                      Collection c)
See Also:
java.util.List.addAll(int, Collection)

beforeInitialize

public void beforeInitialize(CollectionPersister persister,
                             int anticipatedSize)
Called before any elements are read into the collection, allowing appropriate initializations to occur.
Specified by:
beforeInitialize in interface PersistentCollection
Parameters:
persister - The underlying collection persister.
anticipatedSize - The anticipated size of the collection after initilization is complete.

clear

public void clear()
See Also:
java.util.Collection.clear()

contains

public boolean contains(Object object)
See Also:
java.util.Collection.contains(Object)

containsAll

public boolean containsAll(Collection c)
See Also:
java.util.Collection.containsAll(Collection)

disassemble

public Serializable disassemble(CollectionPersister persister)
            throws HibernateException
Disassemble the collection, ready for the cache
Specified by:
disassemble in interface PersistentCollection

empty

public boolean empty()
Is the initialized collection empty?
Specified by:
empty in interface PersistentCollection
Overrides:
empty in interface AbstractPersistentCollection

entries

public Iterator entries(CollectionPersister persister)
Iterate all collection entries, during update of the database
Specified by:
entries in interface PersistentCollection

entryExists

public boolean entryExists(Object entry,
                           int i)
Does an element exist at this entry in the collection?
Specified by:
entryExists in interface PersistentCollection

equals

public boolean equals(Object obj)
Bag does not respect the collection API and do an JVM instance comparison to do the equals. The semantic is broken not to have to initialize a collection for a simple equals() operation.
See Also:
java.lang.Object.equals(java.lang.Object)

equalsSnapshot

public boolean equalsSnapshot(CollectionPersister persister)
            throws HibernateException
Does the current state exactly match the snapshot?
Specified by:
equalsSnapshot in interface PersistentCollection

get

public Object get(int i)
See Also:
java.util.List.get(int)

getDeletes

public Iterator getDeletes(CollectionPersister persister,
                           boolean indexIsFormula)
            throws HibernateException
Get all the elements that need deleting
Specified by:
getDeletes in interface PersistentCollection

getElement

public Object getElement(Object entry)
Get the value of the given collection entry
Specified by:
getElement in interface PersistentCollection

getIndex

public Object getIndex(Object entry,
                       int i,
                       CollectionPersister persister)
Get the index of the given collection entry
Specified by:
getIndex in interface PersistentCollection
Parameters:
persister - it was more elegant before we added this...

getOrphans

public Collection getOrphans(Serializable snapshot,
                             String entityName)
            throws HibernateException
get all "orphaned" elements
Specified by:
getOrphans in interface PersistentCollection
Overrides:
getOrphans in interface AbstractPersistentCollection

getSnapshot

public Serializable getSnapshot(CollectionPersister persister)
            throws HibernateException
Return a new snapshot of the current state of the collection
Specified by:
getSnapshot in interface PersistentCollection

getSnapshotElement

public Object getSnapshotElement(Object entry,
                                 int i)
Get the snapshot value of the given collection entry
Specified by:
getSnapshotElement in interface PersistentCollection

hashCode

public int hashCode()
See Also:
java.lang.Object.hashCode()

indexOf

public int indexOf(Object o)
See Also:
java.util.List.indexOf(Object)

initializeFromCache

public void initializeFromCache(CollectionPersister persister,
                                Serializable disassembled,
                                Object owner)
            throws HibernateException
Read the state of the collection from a disassembled cached value
Specified by:
initializeFromCache in interface PersistentCollection

isEmpty

public boolean isEmpty()
See Also:
java.util.Collection.isEmpty()

isRowUpdatePossible

public boolean isRowUpdatePossible()
Specified by:
isRowUpdatePossible in interface PersistentCollection
Overrides:
isRowUpdatePossible in interface AbstractPersistentCollection

isSnapshotEmpty

public boolean isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?
Specified by:
isSnapshotEmpty in interface PersistentCollection

isWrapper

public boolean isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance?
Specified by:
isWrapper in interface PersistentCollection

iterator

public Iterator iterator()
See Also:
java.util.Collection.iterator()

lastIndexOf

public int lastIndexOf(Object o)
See Also:
java.util.List.lastIndexOf(Object)

listIterator

public ListIterator listIterator()
See Also:
java.util.List.listIterator()

listIterator

public ListIterator listIterator(int i)
See Also:
java.util.List.listIterator(int)

needsInserting

public boolean needsInserting(Object entry,
                              int i,
                              Type elemType)
            throws HibernateException
Do we need to insert this element?
Specified by:
needsInserting in interface PersistentCollection

needsRecreate

public boolean needsRecreate(CollectionPersister persister)
Do we need to completely recreate this collection when it changes?
Specified by:
needsRecreate in interface PersistentCollection
Overrides:
needsRecreate in interface AbstractPersistentCollection

needsUpdating

public boolean needsUpdating(Object entry,
                             int i,
                             Type elemType)
Do we need to update this element?
Specified by:
needsUpdating in interface PersistentCollection

occurrences

public int occurrences(Object o)

readFrom

public Object readFrom(ResultSet rs,
                       CollectionPersister persister,
                       CollectionAliases descriptor,
                       Object owner)
            throws HibernateException,
                   SQLException
Read a row from the JDBC result set
Specified by:
readFrom in interface PersistentCollection

remove

public boolean remove(Object o)
See Also:
java.util.Collection.remove(Object)

remove

public Object remove(int i)
See Also:
java.util.List.remove(int)

removeAll

public boolean removeAll(Collection c)
See Also:
java.util.Collection.removeAll(Collection)

retainAll

public boolean retainAll(Collection c)
See Also:
java.util.Collection.retainAll(Collection)

set

public Object set(int i,
                  Object o)
See Also:
java.util.List.set(int, Object)

size

public int size()
See Also:
java.util.Collection.size()

subList

public List subList(int start,
                    int end)
See Also:
java.util.List.subList(int, int)

toArray

public Object[] toArray()
See Also:
java.util.Collection.toArray()

toArray

public Object[] toArray(Object[] a)
See Also:
java.util.Collection.toArray(Object[])

toString

public String toString()