org.hydrateframework
Class ObjectIndexer

java.lang.Object
  extended by org.hydrateframework.ObjectIndexer
All Implemented Interfaces:
QueryRunner.Observer

public class ObjectIndexer
extends java.lang.Object
implements QueryRunner.Observer

This class maintains a list of HydrateObjects that satisfy a certain criteria. This criteria is used to bucket all HydrateObjects that this class sees (via its built method). The goal is to pre populate the map to allow fast retrival of objects that satisfy the criteria. This class maintains an internal hashmap of keys to Objects or List of objects. It is therefore vital that the hashcode and the equals methods of the keyClass implementation are correct. The Sink interface defines a built method that may be called during object creation time by passing in the sink implementation to the BuildObjects.build method. This may be sufficient to populate the internal map for some cases, however it will not be sufficient for all. The keyClass must have a constructor that takes an HydrateObject as an argument. The keyClass should then proceed to initialise its internal state. If the key's hashcode depends on a value that is set from an object associated with the hydrate object (used to initialise the key) then this reference may not be set until later in the build process. For example, if an Execution object has a link to an Order object, the link from Order to Execution may be built during the population of the Order and the link back from the Execution to Order will be set (if naviagable=true) as a consequence. The problem with this is that we may have already built the Execution object so the sink is never notified of the Execution change. The criteria is specified by the keyClass which is passed in in the constructor. The type of objects that the map holds is specified by the second (Class) arg passed to the constructor.

Version:
@(#)$Revision: 1.3 $
Author:
David Harte

Constructor Summary
ObjectIndexer(java.lang.Class keyClass, java.lang.Class objClass, boolean unique)
          Constructor
 
Method Summary
 boolean built(java.lang.Object hydrateObject, boolean isNew)
          This method is called each time an object is constructed from a row in the query.
 HydrateObject getObject(java.lang.Object key)
          Get the Hydrate Object associated with the specific key.
 java.util.List getObjects(java.lang.Object key)
          Get a list of objects that are associated with this particular key
 void indexNow(ObjectContext ctx)
          This method will reindex the contents of the ObjectContext specified in relation to the key and object classes previously set in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectIndexer

public ObjectIndexer(java.lang.Class keyClass,
                     java.lang.Class objClass,
                     boolean unique)
Constructor

Parameters:
keyClass - the class that represents the key for the internal map.
objClass - the objects associated with the key will be of this class type.
unique - if unique is true then there is a one to many relationship between the key and its associated objects, if false then this relationship is one to many.
Method Detail

indexNow

public void indexNow(ObjectContext ctx)
This method will reindex the contents of the ObjectContext specified in relation to the key and object classes previously set in the constructor.

Parameters:
ctx - the context from which to retrieve the objects.

built

public boolean built(java.lang.Object hydrateObject,
                     boolean isNew)
This method is called each time an object is constructed from a row in the query. It will be called up to a maximum of n times per row, where n is the number of assemblers that were added to the BuildObjects class.

Specified by:
built in interface QueryRunner.Observer
Parameters:
hydrateObject - an object that has just been read from a row of data.
isNew - true if the object was already in memory and has just been refreshed or false if this is the first time this object has been seen by the current ObjectContext

getObject

public HydrateObject getObject(java.lang.Object key)
                        throws java.lang.IllegalArgumentException
Get the Hydrate Object associated with the specific key.

Parameters:
key - the key for which to get the object
Returns:
the object
Throws:
java.lang.IllegalArgumentException - if this Sink is configured with a non unique key.

getObjects

public java.util.List getObjects(java.lang.Object key)
                          throws java.lang.IllegalArgumentException
Get a list of objects that are associated with this particular key

Parameters:
key - the lookup key
Returns:
the list of associated objects.
Throws:
java.lang.IllegalArgumentException - if the key has been specified as non unique.


Copyright © 2000 The Hydrate Project. All Rights Reserved.