org.apache.openjpa.util
Class AbstractLRSProxyCollection

java.lang.Object
  extended by org.apache.openjpa.util.AbstractLRSProxyCollection
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.Set, org.apache.commons.collections.Predicate, ChangeTracker, CollectionChangeTracker, LRSProxy, Proxy

public abstract class AbstractLRSProxyCollection
extends java.lang.Object
implements java.util.Set, LRSProxy, org.apache.commons.collections.Predicate, CollectionChangeTracker

A collection proxy designed for collections backed by extremely large result sets in which each call to iterator() may perform a database query. Changes to the collection are tracked through a ChangeTracker. This collection has the following limitations:

Author:
Abe White

Constructor Summary
AbstractLRSProxyCollection(java.lang.Class elementType, boolean ordered, OpenJPAConfiguration conf)
          Constructor.
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection all)
           
 void added(java.lang.Object val)
          Record that the given element was added.
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection all)
           
 java.lang.Object copy(java.lang.Object orig)
          Return an unproxied copy of the given instance.
protected abstract  int count()
          Return the number of elements in the collection, or Integer.MAX_VALUE.
 boolean evaluate(java.lang.Object o)
           
 java.util.Collection getAdded()
          Return the collection of values that need to be added to the managed container.
 java.util.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.
 java.util.Collection getRemoved()
          Return the set of values that need to be removed from the managed container.
protected abstract  boolean has(java.lang.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.
 java.util.Iterator iterator()
           
protected abstract  java.util.Iterator itr()
          Implement this method to return an iterator over the contents of the collection.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection all)
           
 void removed(java.lang.Object val)
          Record that the given element was removed.
 boolean retainAll(java.util.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.
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
protected  java.lang.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.Set
equals, hashCode
 

Constructor Detail

AbstractLRSProxyCollection

public AbstractLRSProxyCollection(java.lang.Class elementType,
                                  boolean ordered,
                                  OpenJPAConfiguration conf)
Constructor.

Parameters:
elementType - the allowed type of elements, or null for no restrictions
ordered - 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.

Specified by:
setOwner in interface Proxy

getOwner

public OpenJPAStateManager getOwner()
Description copied from interface: Proxy
Return the owning object.

Specified by:
getOwner in interface Proxy

getOwnerField

public int getOwnerField()
Description copied from interface: Proxy
Return the owning field index.

Specified by:
getOwnerField in interface Proxy

getChangeTracker

public ChangeTracker getChangeTracker()
Description copied from interface: Proxy
Return the change tracker for this proxy, or null if none.

Specified by:
getChangeTracker in interface Proxy

copy

public java.lang.Object copy(java.lang.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.

Specified by:
copy in interface Proxy

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set

addAll

public boolean addAll(java.util.Collection all)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set

removeAll

public boolean removeAll(java.util.Collection all)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.Set

retainAll

public boolean retainAll(java.util.Collection all)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.Set

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection all)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.Set

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.Set

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set

writeReplace

protected java.lang.Object writeReplace()
                                 throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

itr

protected abstract java.util.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 the Iterator.remove() method, and may implement Closeable.


has

protected abstract boolean has(java.lang.Object o)
Return whether the collection contains the given element.


count

protected abstract int count()
Return the number of elements in the collection, or Integer.MAX_VALUE.


evaluate

public boolean evaluate(java.lang.Object o)
Specified by:
evaluate in interface org.apache.commons.collections.Predicate

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 interface ChangeTracker

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 interface ChangeTracker

stopTracking

public void stopTracking()
Description copied from interface: ChangeTracker
Tell the tracker to stop tracking changes for its container.

Specified by:
stopTracking in interface ChangeTracker

getAdded

public java.util.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 interface ChangeTracker

getRemoved

public java.util.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 interface ChangeTracker

getChanged

public java.util.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 interface ChangeTracker

added

public void added(java.lang.Object val)
Description copied from interface: CollectionChangeTracker
Record that the given element was added.

Specified by:
added in interface CollectionChangeTracker

removed

public void removed(java.lang.Object val)
Description copied from interface: CollectionChangeTracker
Record that the given element was removed.

Specified by:
removed in interface CollectionChangeTracker

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 interface ChangeTracker

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 interface ChangeTracker


Copyright © 2006 Apache Software Foundation. All Rights Reserved.