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:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
,ChangeTracker
,CollectionChangeTracker
,IndirectCollection<E,List<E>>
,IndirectContainer<List<E>>
public class IndirectList<E> extends Vector<E> implements CollectionChangeTracker, IndirectCollection<E,List<E>>
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 Vector<E>
delegate
Reduce type casting.protected int
initialCapacity
Store initial size for lazy init.protected boolean
isRegistered
PERF: Quick check flag if has been registered in a unit of work.protected ValueHolderInterface<List<E>>
valueHolder
Delegate indirection behavior to a value holder.-
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description IndirectList()
PUBLIC: Construct an empty IndirectList so that its internal data array has size10
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(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 PropertyChangeListener
_persistence_getPropertyChangeListener()
INTERNAL: Return the property change listener for change tracking.void
_persistence_setPropertyChangeListener(PropertyChangeListener changeListener)
INTERNAL: Set the property change listener for change tracking.void
add(int index, E element)
boolean
add(E element)
boolean
addAll(int index, Collection<? extends E> c)
boolean
addAll(Collection<? extends E> c)
void
addElement(E obj)
protected Vector<E>
buildDelegate()
INTERNAL: Return the freshly-built delegate.int
capacity()
void
clear()
void
clearDeferredChanges()
INTERNAL: clear any changes that have been deferred to instantiation.Object
clone()
PUBLIC:boolean
contains(Object element)
PUBLIC:boolean
containsAll(Collection<?> c)
void
copyInto(Object[] anArray)
E
elementAt(int index)
Enumeration<E>
elements()
void
ensureCapacity(int minCapacity)
boolean
equals(Object o)
E
firstElement()
void
forEach(Consumer<? super E> action)
E
get(int index)
List<E>
getAddedElements()
INTERNAL: Return the elements that have been added before instantiation.protected Vector<E>
getDelegate()
INTERNAL: Check whether the contents have been read from the database.List<E>
getDelegateObject()
INTERNAL: Return the real collection object.List<E>
getRemovedElements()
INTERNAL: Return the elements that have been removed before instantiation.String
getTrackedAttributeName()
INTERNAL: Return the mapping attribute name, used to raise change events.ValueHolderInterface<List<E>>
getValueHolder()
INTERNAL: Return the valueHolder.boolean
hasAddedElements()
INTERNAL: Return if any elements that have been added before instantiation.boolean
hasBeenRegistered()
INTERNAL: return whether this IndirectList has been registered with the UnitOfWorkboolean
hasDeferredChanges()
INTERNAL: Return if any elements that have been added or removed before instantiation.int
hashCode()
INTERNAL:boolean
hasRemovedElements()
INTERNAL: Return if any elements that have been removed before instantiation.boolean
hasTrackedPropertyChangeListener()
INTERNAL: Return if the collection has a property change listener for change tracking.int
indexOf(Object elem)
int
indexOf(Object elem, int index)
void
insertElementAt(E obj, int index)
boolean
isEmpty()
boolean
isInstantiated()
PUBLIC: Return whether the contents have been read from the database.boolean
isListOrderBrokenInDb()
protected boolean
isRelationshipMaintenanceRequired()
Iterator<E>
iterator()
E
lastElement()
int
lastIndexOf(Object elem)
int
lastIndexOf(Object elem, int index)
ListIterator<E>
listIterator()
ListIterator<E>
listIterator(int index)
Stream<E>
parallelStream()
protected void
raiseAddChangeEvent(E element, Integer index)
Raise the add change event and relationship maintenance.protected void
raiseAddChangeEvent(E element, Integer index, boolean isSet)
protected void
raiseRemoveChangeEvent(Object element, Integer index)
Raise the remove change event.protected void
raiseRemoveChangeEvent(Object element, Integer index, boolean isSet)
E
remove(int index)
boolean
remove(Object element)
boolean
removeAll(Collection<?> c)
void
removeAllElements()
boolean
removeElement(Object obj)
void
removeElementAt(int index)
boolean
removeIf(Predicate<? super E> filter)
void
replaceAll(UnaryOperator<E> operator)
boolean
retainAll(Collection<?> c)
E
set(int index, E element)
void
setElementAt(E obj, int index)
void
setIsListOrderBrokenInDb(boolean isBroken)
void
setSize(int newSize)
void
setTrackedAttributeName(String attributeName)
INTERNAL: Set the mapping attribute name, used to raise change events.void
setUseLazyInstantiation(boolean useLazyInstantiation)
INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBvoid
setValueHolder(ValueHolderInterface<List<E>> valueHolder)
INTERNAL: Set the value holder.protected boolean
shouldAvoidInstantiation()
INTERNAL: Return if add/remove should trigger instantiation or avoid.protected boolean
shouldUseLazyInstantiation()
Return whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBint
size()
void
sort(Comparator<? super E> c)
Spliterator<E>
spliterator()
Stream<E>
stream()
List<E>
subList(int fromIndex, int toIndex)
Object[]
toArray()
<T> T[]
toArray(T[] a)
String
toString()
PUBLIC: Use the java.util.Vector#toString(); but wrap it with braces to indicate there is a bit of indirection.void
trimToSize()
protected boolean
usesListOrderField()
INTERNAL: Returns whether the mapping has listOrderField.-
Methods inherited from class java.util.Vector
removeRange
-
-
-
-
Field Detail
-
valueHolder
protected volatile ValueHolderInterface<List<E>> 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 size10
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:
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:
IllegalArgumentException
- if the specified initial capacity is negative
-
IndirectList
public IndirectList(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(E element, Integer index)
Raise the add change event and relationship maintenance.
-
isRelationshipMaintenanceRequired
protected boolean isRelationshipMaintenanceRequired()
-
raiseRemoveChangeEvent
protected void raiseRemoveChangeEvent(Object element, Integer index)
Raise the remove change event.
-
raiseRemoveChangeEvent
protected void raiseRemoveChangeEvent(Object element, Integer index, boolean isSet)
-
add
public boolean add(E element)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classVector<E>
- See Also:
Vector.add(java.lang.Object)
-
addAll
public boolean addAll(int index, Collection<? extends E> c)
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classVector<E>
- See Also:
Vector.addAll(java.util.Collection)
-
addElement
public void addElement(E obj)
- Overrides:
addElement
in classVector<E>
- See Also:
Vector.addElement(java.lang.Object)
-
capacity
public int capacity()
- Overrides:
capacity
in classVector<E>
- See Also:
Vector.capacity()
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classVector<E>
- See Also:
Vector.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:
clearDeferredChanges
in interfaceIndirectCollection<E,List<E>>
-
clone
public Object clone()
PUBLIC:- Overrides:
clone
in classVector<E>
- See Also:
This will result in a database query if necessary.
-
contains
public boolean contains(Object element)
PUBLIC:- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classVector<E>
- See Also:
Vector.contains(java.lang.Object)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Overrides:
containsAll
in classVector<E>
- See Also:
Vector.containsAll(java.util.Collection)
-
copyInto
public void copyInto(Object[] anArray)
- Overrides:
copyInto
in classVector<E>
- See Also:
Vector.copyInto(java.lang.Object[])
-
elementAt
public E elementAt(int index)
- Overrides:
elementAt
in classVector<E>
- See Also:
Vector.elementAt(int)
-
elements
public Enumeration<E> elements()
- Overrides:
elements
in classVector<E>
- See Also:
Vector.elements()
-
ensureCapacity
public void ensureCapacity(int minCapacity)
- Overrides:
ensureCapacity
in classVector<E>
- See Also:
Vector.ensureCapacity(int)
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classVector<E>
- See Also:
Vector.equals(java.lang.Object)
-
firstElement
public E firstElement()
- Overrides:
firstElement
in classVector<E>
- See Also:
Vector.firstElement()
-
get
public E get(int index)
-
getDelegate
protected 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 List<E> getDelegateObject()
INTERNAL: Return the real collection object. This will force instantiation.- Specified by:
getDelegateObject
in interfaceIndirectCollection<E,List<E>>
-
getValueHolder
public ValueHolderInterface<List<E>> getValueHolder()
INTERNAL: Return the valueHolder. This method used to be synchronized, which caused deadlock.- Specified by:
getValueHolder
in interfaceIndirectContainer<E>
- 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:- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classVector<E>
- See Also:
Vector.hashCode()
-
indexOf
public int indexOf(Object elem)
-
indexOf
public int indexOf(Object elem, int index)
- Overrides:
indexOf
in classVector<E>
- See Also:
Vector.indexOf(java.lang.Object, int)
-
insertElementAt
public void insertElementAt(E obj, int index)
- Overrides:
insertElementAt
in classVector<E>
- See Also:
Vector.insertElementAt(java.lang.Object, int)
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classVector<E>
- See Also:
Vector.isEmpty()
-
isInstantiated
public boolean isInstantiated()
PUBLIC: Return whether the contents have been read from the database.- Specified by:
isInstantiated
in interfaceIndirectContainer<E>
-
lastElement
public E lastElement()
- Overrides:
lastElement
in classVector<E>
- See Also:
Vector.lastElement()
-
lastIndexOf
public int lastIndexOf(Object elem)
- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classVector<E>
- See Also:
Vector.lastIndexOf(java.lang.Object)
-
lastIndexOf
public int lastIndexOf(Object elem, int index)
- Overrides:
lastIndexOf
in classVector<E>
- See Also:
Vector.lastIndexOf(java.lang.Object, int)
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classVector<E>
- See Also:
AbstractList.listIterator()
-
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classVector<E>
- See Also:
AbstractList.listIterator(int)
-
remove
public E remove(int index)
-
remove
public boolean remove(Object element)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classVector<E>
- See Also:
Vector.remove(java.lang.Object)
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classVector<E>
- See Also:
Vector.removeAll(java.util.Collection)
-
removeAllElements
public void removeAllElements()
- Overrides:
removeAllElements
in classVector<E>
- See Also:
Vector.removeAllElements()
-
removeElement
public boolean removeElement(Object obj)
- Overrides:
removeElement
in classVector<E>
- See Also:
Vector.removeElement(java.lang.Object)
-
removeElementAt
public void removeElementAt(int index)
- Overrides:
removeElementAt
in classVector<E>
- See Also:
Vector.removeElementAt(int)
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classVector<E>
- See Also:
Vector.retainAll(java.util.Collection)
-
setElementAt
public void setElementAt(E obj, int index)
- Overrides:
setElementAt
in classVector<E>
- See Also:
Vector.setElementAt(java.lang.Object, int)
-
setSize
public void setSize(int newSize)
- Overrides:
setSize
in classVector<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:
setUseLazyInstantiation
in interfaceIndirectCollection<E,List<E>>
-
setValueHolder
public void setValueHolder(ValueHolderInterface<List<E>> valueHolder)
INTERNAL: Set the value holder.- Specified by:
setValueHolder
in interfaceIndirectContainer<E>
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Overrides:
size
in classVector<E>
- See Also:
Vector.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:
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classVector<E>
- See Also:
Vector.toArray()
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classVector<E>
- See Also:
Vector.toArray(java.lang.Object[])
-
spliterator
public Spliterator<E> spliterator()
- Specified by:
spliterator
in interfaceCollection<E>
- Specified by:
spliterator
in interfaceIterable<E>
- Specified by:
spliterator
in interfaceList<E>
- Overrides:
spliterator
in classVector<E>
-
replaceAll
public void replaceAll(UnaryOperator<E> operator)
- Specified by:
replaceAll
in interfaceList<E>
- Overrides:
replaceAll
in classVector<E>
-
parallelStream
public Stream<E> parallelStream()
- Specified by:
parallelStream
in interfaceCollection<E>
-
stream
public Stream<E> stream()
- Specified by:
stream
in interfaceCollection<E>
-
sort
public void sort(Comparator<? super E> c)
-
toString
public 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:
toString
in classVector<E>
- See Also:
Vector.toString()
-
trimToSize
public void trimToSize()
- Overrides:
trimToSize
in classVector<E>
- See Also:
Vector.trimToSize()
-
_persistence_getPropertyChangeListener
public PropertyChangeListener _persistence_getPropertyChangeListener()
INTERNAL: Return the property change listener for change tracking.- Specified by:
_persistence_getPropertyChangeListener
in interfaceChangeTracker
-
hasTrackedPropertyChangeListener
public boolean hasTrackedPropertyChangeListener()
INTERNAL: Return if the collection has a property change listener for change tracking.
-
_persistence_setPropertyChangeListener
public void _persistence_setPropertyChangeListener(PropertyChangeListener changeListener)
INTERNAL: Set the property change listener for change tracking.- Specified by:
_persistence_setPropertyChangeListener
in interfaceChangeTracker
-
getTrackedAttributeName
public String getTrackedAttributeName()
INTERNAL: Return the mapping attribute name, used to raise change events.- Specified by:
getTrackedAttributeName
in interfaceCollectionChangeTracker
-
setTrackedAttributeName
public void setTrackedAttributeName(String attributeName)
INTERNAL: Set the mapping attribute name, used to raise change events. This is required if the change listener is set.- Specified by:
setTrackedAttributeName
in interfaceCollectionChangeTracker
-
getRemovedElements
public List<E> getRemovedElements()
INTERNAL: Return the elements that have been removed before instantiation.- Specified by:
getRemovedElements
in interfaceIndirectCollection<E,List<E>>
-
getAddedElements
public List<E> getAddedElements()
INTERNAL: Return the elements that have been added before instantiation.- Specified by:
getAddedElements
in interfaceIndirectCollection<E,List<E>>
-
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:
hasDeferredChanges
in interfaceIndirectCollection<E,List<E>>
-
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)
-
-