- 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.
- See Also:
CollectionMapping,IndirectList, Serialized Form- Author:
- Big Country
- Since:
- TOPLink/Java 2.5
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<K,V>delegateReduce type castingprotected intinitialCapacityStore initial size for lazy init.protected floatloadFactorStore load factor for lazy init.protected ValueHolderInterface<Map<K,V>>valueHolderDelegate indirection behavior to a value holder
-
Constructor Summary
Constructors Constructor Description IndirectMap()PUBLIC: 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PropertyChangeListener_persistence_getPropertyChangeListener()Return the property change listener for change tracking.void_persistence_setPropertyChangeListener(PropertyChangeListener changeListener)INTERNAL: Set the property change listener for change tracking.protected Hashtable<K,V>buildDelegate()Return the freshly-built delegate.voidclear()voidclearDeferredChanges()INTERNAL: clear any changes that have been deferred to instantiation.Objectclone()Vcompute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)VcomputeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)VcomputeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)booleancontains(Object value)booleancontainsKey(Object key)booleancontainsValue(Object value)Enumeration<V>elements()Set<Map.Entry<K,V>>entrySet()booleanequals(Object o)voidforEach(BiConsumer<? super K,? super V> action)Vget(Object key)Collection<Map.Entry<K,V>>getAddedElements()INTERNAL: Return the elements that have been added before instantiation.protected Hashtable<K,V>getDelegate()INTERNAL: Check whether the contents have been read from the database.Map<K,V>getDelegateObject()INTERNAL: Return the real collection object.VgetOrDefault(Object key, V defaultValue)Collection<Map.Entry<K,V>>getRemovedElements()INTERNAL: Return the elements that have been removed before instantiation.StringgetTrackedAttributeName()INTERNAL: Return the mapping attribute name, used to raise change events.ValueHolderInterface<Map<K,V>>getValueHolder()PUBLIC: Return the valueHolder.booleanhasDeferredChanges()INTERNAL: Return if any elements that have been added or removed before instantiation.inthashCode()booleanhasTrackedPropertyChangeListener()INTERNAL: Return if the collection has a property change listener for change tracking.protected voidinitialize(int initialCapacity, float loadFactor)Initialize the instance.protected voidinitialize(Map<? extends K,? extends V> m)Initialize the instance.booleanisEmpty()booleanisInstantiated()PUBLIC: Return whether the contents have been read from the database.Enumeration<K>keys()Set<K>keySet()Vmerge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)Vput(K key, V value)voidputAll(Map<? extends K,? extends V> t)VputIfAbsent(K key, V value)protected voidraiseAddChangeEvent(Object key, Object value)Raise the add change event and relationship maintainence.protected voidraiseRemoveChangeEvent(Object key, Object value)Raise the remove change event.protected voidrehash()Vremove(Object key)booleanremove(Object key, Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)voidreplaceAll(BiFunction<? super K,? super V,? extends V> function)voidsetTrackedAttributeName(String attributeName)INTERNAL: Set the mapping attribute name, used to raise change events.voidsetUseLazyInstantiation(boolean useLazyInstantiation)INTERNAL Set whether this collection should attempt do deal with adds and removes without retrieving the collection from the dBvoidsetValueHolder(ValueHolderInterface<Map<K,V>> valueHolder)INTERNAL: Set the value holder.intsize()StringtoString()PUBLIC: Use the Hashtable.toString(); but wrap it with braces to indicate there is a bit of indirection.Collection<V>values()
-
-
-
Field Detail
-
valueHolder
protected volatile ValueHolderInterface<Map<K,V>> valueHolder
Delegate indirection behavior to a value holder
-
initialCapacity
protected int initialCapacity
Store initial size for lazy init.
-
loadFactor
protected float loadFactor
Store load factor for lazy init.
-
-
Constructor Detail
-
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 IndirectMap(Map<? extends K,? extends V> m)
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 Detail
-
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:
clearDeferredChangesin interfaceIndirectCollection<K,V>
-
clone
public Object clone()
- Overrides:
clonein classHashtable<K,V>- See Also:
This will result in a database query if necessary.
-
contains
public boolean contains(Object value)
- Overrides:
containsin classHashtable<K,V>- See Also:
Hashtable.contains(java.lang.Object)
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K,V>- Overrides:
containsKeyin classHashtable<K,V>- See Also:
Hashtable.containsKey(java.lang.Object)
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K,V>- Overrides:
containsValuein classHashtable<K,V>- See Also:
Hashtable.containsValue(java.lang.Object)
-
elements
public Enumeration<V> elements()
- Overrides:
elementsin classHashtable<K,V>- See Also:
Hashtable.elements()
-
equals
public boolean equals(Object o)
-
getDelegate
protected Hashtable<K,V> 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
public Map<K,V> getDelegateObject()
INTERNAL: Return the real collection object. This will force instantiation.- Specified by:
getDelegateObjectin interfaceIndirectCollection<K,V>
-
getTrackedAttributeName
public String getTrackedAttributeName()
INTERNAL: Return the mapping attribute name, used to raise change events.- Specified by:
getTrackedAttributeNamein interfaceCollectionChangeTracker
-
_persistence_getPropertyChangeListener
public PropertyChangeListener _persistence_getPropertyChangeListener()
Return the property change listener for change tracking.- Specified by:
_persistence_getPropertyChangeListenerin interfaceChangeTracker
-
getValueHolder
public ValueHolderInterface<Map<K,V>> getValueHolder()
PUBLIC: Return the valueHolder. This method used to be synchronized, which caused deadlock.- Specified by:
getValueHolderin 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.
-
isEmpty
public boolean isEmpty()
-
isInstantiated
public boolean isInstantiated()
PUBLIC: Return whether the contents have been read from the database.- Specified by:
isInstantiatedin interfaceIndirectContainer<K>
-
keys
public Enumeration<K> keys()
- Overrides:
keysin classHashtable<K,V>- See Also:
Hashtable.keys()
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
- Specified by:
computeIfAbsentin interfaceMap<K,V>- Overrides:
computeIfAbsentin classHashtable<K,V>
-
computeIfPresent
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
- Specified by:
computeIfPresentin interfaceMap<K,V>- Overrides:
computeIfPresentin classHashtable<K,V>
-
forEach
public void forEach(BiConsumer<? super K,? super V> action)
-
getOrDefault
public V getOrDefault(Object key, V defaultValue)
- Specified by:
getOrDefaultin interfaceMap<K,V>- Overrides:
getOrDefaultin classHashtable<K,V>
-
merge
public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsentin interfaceMap<K,V>- Overrides:
putIfAbsentin classHashtable<K,V>
-
replaceAll
public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
- Specified by:
replaceAllin interfaceMap<K,V>- Overrides:
replaceAllin classHashtable<K,V>
-
rehash
protected void rehash()
- Overrides:
rehashin classHashtable<K,V>- See Also:
Hashtable.rehash()
-
raiseAddChangeEvent
protected void raiseAddChangeEvent(Object key, Object value)
Raise the add change event and relationship maintainence.
-
raiseRemoveChangeEvent
protected void raiseRemoveChangeEvent(Object key, Object value)
Raise the remove change event.
-
setTrackedAttributeName
public void setTrackedAttributeName(String attributeName)
INTERNAL: Set the mapping attribute name, used to raise change events. This is required if the change listener is set.- Specified by:
setTrackedAttributeNamein interfaceCollectionChangeTracker
-
_persistence_setPropertyChangeListener
public void _persistence_setPropertyChangeListener(PropertyChangeListener changeListener)
INTERNAL: Set the property change listener for change tracking.- Specified by:
_persistence_setPropertyChangeListenerin interfaceChangeTracker
-
setValueHolder
public void setValueHolder(ValueHolderInterface<Map<K,V>> valueHolder)
INTERNAL: Set the value holder.- Specified by:
setValueHolderin 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:
setUseLazyInstantiationin interfaceIndirectCollection<K,V>
-
getRemovedElements
public Collection<Map.Entry<K,V>> getRemovedElements()
INTERNAL: Return the elements that have been removed before instantiation.- Specified by:
getRemovedElementsin interfaceIndirectCollection<K,V>
-
getAddedElements
public Collection<Map.Entry<K,V>> getAddedElements()
INTERNAL: Return the elements that have been added before instantiation.- Specified by:
getAddedElementsin interfaceIndirectCollection<K,V>
-
hasDeferredChanges
public boolean hasDeferredChanges()
INTERNAL: Return if any elements that have been added or removed before instantiation.- Specified by:
hasDeferredChangesin interfaceIndirectCollection<K,V>
-
toString
public String 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.- Overrides:
toStringin classHashtable<K,V>- See Also:
Hashtable.toString()
-
-