Package org.apache.openjpa.util
Class AbstractLRSProxyCollection
- java.lang.Object
-
- org.apache.openjpa.util.AbstractLRSProxyCollection
-
- All Implemented Interfaces:
Iterable
,Collection
,Predicate
,Set
,ChangeTracker
,CollectionChangeTracker
,LRSProxy
,Proxy
- Direct Known Subclasses:
LRSProxyCollection
public abstract class AbstractLRSProxyCollection extends Object implements Set, LRSProxy, Predicate, CollectionChangeTracker
A collection proxy designed for collections backed by extremely large result sets in which each call toiterator()
may perform a database query. Changes to the collection are tracked through aChangeTracker
. This collection has the following limitations:- The
size
method may returnInteger.MAX_VALUE
. - The collection cannot contain duplicate elements.
- Author:
- Abe White
-
-
Constructor Summary
Constructors Constructor Description AbstractLRSProxyCollection(Class elementType, boolean ordered)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
add(Object o)
boolean
addAll(Collection all)
void
added(Object val)
Record that the given element was added.void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection all)
Object
copy(Object orig)
Return an unproxied copy of the given instance.protected abstract int
count()
Return the number of elements in the collection, orInteger.MAX_VALUE
.Collection
getAdded()
Return the collection of values that need to be added to the managed container.Collection
getChanged()
Return the set of elements that have changed.ChangeTracker
getChangeTracker()
Return the change tracker for this proxy, or null if none.int
getNextSequence()
The next element sequence value for this proxy at load time.OpenJPAStateManager
getOwner()
Return the owning object.int
getOwnerField()
Return the owning field index.Collection
getRemoved()
Return the set of values that need to be removed from the managed container.protected abstract boolean
has(Object o)
Return whether the collection contains the given element.boolean
isEmpty()
boolean
isTracking()
Return true if this tracker has an up-to-date view of all the changes to the container it is managing.Iterator
iterator()
protected abstract Iterator
itr()
Implement this method to return an iterator over the contents of the collection.boolean
remove(Object o)
boolean
removeAll(Collection all)
void
removed(Object val)
Record that the given element was removed.boolean
retainAll(Collection all)
void
setNextSequence(int seq)
The maximum element sequence value for this proxy at load time.void
setOwner(OpenJPAStateManager sm, int field)
Reset the state of the proxy, and set the owning instance of the proxy and the name of the field it is assigned to.int
size()
void
startTracking()
Reset the state of the change tracker, and turn change tracking back on if it has been disabled.void
stopTracking()
Tell the tracker to stop tracking changes for its container.boolean
test(Object o)
Object[]
toArray()
Object[]
toArray(Object[] a)
protected Object
writeReplace()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Constructor Detail
-
AbstractLRSProxyCollection
public AbstractLRSProxyCollection(Class elementType, boolean ordered)
Constructor.- Parameters:
elementType
- the allowed type of elements, or null for no restrictionsordered
- true if this collection is ordered
-
-
Method Detail
-
setOwner
public void setOwner(OpenJPAStateManager sm, int field)
Description copied from interface:Proxy
Reset the state of the proxy, and set the owning instance of the proxy and the name of the field it is assigned to. Set to null to indicate that the proxy is no longer managed.
-
getOwner
public OpenJPAStateManager getOwner()
Description copied from interface:Proxy
Return the owning object.
-
getOwnerField
public int getOwnerField()
Description copied from interface:Proxy
Return the owning field index.- Specified by:
getOwnerField
in interfaceProxy
-
getChangeTracker
public ChangeTracker getChangeTracker()
Description copied from interface:Proxy
Return the change tracker for this proxy, or null if none.- Specified by:
getChangeTracker
in interfaceProxy
-
copy
public Object copy(Object orig)
Description copied from interface:Proxy
Return an unproxied copy of the given instance. This method is used by proxy managers to create backup values for use in rollback.
-
add
public boolean add(Object o)
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceSet
-
addAll
public boolean addAll(Collection all)
- Specified by:
addAll
in interfaceCollection
- Specified by:
addAll
in interfaceSet
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection
- Specified by:
remove
in interfaceSet
-
removeAll
public boolean removeAll(Collection all)
- Specified by:
removeAll
in interfaceCollection
- Specified by:
removeAll
in interfaceSet
-
retainAll
public boolean retainAll(Collection all)
- Specified by:
retainAll
in interfaceCollection
- Specified by:
retainAll
in interfaceSet
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceSet
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceSet
-
containsAll
public boolean containsAll(Collection all)
- Specified by:
containsAll
in interfaceCollection
- Specified by:
containsAll
in interfaceSet
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
toArray
public Object[] toArray(Object[] a)
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
size
public int size()
- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceSet
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection
- Specified by:
isEmpty
in interfaceSet
-
iterator
public Iterator iterator()
-
writeReplace
protected Object writeReplace() throws ObjectStreamException
- Throws:
ObjectStreamException
-
itr
protected abstract Iterator itr()
Implement this method to return an iterator over the contents of the collection. This method may be invoked multiple times. The returned iterator does not have to support theIterator.remove()
method, and may implementCloseable
.
-
has
protected abstract boolean has(Object o)
Return whether the collection contains the given element.
-
count
protected abstract int count()
Return the number of elements in the collection, orInteger.MAX_VALUE
.
-
isTracking
public boolean isTracking()
Description copied from interface:ChangeTracker
Return true if this tracker has an up-to-date view of all the changes to the container it is managing.- Specified by:
isTracking
in interfaceChangeTracker
-
startTracking
public void startTracking()
Description copied from interface:ChangeTracker
Reset the state of the change tracker, and turn change tracking back on if it has been disabled.- Specified by:
startTracking
in interfaceChangeTracker
-
stopTracking
public void stopTracking()
Description copied from interface:ChangeTracker
Tell the tracker to stop tracking changes for its container.- Specified by:
stopTracking
in interfaceChangeTracker
-
getAdded
public Collection getAdded()
Description copied from interface:ChangeTracker
Return the collection of values that need to be added to the managed container.- Specified by:
getAdded
in interfaceChangeTracker
-
getRemoved
public Collection getRemoved()
Description copied from interface:ChangeTracker
Return the set of values that need to be removed from the managed container.- Specified by:
getRemoved
in interfaceChangeTracker
-
getChanged
public Collection getChanged()
Description copied from interface:ChangeTracker
Return the set of elements that have changed. In maps, this marks a possible change in value for a key. In collections, this marks an element that has been removed and re-added.- Specified by:
getChanged
in interfaceChangeTracker
-
added
public void added(Object val)
Description copied from interface:CollectionChangeTracker
Record that the given element was added.- Specified by:
added
in interfaceCollectionChangeTracker
-
removed
public void removed(Object val)
Description copied from interface:CollectionChangeTracker
Record that the given element was removed.- Specified by:
removed
in interfaceCollectionChangeTracker
-
getNextSequence
public int getNextSequence()
Description copied from interface:ChangeTracker
The next element sequence value for this proxy at load time. If the data store keeps this proxy's data in sequence order but allows holes for removed objects, the implementation can set the next sequence at load time, then retrieve it and start from there for added objects at flush time. This value is set back to 0 if the proxy stops tracking changes. For ordered proxies, it is set to the proxy's size when the proxy starts tracking changes again.- Specified by:
getNextSequence
in interfaceChangeTracker
-
setNextSequence
public void setNextSequence(int seq)
Description copied from interface:ChangeTracker
The maximum element sequence value for this proxy at load time. If the data store keeps this proxy's data in sequence order but allows holes for removed objects, the implementation can set the next sequence at load time, then retrieve it and start from there for added objects at flush time. This value is set back to 0 if the proxy stops tracking changes. For ordered proxies, it is set to the proxy's size when the proxy starts tracking changes again.- Specified by:
setNextSequence
in interfaceChangeTracker
-
-