FileDocCategorySizeDatePackage
IndirectList.javaAPI DocGlassfish v2 API22315Tue May 22 16:54:20 BST 2007oracle.toplink.essentials.indirection

IndirectList

public class IndirectList extends Vector implements IndirectContainer
IndirectList allows a domain class to take advantage of TopLink indirection without having to declare its instance variable as a ValueHolderInterface.

To use an IndirectList:

  • Declare the appropriate instance variable with type IndirectList (jdk1.1) or Collection/List/Vector (jdk1.2).
  • Send the message #useTransparentCollection() to the appropriate CollectionMapping.
TopLink will place an IndirectList in the instance variable when the containing domain object is read from the datatabase. With the first message sent to the IndirectList, the contents are fetched from the database and normal Collection/List/Vector behavior is resumed.
see
oracle.toplink.essentials.mappings.CollectionMapping
see
oracle.toplink.essentials.indirection.IndirectMap
author
Big Country
since
TOPLink/Java 2.5

Fields Summary
protected Vector
delegate
Reduce type casting.
protected ValueHolderInterface
valueHolder
Delegate indirection behavior to a value holder.
private transient String
attributeName
The mapping attribute name, used to raise change events.
protected int
initialCapacity
Store initial size for lazy init.
Constructors Summary
public IndirectList()
PUBLIC: Construct an empty IndirectList so that its internal data array has size 10 and its standard capacity increment is zero.


                              
      
        this(10);
    
public IndirectList(int initialCapacity)
PUBLIC: Construct an empty IndirectList with the specified initial capacity and with its capacity increment equal to zero.

param
initialCapacity the initial capacity of the vector
exception
IllegalArgumentException if the specified initial capacity is negative

        this(initialCapacity, 0);
    
public IndirectList(int initialCapacity, int capacityIncrement)
PUBLIC: Construct an empty IndirectList with the specified initial capacity and capacity increment.

param
initialCapacity the initial capacity of the vector
param
capacityIncrement the amount by which the capacity is increased when the vector overflows
exception
IllegalArgumentException if the specified initial capacity is negative

        super(0);
        this.initialize(initialCapacity, capacityIncrement);
    
public IndirectList(Collection c)
PUBLIC: Construct an IndirectList containing the elements of the specified collection, in the order they are returned by the collection's iterator.

param
c a collection containing the elements to construct this IndirectList with.

        super(0);
        this.initialize(c);
    
Methods Summary
public voidadd(int index, java.lang.Object element)

see
java.util.Vector#add(int, java.lang.Object)

        this.getDelegate().add(index, element);
        raiseAddChangeEvent(element);
    
public synchronized booleanadd(java.lang.Object o)

see
java.util.Vector#add(java.lang.Object)

        this.getDelegate().add(o);
        raiseAddChangeEvent(o);
        return true;
    
public synchronized booleanaddAll(java.util.Collection c)

see
java.util.Vector#addAll(java.util.Collection)

        // Must trigger add events if tracked or uow.
        if (hasBeenRegistered()) {
            Iterator objects = c.iterator();
            while (objects.hasNext()) {
                this.add(objects.next());
            }
            return true;
        }

        return getDelegate().addAll(c);
    
public synchronized booleanaddAll(int index, java.util.Collection c)

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

        Iterator objects = c.iterator();
        // Must trigger add events if tracked or uow.
        if (hasBeenRegistered()) {
            while (objects.hasNext()) {
                this.add(index, objects.next());
                index++;
            }
            return true;
        }

        return this.getDelegate().addAll(index, c);

    
public synchronized voidaddElement(java.lang.Object obj)

see
java.util.Vector#addElement(java.lang.Object)

        this.add(obj);
    
protected java.util.VectorbuildDelegate()
PUBLIC: Return the freshly-built delegate.
In jdk1.1, the delegate may not be a Vector (in which case, it better be another IndirectList).
In jdk1.2, IndirectList is a subclass of Vector, so there is no need to check.

        return (Vector)getValueHolder().getValue();
    
public intcapacity()

