Class COM.odi.util.OSHashtable

java.lang.Object
   |
   +----COM.odi.Persistent
           |
           +----COM.odi.util.HashPersistent
                   |
                   +----COM.odi.util.OSDictionary
                           |
                           +----COM.odi.util.OSHashtable

public class OSHashtable
extends OSDictionary
implements Cloneable, Serializable
OSHashtable implements a persistent hash table. The API is similar to java.util.Hashtable for ease of code conversion.

See Also:
Persistent, Hashtable

Constructor Index

 o OSHashtable()
Constructs a new persistence-capable hash table.
 o OSHashtable(ClassInfo)
Constructs a new hollow hash table.
 o OSHashtable(int)
Constructs a new persistence-capable hash table.

Method Index

 o clear()
Removes all entries from the hash table.
 o clearContents()
Resets the values of the fields of an active persistent object to the default initial values of that class of object.
 o clone()
Clones the object.
 o contains(Object)
Checks whether or not the hash table contains a specified value as an element.
 o containsKey(Object)
Checks whether or not the hash table contains an element with the specified key and maintains a cache from the OSHashtable object to the element.
 o containsKey(Object, boolean)
Checks whether or not the hash table contains an element with the specified key and optionally maintains a cache from the OSHashtable object to the element.
 o destroy()
Destroys the hash table in the database.
 o elements()
Obtains an enumeration of the elements in the hash table.
 o flushContents(GenericObject)
Stores the values of the fields of an active persistent object in an instance of GenericObject.
 o get(Object)
Obtains the element mapped at the specified key and maintains a cache from the OSHashtable object to the element.
 o get(Object, boolean)
Obtains the element mapped at the specified key and optionally maintains a cache from the OSHashtable object to the element.
 o getKey(Object)
Returns the actual key stored in the hash table for the given key and maintains a cache from the OSHashtable object to the element.
 o getKey(Object, boolean)
Returns the actual key stored in the hash table for the given key and optionally maintains a cache from the OSHashtable object to the element.
 o initializeContents(GenericObject)
Initializes the values of the fields of a hollow persistent object from data contained in an instance of GenericObject.
 o isEmpty()
Determines whether or not there are any keys in the hash table.
 o keys()
Returns an enumeration of the keys in the hash table.
 o put(Object, Object)
Enter the mapping of a key to a value in the hash table.
 o remove(Object)
Removes any existing mapping at the specified key.
 o size()
Determines the number of keys in the hash table.
 o toString()
Produces a printable representation of the object.

Constructors

 o OSHashtable
  protected OSHashtable(ClassInfo ignored)
Constructs a new hollow hash table. This constructor should be used only for that purpose

Parameters:
ignored - Only used to distinguish this overloading. The value is not used.
 o OSHashtable
  public OSHashtable(int initialCapacity)
Constructs a new persistence-capable hash table.

Parameters:
initialCapacity - The initial expected capacity requirement for the hash table.
 o OSHashtable
  public OSHashtable()
Constructs a new persistence-capable hash table. A default size is used as the initial hash table capacity.

Methods

 o initializeContents
  public void initializeContents(GenericObject genObject)
Initializes the values of the fields of a hollow persistent object from data contained in an instance of GenericObject. PSE/PSE Pro arranges to call this method when an application calls fetch() or dirty() on a persistent object. In the class you define, the method that overrides this method must initialize all fields in the hollow persistent object, including any fields defined by superclasses. Initialize superclass fields by invoking initializeContents() on the superclass. This is similar to calls to superclass constructors, although in this case the superclass initialization is not enforced by the compiler.

Parameters:
genObj - The representation of the persistent object that the method should read the field values from.

Overrides:
initializeContents in class OSDictionary
See Also:
initializeContents
 o flushContents
  public void flushContents(GenericObject genObject)
Stores the values of the fields of an active persistent object in an instance of GenericObject. PSE/PSE Pro arranges to call this method when a modified persistent object is evicted and when a transaction is committed. Your persistent class definition must define a method to override this one. Ensure that it writes all fields, even fields that were not modified.

Parameters:
genObject - The representation of the persistent object that this method should write the field values into.

Overrides:
flushContents in class OSDictionary
See Also:
flushContents
 o clearContents
  public void clearContents()
Resets the values of the fields of an active persistent object to the default initial values of that class of object. This causes the object to become a stale persistent object. As with initializeContents(), this method must invoke clearContents() on its superclass to ensure that all fields are correctly cleared.

Overrides:
clearContents in class OSDictionary
See Also:
clearContents
 o destroy
  public synchronized void destroy()
Destroys the hash table in the database. The keys and elements in the hash table are unaffected by this operation. If the hash table is persistent, the database must be open for update and there must be an update transaction in progress.

Throws: DatabaseNotOpenException
If the database containing the object is not open.
Throws: NoTransactionInProgressException
If there is no transaction in progress.
Throws: ObjectNotFoundException
If the object was not found, either because the object itself, its segment, or its database was destroyed, or because the object was local and was fetched in a previous transaction.
Throws: ObjectStoreException
If PSE/PSE Pro is not initialized for the current thread or if the object is not associated with this thread.
Throws: UpdateReadOnlyException
If there is a read-only transaction in progress or if the database is open read-only.
Overrides:
destroy in class Persistent
 o size
  public int size()
Determines the number of keys in the hash table.

Returns:
An integer that indicates the number of keys.
Overrides:
size in class OSDictionary
 o isEmpty
  public boolean isEmpty()
Determines whether or not there are any keys in the hash table.

