Package org.apache.openjpa.util
Class AbstractLRSProxyMap<K,V>
- java.lang.Object
-
- org.apache.openjpa.util.AbstractLRSProxyMap<K,V>
-
- All Implemented Interfaces:
java.util.function.Predicate
,java.util.Map<K,V>
,ChangeTracker
,LRSProxy
,MapChangeTracker
,Proxy
public abstract class AbstractLRSProxyMap<K,V> extends java.lang.Object implements java.util.Map<K,V>, LRSProxy, MapChangeTracker, java.util.function.Predicate
A map proxy designed for maps backed by extremely large result sets in which each call toget(java.lang.Object)
orcontainsKey(java.lang.Object)
may perform a database query. Changes to the map are tracked through aChangeTracker
. This map has the following limitations:- The
size
method may returnInteger.MAX_VALUE
. - Null keys and values are not supported.
- Author:
- Abe White
-
-
Constructor Summary
Constructors Constructor Description AbstractLRSProxyMap(java.lang.Class<K> keyType, java.lang.Class<V> valueType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
added(java.lang.Object key, java.lang.Object val)
Record that the given entry was added to the map.void
changed(java.lang.Object key, java.lang.Object orig, java.lang.Object val)
Record that the given entry was altered.void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object val)
java.lang.Object
copy(java.lang.Object orig)
Return an unproxied copy of the given instance.protected abstract int
count()
Return the number of entries in the map, orInteger.MAX_VALUE
.java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
V
get(java.lang.Object key)
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.boolean
getTrackKeys()
Whether to track keys or values.protected abstract boolean
hasKey(java.lang.Object key)
Return whether the given key exists in the map.protected abstract boolean
hasValue(java.lang.Object value)
Return whether the given value exists in the map.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.protected abstract java.util.Iterator<?>
itr()
Implement this method to return an iterator over the entries in the map.protected abstract java.util.Collection<K>
keys(java.lang.Object value)
Return all keys for the given value.java.util.Set<K>
keySet()
V
put(K key, V value)
void
putAll(java.util.Map<? extends K,? extends V> m)
V
remove(java.lang.Object key)
void
removed(java.lang.Object key, java.lang.Object val)
Record that the given entry was removed from the map.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.void
setTrackKeys(boolean keys)
Whether to track keys or values.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(java.lang.Object obj)
protected abstract V
value(java.lang.Object key)
Return the value of the given key.java.util.Collection<V>
values()
protected java.lang.Object
writeReplace()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
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 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.
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object val)
-
values
public java.util.Collection<V> values()
-
writeReplace
protected java.lang.Object writeReplace() throws java.io.ObjectStreamException
- Throws:
java.io.ObjectStreamException
-
hasKey
protected abstract boolean hasKey(java.lang.Object key)
Return whether the given key exists in the map.
-
hasValue
protected abstract boolean hasValue(java.lang.Object value)
Return whether the given value exists in the map.
-
keys
protected abstract java.util.Collection<K> keys(java.lang.Object value)
Return all keys for the given value.
-
value
protected abstract V value(java.lang.Object key)
Return the value of the given key.
-
itr
protected abstract java.util.Iterator<?> itr()
Implement this method to return an iterator over the entries in the map. Each returned object must implement theMap.Entry
interface. This method may be invoked multiple times. The iterator does not have to support theIterator.remove()
method, and may implementCloseable
.
-
count
protected abstract int count()
Return the number of entries in the map, orInteger.MAX_VALUE
.
-
test
public boolean test(java.lang.Object obj)
- Specified by:
test
in interfacejava.util.function.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 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
-
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 interfaceMapChangeTracker
-
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 interfaceMapChangeTracker
-
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 interfaceChangeTracker
-
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 interfaceChangeTracker
-
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 interfaceChangeTracker
-
added
public void added(java.lang.Object key, java.lang.Object val)
Description copied from interface:MapChangeTracker
Record that the given entry was added to the map.- Specified by:
added
in interfaceMapChangeTracker
-
removed
public void removed(java.lang.Object key, java.lang.Object val)
Description copied from interface:MapChangeTracker
Record that the given entry was removed from the map.- Specified by:
removed
in interfaceMapChangeTracker
-
changed
public void changed(java.lang.Object key, java.lang.Object orig, java.lang.Object val)
Description copied from interface:MapChangeTracker
Record that the given entry was altered.- Specified by:
changed
in interfaceMapChangeTracker
-
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
-
-