org.hydrateframework
Interface ObjectKey

All Superinterfaces:
Constraint
All Known Implementing Classes:
ObjectKey.Complex, ObjectKey.Int, ObjectKey.Str

public interface ObjectKey
extends Constraint

Version:
@(#)$Revision: 1.3 $
Author:
David Chamberlin This interface is implemented by any class that can act as a key. Each hydrate object has a set of keys that can be accessed with the HydrateObject.getKey(java.lang.Class) method.
See Also:
HydrateObject, PrimaryKey

Nested Class Summary
static class ObjectKey.Complex
          This partial implementation of the ObjectKey interface is used by objects that have an alternate key.
static class ObjectKey.Int
          This partial implementation of the ObjectKey interface is used by objects that have a primary key whose underlying type is an int
static class ObjectKey.Str
          This partial implementation of the ObjectKey interface is used by objects that have a primary key whose underlying type is a String
 
Field Summary
static org.apache.commons.logging.Log m_log
           
 
Method Summary
 void constrainQuery(NamedParameterStatement stmt, java.lang.String prmName)
          Constrain a query according to the settings of this key.
 boolean equals(java.lang.Object o)
          determine if two keys are equal.
 java.lang.String getKeyName()
           
 int hashCode()
          return a hashcode value for this key.
 void initObject(java.lang.Object obj)
          If a key is used to read an existing object from the database, that object must be populated immediately with information from the key.
 int intValue()
          Return an integer value that represents this key.
 boolean isPersisted()
          Has the object associated with this key been persisted in the database
 void setNotPersisted()
          Set object to indicate it is not persisted.
 

Field Detail

m_log

static final org.apache.commons.logging.Log m_log
Method Detail

isPersisted

boolean isPersisted()
Has the object associated with this key been persisted in the database

Returns:
true if the object is in the database.

setNotPersisted

void setNotPersisted()
Set object to indicate it is not persisted.


equals

boolean equals(java.lang.Object o)
determine if two keys are equal. Keys are equal if the objects to which they refer should have the same physical identity in the database. This means that keys that are null are only equal if the objects match with '==' whereas non null keys are equal if their internal values are equal.

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

hashCode

int hashCode()
return a hashcode value for this key. The hashCode must be the same for two objects if the call to equals returns true. They need not be different if the call returns false but, since keys will be indexed using a the hash code, performance of these indexes will be much improved if they do return distinct results.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

constrainQuery

void constrainQuery(NamedParameterStatement stmt,
                    java.lang.String prmName)
                    throws SaveException
Constrain a query according to the settings of this key. Call this method with a statement that is compatible with this key and it should subsequently read in the object or objects defined by this key.

Specified by:
constrainQuery in interface Constraint
Throws:
SaveException

initObject

void initObject(java.lang.Object obj)
If a key is used to read an existing object from the database, that object must be populated immediately with information from the key. The implementation of this method should do that population.

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.

intValue

int intValue()
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.

Returns:
the integer representation of this key.

getKeyName

java.lang.String getKeyName()


Copyright © 2000 The Hydrate Project. All Rights Reserved.