Returns:
The true constant if there are no keys in the hash table. The false constant if there is at least one key in the hash table.
Overrides:
isEmpty in class OSDictionary
 o keys
  public synchronized Enumeration keys()
Returns an enumeration of the keys in the hash table. Note that the enumeration is only guaranteed to be valid for the duration of the current transaction.

Overrides:
keys in class OSDictionary
 o elements
  public synchronized Enumeration elements()
Obtains an enumeration of the elements in the hash table. Note that the elements are not necessarily unique and that the enumeration is only guaranteed to be valid for the duration of the current transaction.

Returns:
Enumeration The list of elements in the hash table.
Overrides:
elements in class OSDictionary
 o contains
  public synchronized boolean contains(Object value)
Checks whether or not the hash table contains a specified value as an element.

Parameters:
value - The element to search for, which must be nonnull.

Returns:
The true constant if the element is in the hash table. The false constant if the element is not in the hash table.

Throws: NullPointerException
If value is null.
Overrides:
contains in class OSDictionary
 o containsKey
  public synchronized boolean containsKey(Object key)
Checks whether or not the hash table contains an element with the specified key and maintains a cache from the OSHashtable object to the element. This cache prevents the element from being garbage collected unless the application evicts the entire OSHashtable.

Parameters:
key - The key to search for.

Returns:
The true constant if the hash table contains an element with the specified key. The false constant if the hash table does not.

Throws: NullPointerException
If key is null.
Overrides:
containsKey in class OSDictionary
 o containsKey
  public synchronized boolean containsKey(Object key,
                                          boolean noCache)
Checks whether or not the hash table contains an element with the specified key and optionally maintains a cache from the OSHashtable object to the element. Normally, the containsKey() method maintains this cache which prevents the element from being garbage collected unless the application evicts the entire OSHashtable.

Parameters:
key - The key to search for.

noCache - If true, the OSHashtable does not maintain a cache to the returned element. This allows the object to be garbage collected. If false, the OSHashtable maintains a cache to the element.

Returns:
The true constant if the hash table contains an element with the specified key. The false constant if the hash table does not.

Throws: NullPointerException
If key is null.
 o get
  public synchronized Object get(Object key)
Obtains the element mapped at the specified key and maintains a cache from the OSHashtable object to the element. This cache prevents the element from being garbage collected unless the application evicts the entire OSHashtable.

If you prefer to not maintain the cache, invoke get(key, noCache).

Parameters:
key - The key for the element you want to obtain.

Returns:
The element at the key, or null if no such key exists or the object that it refers to is destroyed.

Throws: NullPointerException
If key is null.
Overrides:
get in class OSDictionary
 o get
  public synchronized Object get(Object key,
                                 boolean noCache)
Obtains the element mapped at the specified key and optionally maintains a cache from the OSHashtable object to the element. Normally, the get() method maintains this cache, which prevents the element from being garbage collected.

There is a potential performance penalty if an application repeatedly invokes get() for the same key without maintaining a cache. This is because there is no caching.

Parameters:
key - The key for the element you want to obtain.

noCache - If true, the OSHashtable does not maintain a cache to the returned element. This allows the object to be garbage collected. If false, the OSHashtable maintains a cache to the element.

Returns:
The element at the key or null if no such key exists or the object that it refers to is destroyed.

Throws: NullPointerException
If key is null.
 o getKey
  public synchronized Object getKey(Object key)
Returns the actual key stored in the hash table for the given key and maintains a cache from the OSHashtable object to the element. Normally, the getKey() method maintains this cache, which prevents the element from being garbage collected.

There is a potential performance penalty if an application repeatedly invokes getKey() for the same key without maintaining a cache. This is because there is no caching.

Parameters:
key - The key to search for.

Returns:
The actual key stored in the hash table for the given key, or null if no such key exists.

Throws: NullPointerException
If key is null.
Overrides:
getKey in class OSDictionary
 o getKey
  public synchronized Object getKey(Object key,
                                    boolean noCache)
Returns the actual key stored in the hash table for the given key and optionally maintains a cache from the OSHashtable object to the element. Normally, the getKey() method maintains this cache, which prevents the element from being garbage collected.

There is a potential performance penalty if an application repeatedly invokes getKey() for the same key without maintaining a cache. This is because there is no caching.

Parameters:
key - The key to search for.

noCache - If true, the OSHashtable does not maintain a cache to the returned element. This allows the object to be garbage collected. If false, the OSHashtable maintains a cache to the element.

Returns:
The actual key stored in the hash table for the given key, or null if no such key exists.

Throws: NullPointerException
If key is null.
 o put
  public synchronized Object put(Object key,
                                 Object value)
Enter the mapping of a key to a value in the hash table.

Parameters:
key - The identifier for the value.

value - The value being stored in the hash table.

Returns:
The object previously mapped at the specified key, or null.

Throws: NullPointerException
If either key or value is null.
Overrides:
put in class OSDictionary
 o remove
  public synchronized Object remove(Object key)
Removes any existing mapping at the specified key.

Parameters:
key - The key of the object to remove.

Returns:
The object previously mapped at the specified key, or null.

Throws: NullPointerException
If key is null.
Overrides:
remove in class OSDictionary
 o clear
  public synchronized void clear()
Removes all entries from the hash table.

Overrides:
clear in class OSDictionary
 o clone
  public synchronized Object clone()
Clones the object.

Returns:
The cloned object.
Overrides:
clone in class HashPersistent
 o toString
  public synchronized String toString()
Produces a printable representation of the object.

Returns:
A string that represents the object.

Overrides:
toString in class Object
See Also:
toString

Copyright © 1996, 1997 Object Design, Inc. All rights reserved.