| Method from org.hibernate.collection.PersistentBag Detail: |
public boolean add(Object object) {
if ( !isOperationQueueEnabled() ) {
write();
return bag.add(object);
}
else {
queueOperation( new SimpleAdd(object) );
return true;
}
}
|
public void add(int i,
Object o) {
write();
bag.add(i, o);
}
|
public boolean addAll(Collection values) {
if ( values.size()==0 ) return false;
if ( !isOperationQueueEnabled() ) {
write();
return bag.addAll(values);
}
else {
Iterator iter = values.iterator();
while ( iter.hasNext() ) {
queueOperation( new SimpleAdd( iter.next() ) );
}
return values.size() >0;
}
}
|
public boolean addAll(int i,
Collection c) {
if ( c.size() >0 ) {
write();
return bag.addAll(i, c);
}
else {
return false;
}
}
|
public void beforeInitialize(CollectionPersister persister,
int anticipatedSize) {
this.bag = ( List ) persister.getCollectionType().instantiate( anticipatedSize );
}
|
public void clear() {
if ( isClearQueueEnabled() ) {
queueOperation( new Clear() );
}
else {
initialize( true );
if ( ! bag.isEmpty() ) {
bag.clear();
dirty();
}
}
}
|
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
return exists==null ?
bag.contains(object) :
exists.booleanValue();
}
|
public boolean containsAll(Collection c) {
read();
return bag.containsAll(c);
}
|
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
int length = bag.size();
Serializable[] result = new Serializable[length];
for ( int i=0; i< length; i++ ) {
result[i] = persister.getElementType().disassemble( bag.get(i), getSession(), null );
}
return result;
}
|
public boolean empty() {
return bag.isEmpty();
}
|
public Iterator entries(CollectionPersister persister) {
return bag.iterator();
}
|
public boolean entryExists(Object entry,
int i) {
return entry!=null;
}
|
public boolean equals(Object obj) {
return super.equals(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. |
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
Type elementType = persister.getElementType();
EntityMode entityMode = getSession().getEntityMode();
List sn = (List) getSnapshot();
if ( sn.size()!=bag.size() ) return false;
Iterator iter = bag.iterator();
while ( iter.hasNext() ) {
Object elt = iter.next();
final boolean unequal = countOccurrences(elt, bag, elementType, entityMode) !=
countOccurrences(elt, sn, elementType, entityMode);
if ( unequal ) return false;
}
return true;
}
|
public Object get(int i) {
read();
return bag.get(i);
}
|
public Iterator getDeletes(CollectionPersister persister,
boolean indexIsFormula) throws HibernateException {
//if ( !persister.isOneToMany() ) throw new AssertionFailure("Not implemented for Bags");
Type elementType = persister.getElementType();
EntityMode entityMode = getSession().getEntityMode();
ArrayList deletes = new ArrayList();
List sn = (List) getSnapshot();
Iterator olditer = sn.iterator();
int i=0;
while ( olditer.hasNext() ) {
Object old = olditer.next();
Iterator newiter = bag.iterator();
boolean found = false;
if ( bag.size() >i && elementType.isSame( old, bag.get(i++), entityMode ) ) {
//a shortcut if its location didn't change!
found = true;
}
else {
//search for it
//note that this code is incorrect for other than one-to-many
while ( newiter.hasNext() ) {
if ( elementType.isSame( old, newiter.next(), entityMode ) ) {
found = true;
break;
}
}
}
if (!found) deletes.add(old);
}
return deletes.iterator();
}
|
public Object getElement(Object entry) {
return entry;
}
|
public Object getIndex(Object entry,
int i,
CollectionPersister persister) {
throw new UnsupportedOperationException("Bags don't have indexes");
}
|
public Collection getOrphans(Serializable snapshot,
String entityName) throws HibernateException {
List sn = (List) snapshot;
return getOrphans( sn, bag, entityName, getSession() );
}
|
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
EntityMode entityMode = getSession().getEntityMode();
ArrayList clonedList = new ArrayList( bag.size() );
Iterator iter = bag.iterator();
while ( iter.hasNext() ) {
clonedList.add( persister.getElementType().deepCopy( iter.next(), entityMode, persister.getFactory() ) );
}
return clonedList;
}
|
public Object getSnapshotElement(Object entry,
int i) {
List sn = (List) getSnapshot();
return sn.get(i);
}
|
public int hashCode() {
return super.hashCode();
}
|
public int indexOf(Object o) {
read();
return bag.indexOf(o);
}
|
public void initializeFromCache(CollectionPersister persister,
Serializable disassembled,
Object owner) throws HibernateException {
Serializable[] array = (Serializable[]) disassembled;
int size = array.length;
beforeInitialize( persister, size );
for ( int i = 0; i < size; i++ ) {
Object element = persister.getElementType().assemble( array[i], getSession(), owner );
if ( element!=null ) {
bag.add( element );
}
}
}
|
public boolean isEmpty() {
return readSize() ? getCachedSize()==0 : bag.isEmpty();
}
|
public boolean isRowUpdatePossible() {
return false;
}
|
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
|
public boolean isWrapper(Object collection) {
return bag==collection;
}
|
public Iterator iterator() {
read();
return new IteratorProxy( bag.iterator() );
}
|
public int lastIndexOf(Object o) {
read();
return bag.lastIndexOf(o);
}
|
public ListIterator listIterator() {
read();
return new ListIteratorProxy( bag.listIterator() );
}
|
public ListIterator listIterator(int i) {
read();
return new ListIteratorProxy( bag.listIterator(i) );
}
|
public boolean needsInserting(Object entry,
int i,
Type elemType) throws HibernateException {
//if ( !persister.isOneToMany() ) throw new AssertionFailure("Not implemented for Bags");
List sn = (List) getSnapshot();
final EntityMode entityMode = getSession().getEntityMode();
if ( sn.size() >i && elemType.isSame( sn.get(i), entry, entityMode ) ) {
//a shortcut if its location didn't change!
return false;
}
else {
//search for it
//note that this code is incorrect for other than one-to-many
Iterator olditer = sn.iterator();
while ( olditer.hasNext() ) {
Object old = olditer.next();
if ( elemType.isSame( old, entry, entityMode ) ) return false;
}
return true;
}
}
|
public boolean needsRecreate(CollectionPersister persister) {
return !persister.isOneToMany();
}
|
public boolean needsUpdating(Object entry,
int i,
Type elemType) {
//if ( !persister.isOneToMany() ) throw new AssertionFailure("Not implemented for Bags");
return false;
}
|
public int occurrences(Object o) {
read();
Iterator iter = bag.iterator();
int result=0;
while ( iter.hasNext() ) {
if ( o.equals( iter.next() ) ) result++;
}
return result;
}
|
public Object readFrom(ResultSet rs,
CollectionPersister persister,
CollectionAliases descriptor,
Object owner) throws HibernateException, SQLException {
// note that if we load this collection from a cartesian product
// the multiplicity would be broken ... so use an idbag instead
Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ;
if (element!=null) bag.add(element);
return element;
}
|
public boolean remove(Object o) {
initialize( true );
if ( bag.remove( o ) ) {
dirty();
return true;
}
else {
return false;
}
}
|
public Object remove(int i) {
write();
return bag.remove(i);
}
|
public boolean removeAll(Collection c) {
if ( c.size() >0 ) {
initialize( true );
if ( bag.removeAll( c ) ) {
dirty();
return true;
}
else {
return false;
}
}
else {
return false;
}
}
|
public boolean retainAll(Collection c) {
initialize( true );
if ( bag.retainAll( c ) ) {
dirty();
return true;
}
else {
return false;
}
}
|
public Object set(int i,
Object o) {
write();
return bag.set(i, o);
}
|
public int size() {
return readSize() ? getCachedSize() : bag.size();
}
|
public List subList(int start,
int end) {
read();
return new ListProxy( bag.subList(start, end) );
}
|
public Object[] toArray() {
read();
return bag.toArray();
}
|
public Object[] toArray(Object[] a) {
read();
return bag.toArray(a);
}
|
public String toString() {
read();
return bag.toString();
}
|