see
java.util.Vector#capacity()

        return this.getDelegate().capacity();
    
public voidclear()

see
java.util.Vector#clear()

        if (hasBeenRegistered()) {
            Iterator objects = this.iterator();
            while (objects.hasNext()) {
                Object o = objects.next();
                objects.remove();
                this.raiseRemoveChangeEvent(o);
            }
        } else {
            this.getDelegate().clear();
        }
    
public synchronized java.lang.Objectclone()
PUBLIC:

see
java.util.Vector#clone() This will result in a database query if necessary.

        IndirectList result = (IndirectList)super.clone();
        result.delegate = (Vector)this.getDelegate().clone();
        result.attributeName = null;
        return result;
    
public booleancontains(java.lang.Object elem)
PUBLIC:

see
java.util.Vector#contains(java.lang.Object)

        return this.getDelegate().contains(elem);
    
public synchronized booleancontainsAll(java.util.Collection c)

see
java.util.Vector#containsAll(java.util.Collection)

        return this.getDelegate().containsAll(c);
    
public synchronized voidcopyInto(java.lang.Object[] anArray)

see
java.util.Vector#copyInto(java.lang.Object[])

        this.getDelegate().copyInto(anArray);
    
public synchronized java.lang.ObjectelementAt(int index)

see
java.util.Vector#elementAt(int)

        return this.getDelegate().elementAt(index);
    
public java.util.Enumerationelements()

see
java.util.Vector#elements()

        return this.getDelegate().elements();
    
public synchronized voidensureCapacity(int minCapacity)

see
java.util.Vector#ensureCapacity(int)

        this.getDelegate().ensureCapacity(minCapacity);
    
public synchronized booleanequals(java.lang.Object o)

see
java.util.Vector#equals(java.lang.Object)

        return this.getDelegate().equals(o);
    
public synchronized java.lang.ObjectfirstElement()

see
java.util.Vector#firstElement()

        return this.getDelegate().firstElement();
    
public synchronized java.lang.Objectget(int index)

see
java.util.Vector#get(int)

        return this.getDelegate().get(index);
    
protected synchronized java.util.VectorgetDelegate()
PUBLIC: Check whether the contents have been read from the database. If they have not, read them and set the delegate.

        if (delegate == null) {
            delegate = this.buildDelegate();
        }
        return delegate;
    
public java.lang.StringgetTopLinkAttributeName()
Return the mapping attribute name, used to raise change events.

         return attributeName;
     
public synchronized oracle.toplink.essentials.indirection.ValueHolderInterfacegetValueHolder()
PUBLIC: Return the valueHolder.

        // PERF: lazy initialize value holder and vector as are normally set after creation.
        if (valueHolder == null) {
            valueHolder = new ValueHolder(new Vector(this.initialCapacity, this.capacityIncrement));
        }
        return valueHolder;
    
public booleanhasBeenRegistered()
INTERNAL: return whether this IndirectList has been registered with the UnitOfWork

        return getValueHolder() instanceof oracle.toplink.essentials.internal.indirection.UnitOfWorkQueryValueHolder;
    
public synchronized inthashCode()
INTERNAL:

see
java.util.Vector#hashCode()

        return this.getDelegate().hashCode();
    
public intindexOf(java.lang.Object elem)

see
java.util.Vector#indexOf(java.lang.Object)

        return this.getDelegate().indexOf(elem);
    
public synchronized intindexOf(java.lang.Object elem, int index)

see
java.util.Vector#indexOf(java.lang.Object, int)

        return this.getDelegate().indexOf(elem, index);
    
protected voidinitialize(int initialCapacity, int capacityIncrement)
Initialize the instance.

        this.initialCapacity = initialCapacity;
        this.capacityIncrement = capacityIncrement;
        this.delegate = null;
        this.valueHolder = null;
    
protected voidinitialize(java.util.Collection c)
Initialize the instance.

        this.delegate = null;
        Vector temp = new Vector(c);
        this.valueHolder = new ValueHolder(temp);
    
