org.hydrateframework
Class UniqueIndex

java.lang.Object
  extended by org.hydrateframework.ObjectIndex
      extended by org.hydrateframework.UniqueIndex

public class UniqueIndex
extends ObjectIndex

Version:
@(#)$Revision: 1.4 $
Author:
David Chamberlin

Field Summary
protected static org.apache.commons.logging.Log m_log
           
 
Fields inherited from class org.hydrateframework.ObjectIndex
m_cls, m_ctx, m_keyCls
 
Constructor Summary
UniqueIndex(java.lang.Class cls)
          Construct a unique index that will index objects of the given class using the primary key for that class as a key.
UniqueIndex(java.lang.Class cls, java.lang.Class keyCls)
           
 
Method Summary
 void addObject(java.lang.Object obj, ObjectKey key)
          Add an object to the index with the given key.
 void clear()
          Clear the index.
 java.io.PrintStream dump(java.io.PrintStream out)
          Output details of the index to a PrintStream.
 java.lang.Object findObject(ObjectKey key)
          This abstract method should be implemented to find an object given a key.
 ObjectCollection findObjects(ObjectKey key)
          This method should be implemented to find a collection of business objects given a key.
 java.util.Iterator keys()
          Calls that use the iterator returned by this method must be synchronised on the index object if there is any chance that more than one thread may be accessing the index while the iterator is in use.
 java.lang.Object removeKey(ObjectKey key)
          Remove the entire contents of a particular key in this index.
 void removeObject(java.lang.Object obj, ObjectKey key)
          Remove an object from the index using the given key.
 int size()
           
 
Methods inherited from class org.hydrateframework.ObjectIndex
addObject, equals, getClassToIndex, getKeyClass, keyFromObject, removeObject, setObjectContext
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_log

protected static final org.apache.commons.logging.Log m_log
Constructor Detail

UniqueIndex

public UniqueIndex(java.lang.Class cls)
Construct a unique index that will index objects of the given class using the primary key for that class as a key.

Parameters:
cls - the class that is to be indexed.

UniqueIndex

public UniqueIndex(java.lang.Class cls,
                   java.lang.Class keyCls)
Method Detail

clear

public void clear()
Description copied from class: ObjectIndex
Clear the index.

Specified by:
clear in class ObjectIndex

keys

public java.util.Iterator keys()
Calls that use the iterator returned by this method must be synchronised on the index object if there is any chance that more than one thread may be accessing the index while the iterator is in use.

Specified by:
keys in class ObjectIndex
Returns:
an iterator for keys.

findObject

public java.lang.Object findObject(ObjectKey key)
Description copied from class: ObjectIndex
This abstract method should be implemented to find an object given a key. It always returns a single object.

Specified by:
findObject in class ObjectIndex
Parameters:
key - the key to use on the index
Returns:
the business object found or null if there was object with the given key in the index.

findObjects

public ObjectCollection findObjects(ObjectKey key)
Description copied from class: ObjectIndex
This method should be implemented to find a collection of business objects given a key. It is not guaranteed to return anything if the index is a one-to-one index.

Specified by:
findObjects in class ObjectIndex
Parameters:
key - the key to use on the index
Returns:
the business object collection found or a new empty collection if none was found.

addObject

public void addObject(java.lang.Object obj,
                      ObjectKey key)
Description copied from class: ObjectIndex
Add an object to the index with the given key. This is the only way to add objects to indexes which represent one or other side of a many-to-many relationship.

Specified by:
addObject in class ObjectIndex
Parameters:
obj - the object to add to the index
key - the key to use in adding the object

removeObject

public void removeObject(java.lang.Object obj,
                         ObjectKey key)
Description copied from class: ObjectIndex
Remove an object from the index using the given key.

Specified by:
removeObject in class ObjectIndex
Parameters:
obj - the object to be removed
key - the key to be used to find the object

removeKey

public java.lang.Object removeKey(ObjectKey key)
Description copied from class: ObjectIndex
Remove the entire contents of a particular key in this index. For unique indexes, this will remove a business object, for mutiple indexes, this will remove a collection of business objects. This call is used when the key value of an object changes and it needs to be re-indexed.

Specified by:
removeKey in class ObjectIndex
Parameters:
key - the key to be removed
Returns:
the object associated with the given key or null if none was found.

dump

public java.io.PrintStream dump(java.io.PrintStream out)
Description copied from class: ObjectIndex
Output details of the index to a PrintStream.

Overrides:
dump in class ObjectIndex
Parameters:
out - where to send the output
Returns:
the same output device

size

public int size()
Specified by:
size in class ObjectIndex
Returns:
the number of items in this index


Copyright © 2000 The Hydrate Project. All Rights Reserved.