FileDocCategorySizeDatePackage
PersistentList.javaAPI DocHibernate 3.2.512995Mon Nov 06 15:00:42 GMT 2006org.hibernate.collection

PersistentList

public class PersistentList extends AbstractPersistentCollection implements List
A persistent wrapper for a java.util.List. Underlying collection is an ArrayList.
see
java.util.ArrayList
author
Gavin King

Fields Summary
protected List
list
Constructors Summary
public PersistentList(org.hibernate.engine.SessionImplementor session)

		super(session);
	
public PersistentList(org.hibernate.engine.SessionImplementor session, List list)

		super(session);
		this.list = list;
		setInitialized();
		setDirectlyAccessible(true);
	
public PersistentList()

Methods Summary
public booleanadd(java.lang.Object object)

see
java.util.List#add(Object)

		if ( !isOperationQueueEnabled() ) {
			write();
			return list.add(object);
		}
		else {
			queueOperation( new SimpleAdd(object) );
			return true;
		}
	
public voidadd(int index, java.lang.Object value)

see
java.util.List#add(int, Object)

		if (index<0) {
			throw new ArrayIndexOutOfBoundsException("negative index");
		}
		if ( !isOperationQueueEnabled() ) {
			write();
			list.add(index, value);
		}
		else {
			queueOperation( new Add(index, value) );
		}
	
public booleanaddAll(java.util.Collection values)

see
java.util.List#addAll(Collection)

		if ( values.size()==0 ) {
			return false;
		}
		if ( !isOperationQueueEnabled() ) {
			write();
			return list.addAll(values);
		}
		else {
			Iterator iter = values.iterator();
			while ( iter.hasNext() ) {
				queueOperation( new SimpleAdd( iter.next() ) );	
			}
			return values.size()>0;
		}
	
public booleanaddAll(int index, java.util.Collection coll)

see
java.util.List#addAll(int, Collection)

		if ( coll.size()>0 ) {
			write();
			return list.addAll(index,  coll);
		}
		else {
			return false;
		}
	
public voidbeforeInitialize(org.hibernate.persister.collection.CollectionPersister persister, int anticipatedSize)

		this.list = ( List ) persister.getCollectionType().instantiate( anticipatedSize );
	
public voidclear()

see
java.util.List#clear()

		if ( isClearQueueEnabled() ) {
			queueOperation( new Clear() );
		}
		else {
			initialize( true );
			if ( ! list.isEmpty() ) {
				list.clear();
				dirty();
			}
		}
	
public booleancontains(java.lang.Object object)

see
java.util.List#contains(Object)

		Boolean exists = readElementExistence(object);
		return exists==null ? 
				list.contains(object) : 
				exists.booleanValue();
	
public booleancontainsAll(java.util.Collection coll)

see
java.util.List#containsAll(Collection)

		read();
		return list.containsAll(coll);
	
public java.io.Serializabledisassemble(org.hibernate.persister.collection.CollectionPersister persister)


		int length = list.size();
		Serializable[] result = new Serializable[length];
		for ( int i=0; i<length; i++ ) {
			result[i] = persister.getElementType().disassemble( list.get(i), getSession(), null );
		}
		return result;
	
public booleanempty()

		return list.isEmpty();
	
public java.util.Iteratorentries(org.hibernate.persister.collection.CollectionPersister persister)

		return list.iterator();
	
public booleanentryExists(java.lang.Object entry, int i)

		return entry!=null;
	
public booleanequals(java.lang.Object other)

		read();
		return list.equals(other);
	
public booleanequalsSnapshot(org.hibernate.persister.collection.CollectionPersister persister)

		Type elementType = persister.getElementType();
		List sn = (List) getSnapshot();
		if ( sn.size()!=this.list.size() ) return false;
		Iterator iter = list.iterator();
		Iterator sniter = sn.iterator();
		while ( iter.hasNext() ) {
			if ( elementType.isDirty( iter.next(), sniter.next(), getSession() ) ) return false;
		}
		return true;
	
public java.lang.Objectget(int index)

see
java.util.List#get(int)

		if (index<0) {
			throw new ArrayIndexOutOfBoundsException("negative index");
		}
		Object result = readElementByIndex( new Integer(index) );
		return result==UNKNOWN ? list.get(index) : result;
	
public java.util.IteratorgetDeletes(org.hibernate.persister.collection.CollectionPersister persister, boolean indexIsFormula)

		List deletes = new ArrayList();
		List sn = (List) getSnapshot();
		int end;
		if ( sn.size() > list.size() ) {
			for ( int i=list.size(); i<sn.size(); i++ ) {
				deletes.add( indexIsFormula ? sn.get(i) : new Integer(i) );
			}
			end = list.size();
		}
		else {
			end = sn.size();
		}
		for ( int i=0; i<end; i++ ) {
			if ( list.get(i)==null && sn.get(i)!=null ) {
				deletes.add( indexIsFormula ? sn.get(i) : new Integer(i) );
			}
		}
		return deletes.iterator();
	
public java.lang.ObjectgetElement(java.lang.Object entry)

		return entry;
	
public java.lang.ObjectgetIndex(java.lang.Object entry, int i, org.hibernate.persister.collection.CollectionPersister persister)

		return new Integer(i);
	
public java.util.CollectiongetOrphans(java.io.Serializable snapshot, java.lang.String entityName)

		List sn = (List) snapshot;
	    return getOrphans( sn, list, entityName, getSession() );
	