public synchronized voidinsertElementAt(java.lang.Object obj, int index)

see
java.util.Vector#insertElementAt(java.lang.Object, int)

        this.getDelegate().insertElementAt(obj, index);
        this.raiseAddChangeEvent(obj);
    
public booleanisEmpty()

see
java.util.Vector#isEmpty()

        return this.getDelegate().isEmpty();
    
public booleanisInstantiated()
PUBLIC: Return whether the contents have been read from the database.

        return this.getValueHolder().isInstantiated();
    
public java.util.Iteratoriterator()

see
java.util.AbstractList#iterator()

        // Must wrap the interator to raise the remove event.
        return new Iterator() {
            Iterator delegateIterator = IndirectList.this.getDelegate().iterator();
            Object currentObject;
            
            public boolean hasNext() {
                return this.delegateIterator.hasNext();
            }
            
            public Object next() {
                this.currentObject = this.delegateIterator.next();
                return this.currentObject;
            }
            
            public void remove() {
                this.delegateIterator.remove();
                IndirectList.this.raiseRemoveChangeEvent(this.currentObject);
            }
        };
    
public synchronized java.lang.ObjectlastElement()

see
java.util.Vector#lastElement()

        return this.getDelegate().lastElement();
    
public intlastIndexOf(java.lang.Object elem)

see
java.util.Vector#lastIndexOf(java.lang.Object)

        return this.getDelegate().lastIndexOf(elem);
    
public synchronized intlastIndexOf(java.lang.Object elem, int index)

see
java.util.Vector#lastIndexOf(java.lang.Object, int)

        return this.getDelegate().lastIndexOf(elem, index);
    
public java.util.ListIteratorlistIterator()

see
java.util.AbstractList#listIterator()

        return this.listIterator(0);
    
public java.util.ListIteratorlistIterator(int index)

see
java.util.AbstractList#listIterator(int)

        // Must wrap the interator to raise the remove event.
        return new ListIterator() {
            ListIterator delegateIterator = IndirectList.this.getDelegate().listIterator(index);
            Object currentObject;
            
            public boolean hasNext() {
                return this.delegateIterator.hasNext();
            }
            
            public boolean hasPrevious() {
                return this.delegateIterator.hasPrevious();
            }
            
            public int previousIndex() {
                return this.delegateIterator.previousIndex();
            }
            
            public int nextIndex() {
                return this.delegateIterator.nextIndex();
            }
            
            public Object next() {
                this.currentObject = this.delegateIterator.next();
                return this.currentObject;
            }
            
            public Object previous() {
                this.currentObject = this.delegateIterator.previous();
                return this.currentObject;
            }
            
            public void remove() {
                this.delegateIterator.remove();
                IndirectList.this.raiseRemoveChangeEvent(this.currentObject);
            }
            
            public void set(Object object) {
                this.delegateIterator.set(object);
                IndirectList.this.raiseRemoveChangeEvent(this.currentObject);
                IndirectList.this.raiseAddChangeEvent(object);
            }
            
            public void add(Object object) {
                this.delegateIterator.add(object);
                IndirectList.this.raiseAddChangeEvent(object);
            }
        };
    
protected voidraiseAddChangeEvent(java.lang.Object element)
Raise the add change event and relationship maintainence.

        if (hasBeenRegistered()) {
            ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceSet(element, null);
        }
    
protected voidraiseRemoveChangeEvent(java.lang.Object element)
Raise the remove change event.

        if (hasBeenRegistered()) {
            ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceRemove(element);
        }
    
public synchronized java.lang.Objectremove(int index)

see
java.util.Vector#remove(int)

        Object value = this.getDelegate().remove(index);        
        this.raiseRemoveChangeEvent(value);
        return value;
    
public booleanremove(java.lang.Object o)

see
java.util.Vector#remove(java.lang.Object)

        if (this.getDelegate().remove(o)) {     
            this.raiseRemoveChangeEvent(o);
            return true;
        }
        return false;
    
public synchronized booleanremoveAll(java.util.Collection c)

