ze(persister);
Serializable[] array = (Serializable[]) disassembled;
for ( int i=0; i<array.length; i++ ) {
Object element = persister.getElementType().assemble( array[i], getSession(), owner );
if ( element!=null ) bag.add( element );
}
}
public boolean needsRecreate(CollectionPersister persister) {
return !persister.isOneToMany();
}
// For a one-to-many, a <bag> is not really a bag;
// it is *really* a set, since it can't contain the
// same element twice. It could be considered a bug
// in the mapping dtd that <bag> allows <one-to-many>.
// Anyway, here we implement <set> semantics for a
// <one-to-many> <bag>!
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 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 isRowUpdatePossible() {
return false;
}
public boolean needsUpdating(Object entry, int i, Type elemType) {
//if ( !persister.isOneToMany() ) throw new AssertionFailure("Not implemented for Bags");
return false;
}
/**
* @see java.util.Collection#size()
*/
public int size() {
return readSize() ? getCachedSize() : bag.size();
}
/**
* @see java.util.Collection#isEmpty()
*/
public boolean isEmpty() {
return readSize() ? getCachedSize()==0 : bag.isEmpty();
}
/**
* @see java.util.Collection#contains(Object)
*/
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
return exists==null ?
bag.contains(object) :
exists.booleanValue();
}
/**
* @see java.util.Collection#iterator()
*/
public Iterator iterator() {
read();
return new IteratorProxy( bag.iterator() );
}
/**
* @see java.util.Collection#toArray()
*/
public Object[] toArray() {
read();
return bag.toArray();
}
/**
* @see java.util.Collection#toArray(Object[])
*/
public Object[] toArray(Object[] a) {
read();
return bag.toArray(a);
}
/**
* @see java.util.Collection#add(Object)
*/
public boolean add(Object object) {
if ( !isOperationQueueEnabled() ) {
write();
return bag.add(object);
}
else {
queueOperation( new SimpleAdd(object) );[br