public java.io.SerializablegetSnapshot(org.hibernate.persister.collection.CollectionPersister persister)

		
		EntityMode entityMode = getSession().getEntityMode();
		
		ArrayList clonedList = new ArrayList( list.size() );
		Iterator iter = list.iterator();
		while ( iter.hasNext() ) {
			Object deepCopy = persister.getElementType()
					.deepCopy( iter.next(), entityMode, persister.getFactory() );
			clonedList.add( deepCopy );
		}
		return clonedList;
	
public java.lang.ObjectgetSnapshotElement(java.lang.Object entry, int i)

		final List sn = (List) getSnapshot();
		return sn.get(i);
	
public inthashCode()

		read();
		return list.hashCode();
	
public intindexOf(java.lang.Object value)

see
java.util.List#indexOf(Object)

		read();
		return list.indexOf(value);
	
public voidinitializeFromCache(org.hibernate.persister.collection.CollectionPersister persister, java.io.Serializable disassembled, java.lang.Object owner)

		Serializable[] array = ( Serializable[] ) disassembled;
		int size = array.length;
		beforeInitialize( persister, size );
		for ( int i = 0; i < size; i++ ) {
			list.add( persister.getElementType().assemble( array[i], getSession(), owner ) );
		}
	
public booleanisEmpty()

see
java.util.List#isEmpty()

		return readSize() ? getCachedSize()==0 : list.isEmpty();
	
public booleanisSnapshotEmpty(java.io.Serializable snapshot)

		return ( (Collection) snapshot ).isEmpty();
	
public booleanisWrapper(java.lang.Object collection)

		return list==collection;
	
public java.util.Iteratoriterator()

see
java.util.List#iterator()

		read();
		return new IteratorProxy( list.iterator() );
	
public intlastIndexOf(java.lang.Object value)

see
java.util.List#lastIndexOf(Object)

		read();
		return list.lastIndexOf(value);
	
public java.util.ListIteratorlistIterator()

see
java.util.List#listIterator()

		read();
		return new ListIteratorProxy( list.listIterator() );
	
public java.util.ListIteratorlistIterator(int index)

see
java.util.List#listIterator(int)

		read();
		return new ListIteratorProxy( list.listIterator(index) );
	
public booleanneedsInserting(java.lang.Object entry, int i, org.hibernate.type.Type elemType)

		final List sn = (List) getSnapshot();
		return list.get(i)!=null && ( i >= sn.size() || sn.get(i)==null );
	
public booleanneedsUpdating(java.lang.Object entry, int i, org.hibernate.type.Type elemType)

		final List sn = (List) getSnapshot();
		return i<sn.size() && sn.get(i)!=null && list.get(i)!=null && 
			elemType.isDirty( list.get(i), sn.get(i), getSession() );
	
public java.lang.ObjectreadFrom(java.sql.ResultSet rs, org.hibernate.persister.collection.CollectionPersister persister, org.hibernate.loader.CollectionAliases descriptor, java.lang.Object owner)

		Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ;
		int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ) ).intValue();
		
		//pad with nulls from the current last element up to the new index
		for ( int i = list.size(); i<=index; i++) {
			list.add(i, null);
		}
		
		list.set(index, element);
		return element;
	
public booleanremove(java.lang.Object value)

see
java.util.List#remove(Object)

		Boolean exists = isPutQueueEnabled() ? readElementExistence(value) : null;
		if ( exists == null ) {
			initialize( true );
			if ( list.remove( value ) ) {
				dirty();
				return true;
			}
			else {
				return false;
			}
		}
		else if ( exists.booleanValue() ) {
			queueOperation( new SimpleRemove(value) );
			return true;
		}
		else {
			return false;
		}
	
public java.lang.Objectremove(int index)

see
java.util.List#remove(int)

		if (index<0) {
			throw new ArrayIndexOutOfBoundsException("negative index");
		}
		Object old = isPutQueueEnabled() ?
				readElementByIndex( new Integer(index) ) : UNKNOWN;
		if ( old==UNKNOWN ) {
			write();
			return list.remove(index);
		}
		else {
			queueOperation( new Remove(index, old) );
			return old;
		}
	
public booleanremoveAll(java.util.Collection coll)

see
java.util.List#removeAll(Collection)

		if ( coll.size()>0 ) {
			initialize( true );
			if ( list.removeAll( coll ) ) {
				dirty();
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	
public booleanretainAll(java.util.Collection coll)

see
java.util.List#retainAll(Collection)

		initialize( true );
		if ( list.retainAll( coll ) ) {
			dirty();
			return true;
		}
		else {
			return false;
		}
	
public java.lang.Objectset(int index, java.lang.Object value)

see
java.util.List#set(int, Object)

		if (index<0) {
			throw new ArrayIndexOutOfBoundsException("negative index");
		}
		Object old = isPutQueueEnabled() ? readElementByIndex( new Integer(index) ) : UNKNOWN;
		if ( old==UNKNOWN ) {
			write();
			return list.set(index, value);
		}
		else {
			queueOperation( new Set(index, value, old) );
			return old;
		}
	
public intsize()

see
java.util.List#size()

		return readSize() ? getCachedSize() : list.size();
	
public java.util.ListsubList(int from, int to)

see
java.util.List#subList(int, int)

		read();
		return new ListProxy( list.subList(from, to) );
	
public java.lang.Object[]toArray()

see
java.util.List#toArray()

		read();
		return list.toArray();
	
public java.lang.Object[]toArray(java.lang.Object[] array)

see
java.util.List#toArray(Object[])

		read();
		return list.toArray(array);
	
public java.lang.StringtoString()

		read();
		return list.toString();