org.hydrateframework
Class ObjectKey.Complex

java.lang.Object
  extended by org.hydrateframework.ObjectKey.Complex
All Implemented Interfaces:
Constraint, ObjectKey
Enclosing interface:
ObjectKey

public abstract static class ObjectKey.Complex
extends java.lang.Object
implements ObjectKey

This partial implementation of the ObjectKey interface is used by objects that have an alternate key. To use this object start by creating your own class that derives from it. Provide data members and a constructor or constructors that provide all that data to define the key. Finally, implement the setQryParams, initBusObject and getIdxName as described in the help for those functions. For example an object that is an alternate key for an employee object based on surname and date of birth the start of the class might look something like:


 class EmployeeAltKey extends ObjectKey.Complex {

     private String m_surname;
     private java.util.Date m_dob;

     public EmployeeAltKey(String surname, java.util.Date dob) {
         m_surname = surname;
         m_dob = dob;
     }
     .
     .
 

Author:
David Chamberlin

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.hydrateframework.ObjectKey
ObjectKey.Complex, ObjectKey.Int, ObjectKey.Str
 
Field Summary
protected static int FLAGS_AUTOFIXUP
           
protected static int FLAGS_ISNULL
           
protected  int m_flags
           
 
Fields inherited from interface org.hydrateframework.ObjectKey
m_log
 
Constructor Summary
  ObjectKey.Complex()
           
protected ObjectKey.Complex(boolean autoFixup)
           
 
Method Summary
abstract  void constrainQuery(NamedParameterStatement stmt, java.lang.String prmName)
          This function should call setParam on the DataQuery object provided to set whatever constraints are necessary to get the data indicated by the alternate key.
abstract  boolean equals(java.lang.Object o)
          It is important that you implement this function in your alternate key class if you are going to use this key class in an index.
 int hashCode()
          It is important that you implement this function in your alternate key class if you are going to use this key class in an index.
abstract  void initObject(java.lang.Object obj)
          This should populate a newly constructed hydrate object with information from this key.
 int intValue()
          Return an integer value that represents this key.
 boolean isAutofixup()
           
 boolean isPersisted()
          Has the object associated with this key been persisted in the database
 void setNotPersisted()
          Set object to indicate it is not persisted.
 void setPersisted()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hydrateframework.ObjectKey
getKeyName
 

Field Detail

FLAGS_ISNULL

protected static final int FLAGS_ISNULL
See Also:
Constant Field Values

FLAGS_AUTOFIXUP

protected static final int FLAGS_AUTOFIXUP
See Also:
Constant Field Values

m_flags

protected int m_flags
Constructor Detail

ObjectKey.Complex

public ObjectKey.Complex()

ObjectKey.Complex

protected ObjectKey.Complex(boolean autoFixup)
Method Detail

hashCode

public int hashCode()
It is important that you implement this function in your alternate key class if you are going to use this key class in an index. In our EmployeeAltKey example the following implementation would work:
public int hashCode() { return m_surname.hashCode() + m_dob.hashCode(); }

Specified by:
hashCode in interface ObjectKey
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

intValue

public int intValue()
Description copied from interface: ObjectKey
Return an integer value that represents this key. This only really makes any sense if the underlying type of the key is integer, or some integer that is shorter.

Specified by:
intValue in interface ObjectKey
Returns:
the integer representation of this key.

isPersisted

public boolean isPersisted()
Description copied from interface: ObjectKey
Has the object associated with this key been persisted in the database

Specified by:
isPersisted in interface ObjectKey
Returns:
true if the object is in the database.

isAutofixup

public boolean isAutofixup()

setNotPersisted

public void setNotPersisted()
Description copied from interface: ObjectKey
Set object to indicate it is not persisted.

Specified by:
setNotPersisted in interface ObjectKey

setPersisted

public void setPersisted()

constrainQuery

public abstract void constrainQuery(NamedParameterStatement stmt,
                                    java.lang.String prmName)
                             throws SaveException
This function should call setParam on the DataQuery object provided to set whatever constraints are necessary to get the data indicated by the alternate key. For example, in the EmployeeAltKey (see ObjectKey.Complex) the following implementation might make sense:
public void constrainQuery(QueryInfo qry, String prmName) { // check we were trying to set the key... if (prmName.equals("Key")) { // set the key information qry.setParam("Surname", m_surname); qry.setParam("DateOfBirth", m_dob); return; } // bad argument throw new IllegalArgumentException(prmName); }

Specified by:
constrainQuery in interface Constraint
Specified by:
constrainQuery in interface ObjectKey
Throws:
SaveException

initObject

public abstract void initObject(java.lang.Object obj)
This should populate a newly constructed hydrate object with information from this key. In the EmployeeAltKey example (see ObjectKey.Complex) the following implementation might be used:
public void initObject(Object obj) { // we can safely assume that an employee object // was constructed. Use the 'Init' interface because // we are initialising the object. Employee.Init emp = (Employee.Init)obj; // now initialise the object. emp.initSurname(m_surname); emp.initDateOfBirth(m_dob); }

Specified by:
initObject in interface ObjectKey
Parameters:
obj - the object that has just been constructed and must be populated with data. The type of the object should be known to the fully implemented key.

equals

public abstract boolean equals(java.lang.Object o)
It is important that you implement this function in your alternate key class if you are going to use this key class in an index. In our EmployeeAltKey example the following implementation would work:
public boolean equals(Object o) { // check that this is an EmployeeAltKey first if (o instanceof EmployeeAltKey) { EmployeeAltKey a = (EmployeeAltKey)o; return m_surname = a.m_surname && m_dob = a.m_dob; } return false; }

Specified by:
equals in interface ObjectKey
Overrides:
equals in class java.lang.Object
Returns:
true if the keys are the same


Copyright © 2000 The Hydrate Project. All Rights Reserved.