org.hibernate.collection.internal
Class PersistentBag

java.lang.Object
  extended by org.hibernate.collection.internal.AbstractPersistentCollection
      extended by org.hibernate.collection.internal.PersistentBag
All Implemented Interfaces:
Serializable, Iterable, Collection, List, 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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.hibernate.collection.internal.AbstractPersistentCollection
AbstractPersistentCollection.DelayedOperation, AbstractPersistentCollection.IteratorProxy, AbstractPersistentCollection.ListIteratorProxy, AbstractPersistentCollection.ListProxy, AbstractPersistentCollection.SetProxy
 
Field Summary
protected  List bag
           
 
Fields inherited from class org.hibernate.collection.internal.AbstractPersistentCollection
UNKNOWN
 
Constructor Summary
PersistentBag()
           
PersistentBag(SessionImplementor session)
           
PersistentBag(SessionImplementor session, Collection coll)
           
 
Method Summary
 void add(int i, Object o)
           
 boolean add(Object object)
           
 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
 Object remove(int i)
           
 boolean remove(Object o)
           
 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.internal.AbstractPersistentCollection
afterInitialize, afterRowInsert, beginRead, clearDirty, dirty, endRead, forceInitialization, getCachedSize, getIdentifier, getKey, getOrphans, getOwner, getQueuedOrphans, getRole, getSession, getSnapshot, getStoredSnapshot, getValue, hasQueuedOperations, identityRemove, initialize, isClearQueueEnabled, isDirectlyAccessible, isDirty, isOperationQueueEnabled, isPutQueueEnabled, isUnreferenced, performQueuedOperations, postAction, preInsert, queuedAdditionIterator, queueOperation, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

bag

protected List bag
Constructor Detail

PersistentBag

public PersistentBag(SessionImplementor session)

PersistentBag

public PersistentBag(SessionImplementor session,
                     Collection coll)

PersistentBag

public PersistentBag()
Method Detail

isWrapper

public boolean isWrapper(Object collection)
Description copied from interface: PersistentCollection
Is this the wrapper for the given underlying collection instance?

Specified by:
isWrapper in interface PersistentCollection

empty

public boolean empty()
Description copied from class: AbstractPersistentCollection
Is the initialized collection empty?

Specified by:
empty in interface PersistentCollection
Specified by:
empty in class AbstractPersistentCollection

entries

public Iterator entries(CollectionPersister persister)
Description copied from interface: PersistentCollection
Iterate all collection entries, during update of the database

Specified by:
entries in interface PersistentCollection

readFrom

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

Specified by:
readFrom in interface PersistentCollection
Throws:
HibernateException
SQLException

beforeInitialize

public void beforeInitialize(CollectionPersister persister,
                             int anticipatedSize)
Description copied from interface: PersistentCollection
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.

equalsSnapshot

public boolean equalsSnapshot(CollectionPersister persister)
                       throws HibernateException
Description copied from interface: PersistentCollection
Does the current state exactly match the snapshot?

Specified by:
equalsSnapshot in interface PersistentCollection
Throws:
HibernateException

isSnapshotEmpty

public boolean isSnapshotEmpty(Serializable snapshot)
Description copied from interface: PersistentCollection
Is the snapshot empty?

Specified by:
isSnapshotEmpty in interface PersistentCollection

getSnapshot

public Serializable getSnapshot(CollectionPersister persister)
                         throws HibernateException
Description copied from interface: PersistentCollection
Return a new snapshot of the current state of the collection

Specified by:
getSnapshot in interface PersistentCollection
Throws:
HibernateException

getOrphans

public Collection getOrphans(Serializable snapshot,
                             String entityName)
                      throws HibernateException
Description copied from class: AbstractPersistentCollection
get all "orphaned" elements

Specified by:
getOrphans in interface PersistentCollection
Specified by:
getOrphans in class AbstractPersistentCollection
Throws:
HibernateException

disassemble

public Serializable disassemble(CollectionPersister persister)
                         throws HibernateException
Description copied from interface: PersistentCollection
Disassemble the collection, ready for the cache

Specified by:
disassemble in interface PersistentCollection
Throws:
HibernateException

initializeFromCache

public void initializeFromCache(CollectionPersister persister,
                                Serializable 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 interface PersistentCollection
Throws:
HibernateException

needsRecreate

public boolean needsRecreate(CollectionPersister persister)
Description copied from class: AbstractPersistentCollection
Do we need to completely recreate this collection when it changes?

Specified by:
needsRecreate in interface PersistentCollection
Overrides:
needsRecreate in class AbstractPersistentCollection

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 interface PersistentCollection
Throws:
HibernateException

needsInserting

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

Specified by:
needsInserting in interface PersistentCollection
Throws:
HibernateException

isRowUpdatePossible

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

needsUpdating

public boolean needsUpdating(Object entry,
                             int i,
                             Type elemType)
Description copied from interface: PersistentCollection
Do we need to update this element?

Specified by:
needsUpdating in interface PersistentCollection

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List
See Also:
Collection.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List
See Also:
Collection.isEmpty()

contains

public boolean contains(Object object)
Specified by:
contains in interface Collection
Specified by:
contains in interface List
See Also:
Collection.contains(Object)

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
See Also:
Collection.iterator()

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
See Also:
Collection.toArray()

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
See Also:
Collection.toArray(Object[])

add

public boolean add(Object object)
Specified by:
add in interface Collection
Specified by:
add in interface List
See Also:
Collection.add(Object)

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List
See Also:
Collection.remove(Object)

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List
See Also:
Collection.containsAll(Collection)

addAll

public boolean addAll(Collection values)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
See Also:
Collection.addAll(Collection)

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
See Also:
Collection.removeAll(Collection)

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List
See Also:
Collection.retainAll(Collection)

clear

public void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List
See Also:
Collection.clear()

getIndex

public Object getIndex(Object entry,
                       int i,
                       CollectionPersister persister)
Description copied from interface: PersistentCollection
Get the index of the given collection entry

Specified by:
getIndex in interface PersistentCollection
persister - it was more elegant before we added this...

getElement

public Object getElement(Object entry)
Description copied from interface: PersistentCollection
Get the value of the given collection entry

Specified by:
getElement in interface PersistentCollection

getSnapshotElement

public Object getSnapshotElement(Object entry,
                                 int i)
Description copied from interface: PersistentCollection
Get the snapshot value of the given collection entry

Specified by:
getSnapshotElement in interface PersistentCollection

occurrences

public int occurrences(Object o)

add

public void add(int i,
                Object o)
Specified by:
add in interface List
See Also:
List.add(int, Object)

addAll

public boolean addAll(int i,
                      Collection c)
Specified by:
addAll in interface List
See Also:
List.addAll(int, Collection)

get

public Object get(int i)
Specified by:
get in interface List
See Also:
List.get(int)

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List
See Also:
List.indexOf(Object)

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List
See Also:
List.lastIndexOf(Object)

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List
See Also:
List.listIterator()

listIterator

public ListIterator listIterator(int i)
Specified by:
listIterator in interface List
See Also:
List.listIterator(int)

remove

public Object remove(int i)
Specified by:
remove in interface List
See Also:
List.remove(int)

set

public Object set(int i,
                  Object o)
Specified by:
set in interface List
See Also:
List.set(int, Object)

subList

public List subList(int start,
                    int end)
Specified by:
subList in interface List
See Also:
List.subList(int, int)

toString

public String toString()
Overrides:
toString in class Object

entryExists

public boolean entryExists(Object entry,
                           int i)
Description copied from interface: PersistentCollection
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.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class Object
See Also:
Object.hashCode()


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