Package org.apache.openjpa.util
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
sizemethod may returnInteger.MAX_VALUE. - Null keys and values are not supported.
- Author:
- Abe White
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRecord that the given entry was added to the map.voidRecord that the given entry was altered.voidclear()booleancontainsKey(Object key) booleancontainsValue(Object val) Return an unproxied copy of the given instance.protected abstract intcount()Return the number of entries in the map, orInteger.MAX_VALUE.entrySet()getAdded()Return the collection of values that need to be added to the managed container.Return the set of elements that have changed.Return the change tracker for this proxy, or null if none.intThe next element sequence value for this proxy at load time.getOwner()Return the owning object.intReturn the owning field index.Return the set of values that need to be removed from the managed container.booleanWhether to track keys or values.protected abstract booleanReturn whether the given key exists in the map.protected abstract booleanReturn whether the given value exists in the map.booleanisEmpty()booleanReturn true if this tracker has an up-to-date view of all the changes to the container it is managing.protected abstract Iterator<?>itr()Implement this method to return an iterator over the entries in the map.protected abstract Collection<K>Return all keys for the given value.keySet()voidvoidRecord that the given entry was removed from the map.voidsetNextSequence(int seq) The maximum element sequence value for this proxy at load time.voidsetOwner(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.voidsetTrackKeys(boolean keys) Whether to track keys or values.intsize()voidReset the state of the change tracker, and turn change tracking back on if it has been disabled.voidTell the tracker to stop tracking changes for its container.booleanprotected abstract VReturn the value of the given key.values()protected ObjectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
AbstractLRSProxyMap
-
-
Method Details
-
setOwner
Description copied from interface:ProxyReset 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
Description copied from interface:ProxyReturn the owning object. -
getOwnerField
public int getOwnerField()Description copied from interface:ProxyReturn the owning field index.- Specified by:
getOwnerFieldin interfaceProxy
-
getChangeTracker
Description copied from interface:ProxyReturn the change tracker for this proxy, or null if none.- Specified by:
getChangeTrackerin interfaceProxy
-
copy
Description copied from interface:ProxyReturn an unproxied copy of the given instance. This method is used by proxy managers to create backup values for use in rollback. -
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
putAll
-
remove
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
writeReplace
- Throws:
ObjectStreamException
-
hasKey
Return whether the given key exists in the map. -
hasValue
Return whether the given value exists in the map. -
keys
Return all keys for the given value. -
value
Return the value of the given key. -
itr
Implement this method to return an iterator over the entries in the map. Each returned object must implement theMap.Entryinterface. 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
-
isTracking
public boolean isTracking()Description copied from interface:ChangeTrackerReturn true if this tracker has an up-to-date view of all the changes to the container it is managing.- Specified by:
isTrackingin interfaceChangeTracker
-
startTracking
public void startTracking()Description copied from interface:ChangeTrackerReset the state of the change tracker, and turn change tracking back on if it has been disabled.- Specified by:
startTrackingin interfaceChangeTracker
-
stopTracking
public void stopTracking()Description copied from interface:ChangeTrackerTell the tracker to stop tracking changes for its container.- Specified by:
stopTrackingin interfaceChangeTracker
-
getTrackKeys
public boolean getTrackKeys()Description copied from interface:MapChangeTrackerWhether 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:
getTrackKeysin interfaceMapChangeTracker
-
setTrackKeys
public void setTrackKeys(boolean keys) Description copied from interface:MapChangeTrackerWhether 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:
setTrackKeysin interfaceMapChangeTracker
-
getAdded
Description copied from interface:ChangeTrackerReturn the collection of values that need to be added to the managed container.- Specified by:
getAddedin interfaceChangeTracker
-
getRemoved
Description copied from interface:ChangeTrackerReturn the set of values that need to be removed from the managed container.- Specified by:
getRemovedin interfaceChangeTracker
-
getChanged
Description copied from interface:ChangeTrackerReturn 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:
getChangedin interfaceChangeTracker
-
added
Description copied from interface:MapChangeTrackerRecord that the given entry was added to the map.- Specified by:
addedin interfaceMapChangeTracker
-
removed
Description copied from interface:MapChangeTrackerRecord that the given entry was removed from the map.- Specified by:
removedin interfaceMapChangeTracker
-
changed
Description copied from interface:MapChangeTrackerRecord that the given entry was altered.- Specified by:
changedin interfaceMapChangeTracker
-
getNextSequence
public int getNextSequence()Description copied from interface:ChangeTrackerThe 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:
getNextSequencein interfaceChangeTracker
-
setNextSequence
public void setNextSequence(int seq) Description copied from interface:ChangeTrackerThe 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:
setNextSequencein interfaceChangeTracker
-