org.eclipse.persistence.indirection
Class IndirectMap

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by org.eclipse.persistence.indirection.IndirectMap
All Implemented Interfaces:
Serializable, Cloneable, Map, ChangeTracker, CollectionChangeTracker, IndirectCollection, IndirectContainer

public class IndirectMap
extends Hashtable
implements CollectionChangeTracker, IndirectCollection

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:

TopLink will place an IndirectMap in the instance variable when the containing domain object is read from the datatabase. With the first message sent to the IndirectMap, the contents are fetched from the database and normal Hashtable/Map behavior is resumed.

Since:
TOPLink/Java 2.5
Author:
Big Country
See Also:
CollectionMapping, IndirectList, Serialized Form

Constructor Summary
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 m)
          PUBLIC: Construct a new IndirectMap with the same mappings as the given Map.
 
Method Summary
 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.
 void clear()
           
 Object clone()
           
 boolean contains(Object value)
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Enumeration elements()
           
 Set entrySet()
           
 boolean equals(Object o)
           
 Object get(Object key)
           
 Collection getAddedElements()
          INTERNAL: Return the elements that have been added before instantiation.
 Object getDelegateObject()
          INTERNAL: Return the real collection object.
 Collection getRemovedElements()
          INTERNAL: Return the elements that have been removed before instantiation.
 String getTrackedAttributeName()
          INTERNAL: Return the mapping attribute name, used to raise change events.
 ValueHolderInterface getValueHolder()
          PUBLIC: Return the valueHolder.
 boolean hasDeferredChanges()
          INTERNAL: Return if any elements that have been added or removed before instantiation.
 int hashCode()
           
 boolean hasTrackedPropertyChangeListener()
          INTERNAL: Return if the collection has a property change listener for change tracking.
 boolean isEmpty()
           
 boolean isInstantiated()
          PUBLIC: Return whether the contents have been read from the database.
 Enumeration keys()
           
 Set keySet()
           
 Object put(Object key, Object value)
           
 void putAll(Map t)
           
 Object remove(Object key)
           
 void setTrackedAttributeName(String attributeName)
          INTERNAL: Set the mapping attribute name, used to raise change events.
 void setValueHolder(ValueHolderInterface valueHolder)
          INTERNAL: Set the value holder.
 int size()
           
 String toString()
          PUBLIC: Use the Hashtable.toString(); but wrap it with braces to indicate there is a bit of indirection.
 Collection values()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

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 hashtable
loadFactor - 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 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()
Specified by:
clear in interface Map
Overrides:
clear in class Hashtable
See Also:
Hashtable.clear()

clone

public Object clone()
Overrides:
clone in class Hashtable
See Also:
This will result in a database query if necessary.

contains

public boolean contains(Object value)
Overrides:
contains in class Hashtable
See Also:
Hashtable.contains(java.lang.Object)

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map
Overrides:
containsKey in class Hashtable
See Also:
Hashtable.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map
Overrides:
containsValue in class Hashtable
See Also:
Hashtable.containsValue(java.lang.Object)

elements

public Enumeration elements()
Overrides:
elements in class Hashtable
See Also:
Hashtable.elements()

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Overrides:
entrySet in class Hashtable
See Also:
Hashtable.entrySet()

equals

public boolean equals(Object o)
Specified by:
equals in interface Map
Overrides:
equals in class Hashtable
See Also:
Hashtable.equals(java.lang.Object)

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class Hashtable
See Also:
Hashtable.get(java.lang.Object)

getDelegateObject

public Object getDelegateObject()
INTERNAL: Return the real collection object. This will force instantiation.

Specified by:
getDelegateObject in interface IndirectCollection

getTrackedAttributeName

public String getTrackedAttributeName()
INTERNAL: Return the mapping attribute name, used to raise change events.

Specified by:
getTrackedAttributeName in interface CollectionChangeTracker

_persistence_getPropertyChangeListener

public PropertyChangeListener _persistence_getPropertyChangeListener()
Return the property change listener for change tracking.

Specified by:
_persistence_getPropertyChangeListener in interface ChangeTracker

getValueHolder

public ValueHolderInterface getValueHolder()
PUBLIC: Return the valueHolder. This method used to be synchronized, which caused deadlock.

Specified by:
getValueHolder in interface IndirectContainer
Returns:
org.eclipse.persistence.indirection.ValueHolderInterface A representation of the valueholder * which this container uses

hashCode

public int hashCode()
Specified by:
hashCode in interface Map
Overrides:
hashCode in class Hashtable
See Also:
Hashtable.hashCode()

hasTrackedPropertyChangeListener

public boolean hasTrackedPropertyChangeListener()
INTERNAL: Return if the collection has a property change listener for change tracking.


isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map
Overrides:
isEmpty in class Hashtable
See Also:
Hashtable.isEmpty()

isInstantiated

public boolean isInstantiated()
PUBLIC: Return whether the contents have been read from the database.

Specified by:
isInstantiated in interface IndirectContainer

keys

public Enumeration keys()
Overrides:
keys in class Hashtable
See Also:
Hashtable.keys()

keySet

public Set keySet()
Specified by:
keySet in interface Map
Overrides:
keySet in class Hashtable
See Also:
Hashtable.keySet()

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map
Overrides:
put in class Hashtable
See Also:
Hashtable.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(Map t)
Specified by:
putAll in interface Map
Overrides:
putAll in class Hashtable
See Also:
Hashtable.putAll(java.util.Map)

remove

public Object remove(Object key)
Specified by:
remove in interface Map
Overrides:
remove in class Hashtable
See Also:
Hashtable.remove(java.lang.Object)

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:
setTrackedAttributeName in interface CollectionChangeTracker

_persistence_setPropertyChangeListener

public void _persistence_setPropertyChangeListener(PropertyChangeListener changeListener)
INTERNAL: Set the property change listener for change tracking.

Specified by:
_persistence_setPropertyChangeListener in interface ChangeTracker

setValueHolder

public void setValueHolder(ValueHolderInterface valueHolder)
INTERNAL: Set the value holder.

Specified by:
setValueHolder in interface IndirectContainer

size

public int size()
Specified by:
size in interface Map
Overrides:
size in class Hashtable
See Also:
Hashtable.size()

getRemovedElements

public Collection getRemovedElements()
INTERNAL: Return the elements that have been removed before instantiation.

Specified by:
getRemovedElements in interface IndirectCollection

getAddedElements

public Collection getAddedElements()
INTERNAL: Return the elements that have been added before instantiation.

Specified by:
getAddedElements in interface IndirectCollection

hasDeferredChanges

public boolean hasDeferredChanges()
INTERNAL: Return if any elements that have been added or removed before instantiation.

Specified by:
hasDeferredChanges in interface IndirectCollection

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:
toString in class Hashtable
See Also:
Hashtable.toString()

values

public Collection values()
Specified by:
values in interface Map
Overrides:
values in class Hashtable
See Also:
Hashtable.values()