Class AbstractChangeTracker

java.lang.Object
org.apache.openjpa.util.AbstractChangeTracker
All Implemented Interfaces:
ChangeTracker
Direct Known Subclasses:
CollectionChangeTrackerImpl, MapChangeTrackerImpl

public abstract class AbstractChangeTracker extends Object implements ChangeTracker
Base class that provides utilities to change trackers.
Author:
Abe White
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Collection
    Collection of added items.
    protected Collection
    Collection of changed items.
    protected Collection
    Collection of removed items.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor; supply configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    add(Object val)
    Mark the given value as added.
    protected void
    Notify the tracker that the given object was added.
    protected abstract void
    Mark the given value as changed.
    protected void
    Notify the tracker that the given object was changed.
    Return the collection of values that need to be added to the managed container.
    boolean
    Whether to automatically stop tracking when the number of changes exceeds the container size.
    Return the set of elements that have changed.
    int
    The next element sequence value for this proxy at load time.
    Return the set of values that need to be removed from the managed container.
    protected int
    Return the initial sequence value for this proxy.
    boolean
    Return true if this tracker has an up-to-date view of all the changes to the container it is managing.
    protected Set
    Create a new set for storing adds/removes/changes.
    protected abstract void
    Mark the given value as removed.
    protected void
    Notify the tracker that the given object was removed.
    protected void
    Reset the state of the tracker.
    void
    setAutoOff(boolean autoOff)
    Whether to automatically stop tracking when the number of changes exceeds the container size.
    void
    setNextSequence(int seq)
    The maximum element sequence value for this proxy at load time.
    void
    Reset the state of the change tracker, and turn change tracking back on if it has been disabled.
    void
    Tell the tracker to stop tracking changes for its container.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • add

      protected Collection add
      Collection of added items. May be null.
    • rem

      protected Collection rem
      Collection of removed items. May be null.
    • change

      protected Collection change
      Collection of changed items. May be null.
  • Constructor Details

    • AbstractChangeTracker

      public AbstractChangeTracker()
      Constructor; supply configuration.
  • Method Details

    • getAutoOff

      public boolean getAutoOff()
      Whether to automatically stop tracking when the number of changes exceeds the container size. Defaults to true.
    • setAutoOff

      public void setAutoOff(boolean autoOff)
      Whether to automatically stop tracking when the number of changes exceeds the container size. Defaults to true.
    • 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
    • initialSequence

      protected int initialSequence()
      Return the initial sequence value for this proxy. Typically this is the container size. Assumes an unordered collection by default, returning 0.
    • 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
    • reset

      protected void reset()
      Reset the state of the tracker.
    • 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 interface ChangeTracker
    • 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 interface ChangeTracker
    • 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 interface ChangeTracker
    • added

      protected void added(Object val)
      Notify the tracker that the given object was added.
    • add

      protected abstract void add(Object val)
      Mark the given value as added.
    • removed

      protected void removed(Object val)
      Notify the tracker that the given object was removed.
    • remove

      protected abstract void remove(Object val)
      Mark the given value as removed.
    • changed

      protected void changed(Object val)
      Notify the tracker that the given object was changed.
    • change

      protected abstract void change(Object val)
      Mark the given value as changed.
    • 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
    • newSet

      protected Set newSet()
      Create a new set for storing adds/removes/changes. Takes into account whether we need to use an identity set or standard set.