Class IndirectList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.Vector<E>
-
- org.eclipse.persistence.indirection.IndirectList<E>
-
- Type Parameters:
E- the type of elements maintained by this list
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess,ChangeTracker,CollectionChangeTracker,IndirectCollection,IndirectContainer
public class IndirectList<E> extends java.util.Vector<E> implements CollectionChangeTracker, IndirectCollection
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 Collection/List/Vector (jdk1.2).
- Send the message #useTransparentCollection() to the appropriate CollectionMapping.
- See Also:
CollectionMapping,IndirectMap, Serialized Form- Author:
- Big Country
- Since:
- TOPLink/Java 2.5
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector<E>delegateReduce type casting.protected intinitialCapacityStore initial size for lazy init.protected booleanisRegisteredPERF: Quick check flag if has been registered in a unit of work.protected ValueHolderInterfacevalueHolderDelegate indirection behavior to a value holder.
-
Constructor Summary
Constructors Constructor Description IndirectList()PUBLIC: Construct an empty IndirectList so that its internal data array has size 10 and its standard capacity increment is zero.IndirectList(int initialCapacity)PUBLIC: Construct an empty IndirectList with the specified initial capacity and with its capacity increment equal to zero.IndirectList(int initialCapacity, int capacityIncrement)PUBLIC: Construct an empty IndirectList with the specified initial capacity and capacity increment.IndirectList(java.util.Collection<? extends E> collection)PUBLIC: Construct an IndirectList containing the elements of the specified collection, in the order they are returned by the collection's iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.beans.PropertyChangeListener_persistence_getPropertyChangeListener()INTERNAL: Return the property change listener for change tracking.void_persistence_setPropertyChangeListener(java.beans.PropertyChangeListener changeListener)INTERNAL: Set the property change listener for change tracking.voidadd(int index, E element)booleanadd(E element)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)voidaddElement(E obj)protected java.util.Vector<E>buildDelegate()INTERNAL: Return the freshly-built delegate.intcapacity()voidclear()voidclearDeferredChanges()INTERNAL: clear any changes that have been deferred to instantiation.java.lang.Objectclone()PUBLIC:booleancontains(java.lang.Object element)PUBLIC:booleancontainsAll(java.util.Collection<?> c)voidcopyInto(java.lang.Object[] anArray)EelementAt(int index)java.util.Enumeration<E>elements()voidensureCapacity(int minCapacity)booleanequals(java.lang.Object o)EfirstElement()voidforEach(java.util.function.Consumer<? super E> action)Eget(int index)java.util.Collection<E>getAddedElements()INTERNAL: Return the elements that have been added before instantiation.protected java.util.Vector<E>getDelegate()INTERNAL: Check whether the contents have been read from the database.java.lang.ObjectgetDelegateObject()INTERNAL: Return the real collection object.java.util.Collection<E>getRemovedElements()INTERNAL: Return the elements that have been removed before instantiation.java.lang.StringgetTrackedAttributeName()INTERNAL: Return the mapping attribute name, used to raise change events.ValueHolderInterfacegetValueHolder()INTERNAL: Return the valueHolder.booleanhasAddedElements()INTERNAL: Return if any elements that have been added before instantiation.booleanhasBeenRegistered()INTERNAL: return whether this IndirectList has been registered with the UnitOfWorkbooleanhasDeferredChanges()INTERNAL: Return if any elements that have been added or removed before instantiation.inthashCode()INTERNAL:booleanhasRemovedElements()INTERNAL: Return if any elements that have been removed before instantiation.booleanhasTrackedPropertyChangeListener()INTERNAL: Return if the collection has a property change listener for change tracking.intindexOf(java.lang.Object elem)intindexOf(java.lang.Object elem, int index)voidinsertElementAt(E obj, int index)booleanisEmpty()booleanisInstantiated()PUBLIC: Return whether the contents have been read from the database.booleanisListOrderBrokenInDb()protected booleanisRelationshipMaintenanceRequired()java.util.Iterator<E>iterator()ElastElement()intlastIndexOf(java.lang.Object elem)intlastIndexOf(java.lang.Object elem, int index)java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)java.util.stream.Stream<E>parallelStream()protected voidraiseAddChangeEvent(java.lang.Object element, java.lang.Integer index)Raise the add change event and relationship maintenance.protected voidraiseAddChangeEvent(java.lang.Object element, java.lang.Integer index, boolean isSet)protected voidraiseRemoveChangeEvent(java.lang.Object element, java.lang.Integer index)Raise the remove change event.protected voidraiseRemoveChangeEvent(java.lang.Object element, java.lang.Integer index, boolean isSet)Eremove(int index)booleanremove(java.lang.Object element)booleanremoveAll(java.util.Collection<?> c)voidremoveAllElements()booleanremoveElement(java.lang.Object obj)voidremoveElementAt(int index)booleanremoveIf(java.util.function.Predicate<? super E> filter)voidreplaceAll(java.util.function.UnaryOperator<E> operator)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)voidsetElementAt(E obj, int index)voidsetIsListOrderBrokenInDb(boolean isBroken)voidsetSize(int newSize)voidsetTrackedAttributeName(java.lang.String attributeName)INTERNAL: Set the mapping attribute name, used to raise change events.voidsetUseLazyInstantiation(boolean useLazyInstantiation)INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBvoidsetValueHolder(ValueHolderInterface valueHolder)INTERNAL: Set the value holder.protected booleanshouldAvoidInstantiation()INTERNAL: Return if add/remove should trigger instantiation or avoid.protected booleanshouldUseLazyInstantiation()Return whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBintsize()voidsort(java.util.Comparator<? super E> c)java.util.Spliterator<E>spliterator()java.util.stream.Stream<E>stream()java.util.List<E>subList(int fromIndex, int toIndex)java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()PUBLIC: Use the java.util.Vector#toString(); but wrap it with braces to indicate there is a bit of indirection.voidtrimToSize()protected booleanusesListOrderField()INTERNAL: Returns whether the mapping has listOrderField.
-
-
-
Field Detail
-
delegate
protected volatile java.util.Vector<E> delegate
Reduce type casting.
-
valueHolder
protected volatile ValueHolderInterface valueHolder
Delegate indirection behavior to a value holder.
-
initialCapacity
protected int initialCapacity
Store initial size for lazy init.
-
isRegistered
protected boolean isRegistered
PERF: Quick check flag if has been registered in a unit of work.
-
-
Constructor Detail
-
IndirectList
public IndirectList()
PUBLIC: Construct an empty IndirectList so that its internal data array has size 10 and its standard capacity increment is zero.
-
IndirectList
public IndirectList(int initialCapacity)
PUBLIC: Construct an empty IndirectList with the specified initial capacity and with its capacity increment equal to zero.- Parameters:
initialCapacity- the initial capacity of the vector- Throws:
java.lang.IllegalArgumentException- if the specified initial capacity is negative
-
IndirectList
public IndirectList(int initialCapacity, int capacityIncrement)PUBLIC: Construct an empty IndirectList with the specified initial capacity and capacity increment.- Parameters:
initialCapacity- the initial capacity of the vectorcapacityIncrement- the amount by which the capacity is increased when the vector overflows- Throws:
java.lang.IllegalArgumentException- if the specified initial capacity is negative
-
IndirectList
public IndirectList(java.util.Collection<? extends E> collection)
PUBLIC: Construct an IndirectList containing the elements of the specified collection, in the order they are returned by the collection's iterator.- Parameters:
collection- a collection containing the elements to construct this IndirectList with.
-
-
Method Detail
-
add
public void add(int index, E element)
-
raiseAddChangeEvent
protected void raiseAddChangeEvent(java.lang.Object element, java.lang.Integer index)Raise the add change event and relationship maintenance.
-
raiseAddChangeEvent
protected void raiseAddChangeEvent(java.lang.Object element, java.lang.Integer index, boolean isSet)
-
isRelationshipMaintenanceRequired
protected boolean isRelationshipMaintenanceRequired()
-
raiseRemoveChangeEvent
protected void raiseRemoveChangeEvent(java.lang.Object element, java.lang.Integer index)Raise the remove change event.
-
raiseRemoveChangeEvent
protected void raiseRemoveChangeEvent(java.lang.Object element, java.lang.Integer index, boolean isSet)
-
add
public boolean add(E element)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
addElement
public void addElement(E obj)
- Overrides:
addElementin classjava.util.Vector<E>- See Also:
Vector.addElement(java.lang.Object)
-
buildDelegate
protected java.util.Vector<E> buildDelegate()
INTERNAL: Return the freshly-built delegate.
-
capacity
public int capacity()
- Overrides:
capacityin classjava.util.Vector<E>- See Also:
Vector.capacity()
-
clear
public void clear()
-
clearDeferredChanges
public void clearDeferredChanges()
INTERNAL: clear any changes that have been deferred to instantiation. Indirect collections with change tracking avoid instantiation on add/remove.- Specified by:
clearDeferredChangesin interfaceIndirectCollection
-
clone
public java.lang.Object clone()
PUBLIC:- Overrides:
clonein classjava.util.Vector<E>- See Also:
This will result in a database query if necessary.
-
contains
public boolean contains(java.lang.Object element)
PUBLIC:
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
copyInto
public void copyInto(java.lang.Object[] anArray)
- Overrides:
copyIntoin classjava.util.Vector<E>- See Also:
Vector.copyInto(java.lang.Object[])
-
elementAt
public E elementAt(int index)
- Overrides:
elementAtin classjava.util.Vector<E>- See Also:
Vector.elementAt(int)
-
elements
public java.util.Enumeration<E> elements()
- Overrides:
elementsin classjava.util.Vector<E>- See Also:
Vector.elements()
-
ensureCapacity
public void ensureCapacity(int minCapacity)
- Overrides:
ensureCapacityin classjava.util.Vector<E>- See Also:
Vector.ensureCapacity(int)
-
equals
public boolean equals(java.lang.Object o)
-
firstElement
public E firstElement()
- Overrides:
firstElementin classjava.util.Vector<E>- See Also:
Vector.firstElement()
-
get
public E get(int index)
-
getDelegate
protected java.util.Vector<E> getDelegate()
INTERNAL: Check whether the contents have been read from the database. If they have not, read them and set the delegate. This method used to be synchronized, which caused deadlock.
-
getDelegateObject
public java.lang.Object getDelegateObject()
INTERNAL: Return the real collection object. This will force instantiation.- Specified by:
getDelegateObjectin interfaceIndirectCollection
-
getValueHolder
public ValueHolderInterface getValueHolder()
INTERNAL: Return the valueHolder. This method used to be synchronized, which caused deadlock.- Specified by:
getValueHolderin interfaceIndirectContainer- Returns:
- org.eclipse.persistence.indirection.ValueHolderInterface A representation of the valueholder * which this container uses
-
hasBeenRegistered
public boolean hasBeenRegistered()
INTERNAL: return whether this IndirectList has been registered with the UnitOfWork
-
hashCode
public int hashCode()
INTERNAL:
-
indexOf
public int indexOf(java.lang.Object elem)
-
indexOf
public int indexOf(java.lang.Object elem, int index)- Overrides:
indexOfin classjava.util.Vector<E>- See Also:
Vector.indexOf(java.lang.Object, int)
-
insertElementAt
public void insertElementAt(E obj, int index)
- Overrides:
insertElementAtin classjava.util.Vector<E>- See Also:
Vector.insertElementAt(java.lang.Object, int)
-
isEmpty
public boolean isEmpty()
-
isInstantiated
public boolean isInstantiated()
PUBLIC: Return whether the contents have been read from the database.- Specified by:
isInstantiatedin interfaceIndirectContainer
-
iterator
public java.util.Iterator<E> iterator()
-
lastElement
public E lastElement()
- Overrides:
lastElementin classjava.util.Vector<E>- See Also:
Vector.lastElement()
-
lastIndexOf
public int lastIndexOf(java.lang.Object elem)
-
lastIndexOf
public int lastIndexOf(java.lang.Object elem, int index)- Overrides:
lastIndexOfin classjava.util.Vector<E>- See Also:
Vector.lastIndexOf(java.lang.Object, int)
-
listIterator
public java.util.ListIterator<E> listIterator()
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
-
remove
public E remove(int index)
-
remove
public boolean remove(java.lang.Object element)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
removeAllElements
public void removeAllElements()
- Overrides:
removeAllElementsin classjava.util.Vector<E>- See Also:
Vector.removeAllElements()
-
removeElement
public boolean removeElement(java.lang.Object obj)
- Overrides:
removeElementin classjava.util.Vector<E>- See Also:
Vector.removeElement(java.lang.Object)
-
removeElementAt
public void removeElementAt(int index)
- Overrides:
removeElementAtin classjava.util.Vector<E>- See Also:
Vector.removeElementAt(int)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
setElementAt
public void setElementAt(E obj, int index)
- Overrides:
setElementAtin classjava.util.Vector<E>- See Also:
Vector.setElementAt(java.lang.Object, int)
-
setSize
public void setSize(int newSize)
- Overrides:
setSizein classjava.util.Vector<E>- See Also:
Vector.setSize(int)
-
setUseLazyInstantiation
public void setUseLazyInstantiation(boolean useLazyInstantiation)
INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dB- Specified by:
setUseLazyInstantiationin interfaceIndirectCollection
-
setValueHolder
public void setValueHolder(ValueHolderInterface valueHolder)
INTERNAL: Set the value holder.- Specified by:
setValueHolderin interfaceIndirectContainer
-
size
public int size()
-
shouldUseLazyInstantiation
protected boolean shouldUseLazyInstantiation()
Return whether this collection should attempt do deal with adds and removes without retrieving the collection from the dB- Returns:
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
spliterator
public java.util.Spliterator<E> spliterator()
-
replaceAll
public void replaceAll(java.util.function.UnaryOperator<E> operator)
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
-
forEach
public void forEach(java.util.function.Consumer<? super E> action)
-
parallelStream
public java.util.stream.Stream<E> parallelStream()
- Specified by:
parallelStreamin interfacejava.util.Collection<E>
-
stream
public java.util.stream.Stream<E> stream()
- Specified by:
streamin interfacejava.util.Collection<E>
-
sort
public void sort(java.util.Comparator<? super E> c)
-
toString
public java.lang.String toString()
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.- Overrides:
toStringin classjava.util.Vector<E>- See Also:
Vector.toString()
-
trimToSize
public void trimToSize()
- Overrides:
trimToSizein classjava.util.Vector<E>- See Also:
Vector.trimToSize()
-
_persistence_getPropertyChangeListener
public java.beans.PropertyChangeListener _persistence_getPropertyChangeListener()
INTERNAL: Return the property change listener for change tracking.- Specified by:
_persistence_getPropertyChangeListenerin interfaceChangeTracker
-
hasTrackedPropertyChangeListener
public boolean hasTrackedPropertyChangeListener()
INTERNAL: Return if the collection has a property change listener for change tracking.
-
_persistence_setPropertyChangeListener
public void _persistence_setPropertyChangeListener(java.beans.PropertyChangeListener changeListener)
INTERNAL: Set the property change listener for change tracking.- Specified by:
_persistence_setPropertyChangeListenerin interfaceChangeTracker
-
getTrackedAttributeName
public java.lang.String getTrackedAttributeName()
INTERNAL: Return the mapping attribute name, used to raise change events.- Specified by:
getTrackedAttributeNamein interfaceCollectionChangeTracker
-
setTrackedAttributeName
public void setTrackedAttributeName(java.lang.String attributeName)
INTERNAL: Set the mapping attribute name, used to raise change events. This is required if the change listener is set.- Specified by:
setTrackedAttributeNamein interfaceCollectionChangeTracker
-
getRemovedElements
public java.util.Collection<E> getRemovedElements()
INTERNAL: Return the elements that have been removed before instantiation.- Specified by:
getRemovedElementsin interfaceIndirectCollection
-
getAddedElements
public java.util.Collection<E> getAddedElements()
INTERNAL: Return the elements that have been added before instantiation.- Specified by:
getAddedElementsin interfaceIndirectCollection
-
hasAddedElements
public boolean hasAddedElements()
INTERNAL: Return if any elements that have been added before instantiation.
-
hasRemovedElements
public boolean hasRemovedElements()
INTERNAL: Return if any elements that have been removed before instantiation.
-
hasDeferredChanges
public boolean hasDeferredChanges()
INTERNAL: Return if any elements that have been added or removed before instantiation.- Specified by:
hasDeferredChangesin interfaceIndirectCollection
-
shouldAvoidInstantiation
protected boolean shouldAvoidInstantiation()
INTERNAL: Return if add/remove should trigger instantiation or avoid. Current instantiation is avoided is using change tracking.
-
usesListOrderField
protected boolean usesListOrderField()
INTERNAL: Returns whether the mapping has listOrderField.
-
isListOrderBrokenInDb
public boolean isListOrderBrokenInDb()
-
setIsListOrderBrokenInDb
public void setIsListOrderBrokenInDb(boolean isBroken)
-
-