站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

Bag (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate.collection
Class Bag

java.lang.Object
  extended bynet.sf.hibernate.collection.PersistentCollection
      extended bynet.sf.hibernate.collection.ODMGCollection
          extended bynet.sf.hibernate.collection.Bag
All Implemented Interfaces:
Collection, org.odmg.DBag, org.odmg.DCollection, List, Serializable

public class Bag
extends ODMGCollection
implements org.odmg.DBag, 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
See Also:
Serialized Form

Constructor Summary
Bag()
           
Bag(SessionImplementor session)
           
Bag(SessionImplementor session, Collection coll)
           
 
Method Summary
 void add(int i, Object o)
           
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int i, Collection c)
           
 void beforeInitialize(CollectionPersister persister)
          Called before any elements are read into the collection, allowing appropriate initializations to occur.
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 void delayedAddAll(Collection c)
          After reading all existing elements from the database, add the queued elements to the underlying collection.
 org.odmg.DBag difference(org.odmg.DBag otherBag)
           
 Serializable disassemble(CollectionPersister persister)
          Disassemble the collection, ready for the cache
 boolean empty()
          Is the initialized collection empty?
 Iterator entries()
          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(Type elementType)
          Does the current state exactly match the snapshot?
 Object get(int i)
           
 Iterator getDeletes(Type elemType)
          Get all the elements that need deleting
 Object getIndex(Object entry, int i)
          Get the index of the given collection entry
 Collection getOrphans(Serializable snapshot)
          get all "orphaned" elements
 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
 org.odmg.DBag intersection(org.odmg.DBag otherBag)
           
 boolean isEmpty()
           
 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, 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()
           
protected  Serializable snapshot(CollectionPersister persister)
          Return a new snapshot of the current state
 List subList(int start, int end)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 String toString()
           
 org.odmg.DBag union(org.odmg.DBag otherBag)
           
 void writeTo(PreparedStatement st, CollectionPersister persister, Object entry, int i, boolean writeOrder)
          Write a row to the JDBC prepared statement
 
Methods inherited from class net.sf.hibernate.collection.ODMGCollection
existsElement, query, select, selectElement
 
Methods inherited from class net.sf.hibernate.collection.PersistentCollection
afterRowInsert, beginRead, endRead, forceInitialization, getCollectionSnapshot, getOrphans, getSession, getSnapshot, getSnapshot, getValue, hasQueuedAdditions, initialize, isDirectlyAccessible, postFlush, preInsert, queueAdd, queueAddAll, queuedAdditionIterator, read, setCollectionSnapshot, setCurrentSession, setDirectlyAccessible, setInitialized, unsetSession, wasInitialized, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.odmg.DCollection
existsElement, query, select, selectElement
 

Constructor Detail

Bag

public Bag(SessionImplementor session)

Bag

public Bag(SessionImplementor session,
           Collection coll)

Bag

public Bag()
Method Detail

isWrapper

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

Specified by:
isWrapper in class PersistentCollection

empty

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

Specified by:
empty in class PersistentCollection

entries

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

Specified by:
entries in class PersistentCollection
See Also:
PersistentCollection.entries()

readFrom

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

Specified by:
readFrom in class PersistentCollection
Throws:
HibernateException
SQLException
See Also:
PersistentCollection.readFrom(ResultSet, CollectionPersister, Object)

writeTo

public void writeTo(PreparedStatement st,
                    CollectionPersister persister,
                    Object entry,
                    int i,
                    boolean writeOrder)
             throws HibernateException,
                    SQLException
Description copied from class: PersistentCollection
Write a row to the JDBC prepared statement

Specified by:
writeTo in class PersistentCollection
Throws:
HibernateException
SQLException
See Also:
PersistentCollection.writeTo(PreparedStatement, CollectionPersister, Object, int, boolean)

beforeInitialize

public void beforeInitialize(CollectionPersister persister)
Description copied from class: PersistentCollection
Called before any elements are read into the collection, allowing appropriate initializations to occur.

Specified by:
beforeInitialize in class PersistentCollection
See Also:
PersistentCollection.beforeInitialize(CollectionPersister persister)

equalsSnapshot

public boolean equalsSnapshot(Type elementType)
                       throws HibernateException
Description copied from class: PersistentCollection
Does the current state exactly match the snapshot?

Specified by:
equalsSnapshot in class PersistentCollection
Throws:
HibernateException
See Also:
PersistentCollection.equalsSnapshot(Type elementType)

snapshot

protected Serializable snapshot(CollectionPersister persister)
                         throws HibernateException
Description copied from class: PersistentCollection
Return a new snapshot of the current state

Specified by:
snapshot in class PersistentCollection
Throws:
HibernateException
See Also:
PersistentCollection.snapshot(CollectionPersister persister)

getOrphans

public Collection getOrphans(Serializable snapshot)
                      throws HibernateException
Description copied from class: PersistentCollection
get all "orphaned" elements

Specified by:
getOrphans in class PersistentCollection
Throws:
HibernateException

disassemble

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

Specified by:
disassemble in class PersistentCollection
Throws:
HibernateException
See Also:
PersistentCollection.disassemble(CollectionPersister persister)

initializeFromCache

public void initializeFromCache(CollectionPersister persister,
                                Serializable disassembled,
                                Object owner)
                         throws HibernateException
Description copied from class: PersistentCollection
Read the state of the collection from a disassembled cached value

Specified by:
initializeFromCache in class PersistentCollection
Throws:
HibernateException

needsRecreate

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

Overrides:
needsRecreate in class PersistentCollection

getDeletes

public Iterator getDeletes(Type elemType)
                    throws HibernateException
Description copied from class: PersistentCollection
Get all the elements that need deleting

Specified by:
getDeletes in class PersistentCollection
Throws:
HibernateException

needsInserting

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

Specified by:
needsInserting in class PersistentCollection
Throws:
HibernateException

needsUpdating

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

Specified by:
needsUpdating in class PersistentCollection

size

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

isEmpty

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

contains

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

iterator

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

toArray

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

toArray

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

add

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

remove

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

containsAll

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

addAll

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

delayedAddAll

public void delayedAddAll(Collection c)
Description copied from class: PersistentCollection
After reading all existing elements from the database, add the queued elements to the underlying collection.

Overrides:
delayedAddAll in class PersistentCollection

removeAll

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

retainAll

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

clear

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

getIndex

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

Specified by:
getIndex in class PersistentCollection
See Also:
PersistentCollection.getIndex(Object, int)

difference

public org.odmg.DBag difference(org.odmg.DBag otherBag)
Specified by:
difference in interface org.odmg.DBag

intersection

public org.odmg.DBag intersection(org.odmg.DBag otherBag)
Specified by:
intersection in interface org.odmg.DBag

occurrences

public int occurrences(Object o)
Specified by:
occurrences in interface org.odmg.DBag

union

public org.odmg.DBag union(org.odmg.DBag otherBag)
Specified by:
union in interface org.odmg.DBag

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()

entryExists

public boolean entryExists(Object entry,
                           int i)
Description copied from class: PersistentCollection
Does an element exist at this entry in the collection?

Specified by:
entryExists in class PersistentCollection
See Also:
PersistentCollection.entryExists(java.lang.Object, int)

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
See Also:
Object.equals(java.lang.Object)

hashCode

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