Module org.eclipse.persistence.core
Class IndirectMap<K,V>
java.lang.Object
java.util.Dictionary<K,V>
java.util.Hashtable<K,V>
org.eclipse.persistence.indirection.IndirectMap<K,V>
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
,V> ChangeTracker
,CollectionChangeTracker
,IndirectCollection<Map.Entry<K,
,V>, Map<K, V>> IndirectContainer<Map<K,
V>>
public class IndirectMap<K,V>
extends Hashtable<K,V>
implements CollectionChangeTracker, IndirectCollection<Map.Entry<K,V>,Map<K,V>>
IndirectMap allows a domain class to take advantage of TopLink indirection
without having to declare its instance variable as a ValueHolderInterface.
To use an IndirectMap:
- Declare the appropriate instance variable with type Map or Hashtable
- Send the message #useTransparentMap(String) to the appropriate CollectionMapping.
- Since:
- TOPLink/Java 2.5
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionReduce type castingprotected int
Store initial size for lazy init.protected float
Store load factor for lazy init.protected ValueHolderInterface
<Map<K, V>> Delegate indirection behavior to a value holder -
Constructor Summary
ConstructorDescriptionPUBLIC: Construct a new, empty IndirectMap with a default capacity and load factor.IndirectMap
(int initialCapacity) PUBLIC: Construct a new, empty IndirectMap with the specified initial capacity and default load factor.IndirectMap
(int initialCapacity, float loadFactor) PUBLIC: Construct a new, empty IndirectMap with the specified initial capacity and load factor.IndirectMap
(Map<? extends K, ? extends V> m) PUBLIC: Construct a new IndirectMap with the same mappings as the given Map. -
Method Summary
Modifier and TypeMethodDescriptionReturn the property change listener for change tracking.void
_persistence_setPropertyChangeListener
(PropertyChangeListener changeListener) INTERNAL: Set the property change listener for change tracking.Return the freshly-built delegate.void
clear()
void
INTERNAL: clear any changes that have been deferred to instantiation.clone()
computeIfAbsent
(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) boolean
boolean
containsKey
(Object key) boolean
containsValue
(Object value) elements()
entrySet()
boolean
void
forEach
(BiConsumer<? super K, ? super V> action) INTERNAL: Return the elements that have been added before instantiation.INTERNAL: Check whether the contents have been read from the database.INTERNAL: Return the real collection object.getOrDefault
(Object key, V defaultValue) INTERNAL: Return the elements that have been removed before instantiation.INTERNAL: Return the mapping attribute name, used to raise change events.PUBLIC: Return the valueHolder.boolean
INTERNAL: Return if any elements that have been added or removed before instantiation.int
hashCode()
boolean
INTERNAL: Return if the collection has a property change listener for change tracking.protected void
initialize
(int initialCapacity, float loadFactor) Initialize the instance.protected void
initialize
(Map<? extends K, ? extends V> m) Initialize the instance.boolean
isEmpty()
boolean
PUBLIC: Return whether the contents have been read from the database.keys()
keySet()
void
putIfAbsent
(K key, V value) protected void
raiseAddChangeEvent
(Object key, Object value) Raise the add change event and relationship maintainence.protected void
raiseRemoveChangeEvent
(Object key, Object value) Raise the remove change event.protected void
rehash()
boolean
boolean
void
replaceAll
(BiFunction<? super K, ? super V, ? extends V> function) void
setTrackedAttributeName
(String attributeName) INTERNAL: Set the mapping attribute name, used to raise change events.void
setUseLazyInstantiation
(boolean useLazyInstantiation) INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBvoid
setValueHolder
(ValueHolderInterface<Map<K, V>> valueHolder) INTERNAL: Set the value holder.int
size()
toString()
PUBLIC: Use the Hashtable.toString(); but wrap it with braces to indicate there is a bit of indirection.values()
-
Field Details
-
delegate
Reduce type casting -
valueHolder
Delegate indirection behavior to a value holder -
initialCapacity
protected int initialCapacityStore initial size for lazy init. -
loadFactor
protected float loadFactorStore load factor for lazy init.
-
-
Constructor Details
-
IndirectMap
public IndirectMap()PUBLIC: Construct a new, empty IndirectMap with a default capacity and load factor. -
IndirectMap
public IndirectMap(int initialCapacity) PUBLIC: Construct a new, empty IndirectMap with the specified initial capacity and default load factor.- Parameters:
initialCapacity
- the initial capacity of the hashtable
-
IndirectMap
public IndirectMap(int initialCapacity, float loadFactor) PUBLIC: Construct a new, empty IndirectMap with the specified initial capacity and load factor.- Parameters:
initialCapacity
- the initial capacity of the hashtableloadFactor
- a number between 0.0 and 1.0- Throws:
IllegalArgumentException
- if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero
-
IndirectMap
PUBLIC: Construct a new IndirectMap with the same mappings as the given Map. The IndirectMap is created with a capacity of twice the number of entries in the given Map or 11 (whichever is greater), and a default load factor, which is 0.75.- Parameters:
m
- a map containing the mappings to use
-
-
Method Details
-
buildDelegate
Return the freshly-built delegate. -
clear
public void clear() -
clearDeferredChanges
public void clearDeferredChanges()INTERNAL: clear any changes that have been deferred to instantiation. Indirect collections with change tracking avoid instantiation on add/remove.- Specified by:
clearDeferredChanges
in interfaceIndirectCollection<K,
V>
-
clone
-
contains
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classHashtable<K,
V> - See Also:
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classHashtable<K,
V> - See Also:
-
elements
-
entrySet
-
equals
-
get
-
getDelegate
INTERNAL: Check whether the contents have been read from the database. If they have not, read them and set the delegate. This method used to be synchronized, which caused deadlock. -
getDelegateObject
INTERNAL: Return the real collection object. This will force instantiation.- Specified by:
getDelegateObject
in interfaceIndirectCollection<K,
V>
-
getTrackedAttributeName
INTERNAL: Return the mapping attribute name, used to raise change events.- Specified by:
getTrackedAttributeName
in interfaceCollectionChangeTracker
-
_persistence_getPropertyChangeListener
Return the property change listener for change tracking.- Specified by:
_persistence_getPropertyChangeListener
in interfaceChangeTracker
-
getValueHolder
PUBLIC: Return the valueHolder. This method used to be synchronized, which caused deadlock.- Specified by:
getValueHolder
in interfaceIndirectContainer<K>
- Returns:
- org.eclipse.persistence.indirection.ValueHolderInterface A representation of the valueholder * which this container uses
-
hashCode
public int hashCode() -
hasTrackedPropertyChangeListener
public boolean hasTrackedPropertyChangeListener()INTERNAL: Return if the collection has a property change listener for change tracking. -
initialize
protected void initialize(int initialCapacity, float loadFactor) Initialize the instance. -
initialize
Initialize the instance. -
isEmpty
public boolean isEmpty() -
isInstantiated
public boolean isInstantiated()PUBLIC: Return whether the contents have been read from the database.- Specified by:
isInstantiated
in interfaceIndirectContainer<K>
-
keys
-
keySet
-
put
-
putAll
-
compute
-
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceMap<K,
V> - Overrides:
computeIfAbsent
in classHashtable<K,
V>
-
computeIfPresent
- Specified by:
computeIfPresent
in interfaceMap<K,
V> - Overrides:
computeIfPresent
in classHashtable<K,
V>
-
forEach
-
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<K,
V> - Overrides:
getOrDefault
in classHashtable<K,
V>
-
merge
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<K,
V> - Overrides:
putIfAbsent
in classHashtable<K,
V>
-
remove
-
replace
-
replace
-
replaceAll
- Specified by:
replaceAll
in interfaceMap<K,
V> - Overrides:
replaceAll
in classHashtable<K,
V>
-
rehash
protected void rehash() -
raiseAddChangeEvent
Raise the add change event and relationship maintainence. -
raiseRemoveChangeEvent
Raise the remove change event. -
remove
-
setTrackedAttributeName
INTERNAL: Set the mapping attribute name, used to raise change events. This is required if the change listener is set.- Specified by:
setTrackedAttributeName
in interfaceCollectionChangeTracker
-
_persistence_setPropertyChangeListener
INTERNAL: Set the property change listener for change tracking.- Specified by:
_persistence_setPropertyChangeListener
in interfaceChangeTracker
-
setValueHolder
INTERNAL: Set the value holder.- Specified by:
setValueHolder
in interfaceIndirectContainer<K>
-
size
public int size() -
setUseLazyInstantiation
public void setUseLazyInstantiation(boolean useLazyInstantiation) INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dB- Specified by:
setUseLazyInstantiation
in interfaceIndirectCollection<K,
V>
-
getRemovedElements
INTERNAL: Return the elements that have been removed before instantiation.- Specified by:
getRemovedElements
in interfaceIndirectCollection<K,
V>
-
getAddedElements
INTERNAL: Return the elements that have been added before instantiation.- Specified by:
getAddedElements
in interfaceIndirectCollection<K,
V>
-
hasDeferredChanges
public boolean hasDeferredChanges()INTERNAL: Return if any elements that have been added or removed before instantiation.- Specified by:
hasDeferredChanges
in interfaceIndirectCollection<K,
V>
-
toString
PUBLIC: Use the Hashtable.toString(); but wrap it with braces to indicate there is a bit of indirection. Don't allow this method to trigger a database read. -
values
-