Class AbstractLRSProxyMap<K,V>

java.lang.Object
org.apache.openjpa.util.AbstractLRSProxyMap<K,V>
All Implemented Interfaces:
Predicate, Map<K,V>, ChangeTracker, LRSProxy, MapChangeTracker, Proxy

public abstract class AbstractLRSProxyMap<K,V> extends Object implements Map<K,V>, LRSProxy, MapChangeTracker, Predicate
A map proxy designed for maps backed by extremely large result sets in which each call to get(java.lang.Object) or containsKey(java.lang.Object) may perform a database query. Changes to the map are tracked through a ChangeTracker. This map has the following limitations:
  • The size method may return Integer.MAX_VALUE.
  • Null keys and values are not supported.
Author:
Abe White
  • Constructor Details

    • AbstractLRSProxyMap

      public AbstractLRSProxyMap(Class<K> keyType, Class<V> valueType)
  • Method Details

    • 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 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.
      Specified by:
      copy in interface Proxy
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object val)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • writeReplace

      protected Object writeReplace() throws ObjectStreamException
      Throws:
      ObjectStreamException
    • hasKey

      protected abstract boolean hasKey(Object key)
      Return whether the given key exists in the map.
    • hasValue

      protected abstract boolean hasValue(Object value)
      Return whether the given value exists in the map.
    • keys

      protected abstract Collection<K> keys(Object value)
      Return all keys for the given value.
    • value

      protected abstract V value(Object key)
      Return the value of the given key.
    • itr

      protected abstract Iterator<?> itr()
      Implement this method to return an iterator over the entries in the map. Each returned object must implement the Map.Entry interface. This method may be invoked multiple times. The iterator does not have to support the Iterator.remove() method, and may implement Closeable.
    • count

      protected abstract int count()
      Return the number of entries in the map, or Integer.MAX_VALUE.
    • test

      public boolean test(Object obj)
      Specified by:
      test in interface Predicate<K>
    • 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
    • getTrackKeys

      public boolean getTrackKeys()
      Description copied from interface: MapChangeTracker
      Whether to track keys or values. Defaults to keys. If you set to values, it is assumed there is a 1-1 correlation between keys and values in this map.
      Specified by:
      getTrackKeys in interface MapChangeTracker
    • setTrackKeys

      public void setTrackKeys(boolean keys)
      Description copied from interface: MapChangeTracker
      Whether to track keys or values. Defaults to keys. If you set to values, it is assumed there is a 1-1 correlation between keys and values in this map.
      Specified by:
      setTrackKeys in interface MapChangeTracker
    • 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

      public void added(Object key, Object val)
      Description copied from interface: MapChangeTracker
      Record that the given entry was added to the map.
      Specified by:
      added in interface MapChangeTracker
    • removed

      public void removed(Object key, Object val)
      Description copied from interface: MapChangeTracker
      Record that the given entry was removed from the map.
      Specified by:
      removed in interface MapChangeTracker
    • changed

      public void changed(Object key, Object orig, Object val)
      Description copied from interface: MapChangeTracker
      Record that the given entry was altered.
      Specified by:
      changed in interface MapChangeTracker
    • 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