see
java.util.Vector#removeAll(java.util.Collection)

        // Must trigger remove events if tracked or uow.
        if (hasBeenRegistered()) {
            Iterator objects = c.iterator();
            while (objects.hasNext()) {
                this.remove(objects.next());
            }
            return true;
        }
        return this.getDelegate().removeAll(c);
    
public synchronized voidremoveAllElements()

see
java.util.Vector#removeAllElements()

        // Must trigger remove events if tracked or uow.
        if (hasBeenRegistered()) {
            Iterator objects = this.iterator();
            while (objects.hasNext()) {
                Object object = objects.next();
                objects.remove();
                this.raiseRemoveChangeEvent(object);
            }
            return;
        }
        this.getDelegate().removeAllElements();
    
public synchronized booleanremoveElement(java.lang.Object obj)

see
java.util.Vector#removeElement(java.lang.Object)

        return this.remove(obj);
    
public synchronized voidremoveElementAt(int index)

see
java.util.Vector#removeElementAt(int)

        this.remove(index);
    
public synchronized booleanretainAll(java.util.Collection c)

see
java.util.Vector#retainAll(java.util.Collection)

        // Must trigger remove events if tracked or uow.
        if (hasBeenRegistered()) {
            Iterator objects = getDelegate().iterator();
            while (objects.hasNext()) {
                Object object = objects.next();
                if (!c.contains(object)) {
                    objects.remove();
                    this.raiseRemoveChangeEvent(object);
                }
            }
            return true;
        }
        return this.getDelegate().retainAll(c);
    
public synchronized java.lang.Objectset(int index, java.lang.Object element)

see
java.util.Vector#set(int, java.lang.Object)

        Object oldValue = this.getDelegate().set(index, element);
        this.raiseRemoveChangeEvent(oldValue);
        this.raiseAddChangeEvent(element);
        return oldValue;
    
public synchronized voidsetElementAt(java.lang.Object obj, int index)

see
java.util.Vector#setElementAt(java.lang.Object, int)

        this.set(index, obj);
    
public synchronized voidsetSize(int newSize)

see
java.util.Vector#setSize(int)

        // Must trigger remove events if tracked or uow.
        if (hasBeenRegistered()) {
            if (newSize > this.size()) {
                for (int index = size(); index > newSize; index--) {
                    this.remove(index - 1);
                }
            }
        }    
        this.getDelegate().setSize(newSize);
    
public voidsetTopLinkAttributeName(java.lang.String attributeName)
Set the mapping attribute name, used to raise change events. This is required if the change listener is set.

         this.attributeName = attributeName;
     
public voidsetValueHolder(oracle.toplink.essentials.indirection.ValueHolderInterface valueHolder)
PUBLIC: Set the value holder.

        this.delegate = null;
        this.valueHolder = valueHolder;
    
public intsize()

see
java.util.Vector#size()

        return this.getDelegate().size();
    
public java.util.ListsubList(int fromIndex, int toIndex)

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

        return this.getDelegate().subList(fromIndex, toIndex);
    
public synchronized java.lang.Object[]toArray()

see
java.util.Vector#toArray()

        return this.getDelegate().toArray();
    
public synchronized java.lang.Object[]toArray(java.lang.Object[] a)

see
java.util.Vector#toArray(java.lang.Object[])

        return this.getDelegate().toArray(a);
    
public java.lang.StringtoString()
PUBLIC: Use the java.util.Vector#toString(); but wrap it with braces to indicate there is a bit of indirection. Don't allow this method to trigger a database read.

see
java.util.Vector#toString()

        if (ValueHolderInterface.shouldToStringInstantiate) {
            return this.getDelegate().toString();
        }
        if (this.isInstantiated()) {
            return "{" + this.getDelegate().toString() + "}";
        } else {
            return "{" + oracle.toplink.essentials.internal.helper.Helper.getShortClassName(this.getClass()) + ": not instantiated}";
        }
    
public synchronized voidtrimToSize()

see
java.util.Vector#trimToSize()

        this.getDelegate().trimToSize();