Class Map<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.datanucleus.store.types.wrappers.Map<K,V>
-
- org.datanucleus.store.types.wrappers.backed.Map<K,V>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,V>
,SCO<Map<K,V>>
,SCOContainer<Map<K,V>>
,SCOMap<Map<K,V>,K,V>
,BackedSCO
public class Map<K,V> extends Map<K,V> implements BackedSCO
A mutable second-class Map object. Uses a "delegate" as a local store for the Map. Uses a "backing store" (SetStore) to represent the datastore. The "delegate" is updated with the "backing store" information at necessary intervals.Modes of Operation
The user can operate the map in 2 modes. The cached mode will use an internal cache of the elements (in the "delegate") reading them at the first opportunity and then using the cache thereafter. The non-cached mode will just go direct to the "backing store" each call.Mutators
When the backing store is present any updates are passed direct to the datastore as well as to the "delegate". If the "backing store" isn't present the changes are made to the "delegate" only.Accessors
When any accessor method is invoked, it typically checks whether the map has been loaded from its backing store and does this as necessary. Some methods (size(), containsKey()) just check if everything is loaded and use the delegate if possible, otherwise going direct to the datastore.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowNulls
protected MapStore<K,V>
backingStore
protected boolean
isCacheLoaded
protected boolean
useCache
-
Constructor Summary
Constructors Constructor Description Map(DNStateManager sm, AbstractMemberMetaData mmd)
Constructor, using StateManager of the "owner" and the field name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Method to clear the Map.Object
clone()
Creates and returns a copy of this object.boolean
containsKey(Object key)
Utility to check if a key is contained in the Map.boolean
containsValue(Object value)
Utility to check if a value is contained in the Map.Set
entrySet()
Accessor for the set of entries in the Map.boolean
equals(Object o)
Method to check the equality of this map, and another.void
forEach(BiConsumer<? super K,? super V> action)
V
get(Object key)
Accessor for the value stored against a key.Store
getBackingStore()
Map
getValue()
Accessor for the unwrapped value that we are wrapping.int
hashCode()
Method to generate a hashcode for this Map.void
initialise()
Method to initialise the SCO for use.void
initialise(Map m)
Method to initialise the SCO from an existing value.void
initialise(Map newValue, Object oldValue)
Method to initialise the SCO for use, where replacing an old value with a new value such as when calling a setter field passing in a new value.boolean
isEmpty()
Method to return if the Map is empty.boolean
isLoaded()
Method to return if the SCO has its contents loaded.Set
keySet()
Accessor for the set of keys in the Map.void
load()
Method to effect the load of the data in the SCO.protected void
loadFromStore()
Method to load all elements from the "backing store" where appropriate.V
put(K key, V value)
Method to add a value to the Map.void
putAll(Map m)
Method to add a Map of values to this map.V
remove(Object key)
Method to remove a value from the Map.int
size()
Method to return the size of the Map.String
toString()
Method to return a string form of this Map.void
unsetOwner()
Method to unset the owner and field information.void
updateEmbeddedKey(K key, int fieldNumber, Object newValue, boolean makeDirty)
Method to update an embedded key in this map.void
updateEmbeddedValue(V value, int fieldNumber, Object newValue, boolean makeDirty)
Method to update an embedded value in this map.Collection
values()
Accessor for the set of values in the Map.protected Object
writeReplace()
The writeReplace method is called when ObjectOutputStream is preparing to write the object to the stream.-
Methods inherited from class org.datanucleus.store.types.wrappers.Map
attachCopy, detachCopy, getFieldName, getOwner, makeDirty, setValue
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
Map
public Map(DNStateManager sm, AbstractMemberMetaData mmd)
Constructor, using StateManager of the "owner" and the field name.- Parameters:
sm
- The owner StateManagermmd
- Metadata for the member
-
-
Method Detail
-
initialise
public void initialise(Map newValue, Object oldValue)
Description copied from interface:SCO
Method to initialise the SCO for use, where replacing an old value with a new value such as when calling a setter field passing in a new value. Note that oldValue is marked as Object since for cases where the member type is Collection the newValue could be, for example, ArrayList, and the oldValue of type Collection (representing null).- Specified by:
initialise
in interfaceSCO<K>
- Overrides:
initialise
in classMap<K,V>
- Parameters:
newValue
- New value (to wrap)oldValue
- Old value (to use in deciding what needs deleting etc)
-
initialise
public void initialise(Map m)
Method to initialise the SCO from an existing value.- Specified by:
initialise
in interfaceSCO<K>
- Overrides:
initialise
in classMap<K,V>
- Parameters:
m
- The object to set from
-
initialise
public void initialise()
Method to initialise the SCO for use.- Specified by:
initialise
in interfaceSCO<K>
- Overrides:
initialise
in classMap<K,V>
-
getValue
public Map getValue()
Accessor for the unwrapped value that we are wrapping.
-
load
public void load()
Method to effect the load of the data in the SCO. Used when the SCO supports lazy-loading to tell it to load all now.
-
isLoaded
public boolean isLoaded()
Method to return if the SCO has its contents loaded. If the SCO doesn't support lazy loading will just return true.
-
loadFromStore
protected void loadFromStore()
Method to load all elements from the "backing store" where appropriate.
-
getBackingStore
public Store getBackingStore()
- Specified by:
getBackingStore
in interfaceBackedSCO
-
updateEmbeddedKey
public void updateEmbeddedKey(K key, int fieldNumber, Object newValue, boolean makeDirty)
Method to update an embedded key in this map.
-
updateEmbeddedValue
public void updateEmbeddedValue(V value, int fieldNumber, Object newValue, boolean makeDirty)
Method to update an embedded value in this map.
-
unsetOwner
public void unsetOwner()
Method to unset the owner and field information.- Specified by:
unsetOwner
in interfaceSCO<K>
- Overrides:
unsetOwner
in classMap<K,V>
-
clone
public Object clone()
Creates and returns a copy of this object.Mutable second-class Objects are required to provide a public clone method in order to allow for copying persistable objects. In contrast to Object.clone(), this method must not throw a CloneNotSupportedException.
-
containsKey
public boolean containsKey(Object key)
Utility to check if a key is contained in the Map.- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classMap<K,V>
- Parameters:
key
- The key to check- Returns:
- Whether it is contained
-
containsValue
public boolean containsValue(Object value)
Utility to check if a value is contained in the Map.- Specified by:
containsValue
in interfaceMap<K,V>
- Overrides:
containsValue
in classMap<K,V>
- Parameters:
value
- The value to check- Returns:
- Whether it is contained
-
entrySet
public Set entrySet()
Accessor for the set of entries in the Map.
-
equals
public boolean equals(Object o)
Method to check the equality of this map, and another.
-
forEach
public void forEach(BiConsumer<? super K,? super V> action)
-
hashCode
public int hashCode()
Method to generate a hashcode for this Map.
-
isEmpty
public boolean isEmpty()
Method to return if the Map is empty.
-
keySet
public Set keySet()
Accessor for the set of keys in the Map.
-
size
public int size()
Method to return the size of the Map.
-
values
public Collection values()
Accessor for the set of values in the Map.
-
toString
public String toString()
Method to return a string form of this Map.- Overrides:
toString
in classAbstractMap<K,V>
- Returns:
- String form of this Map.
-
clear
public void clear()
Method to clear the Map.
-
putAll
public void putAll(Map m)
Method to add a Map of values to this map.
-
writeReplace
protected Object writeReplace() throws ObjectStreamException
The writeReplace method is called when ObjectOutputStream is preparing to write the object to the stream. The ObjectOutputStream checks whether the class defines the writeReplace method. If the method is defined, the writeReplace method is called to allow the object to designate its replacement in the stream. The object returned should be either of the same type as the object passed in or an object that when read and resolved will result in an object of a type that is compatible with all references to the object.- Overrides:
writeReplace
in classMap<K,V>
- Returns:
- the replaced object
- Throws:
ObjectStreamException
- if an error occurs
-
-