|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hydrateframework.ObjectKey.Complex
public abstract static class ObjectKey.Complex
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;
}
.
.
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 |
---|
protected static final int FLAGS_ISNULL
protected static final int FLAGS_AUTOFIXUP
protected int m_flags
Constructor Detail |
---|
public ObjectKey.Complex()
protected ObjectKey.Complex(boolean autoFixup)
Method Detail |
---|
public int hashCode()
EmployeeAltKey
example the following
implementation would work:
public int hashCode() { return m_surname.hashCode() + m_dob.hashCode(); }
hashCode
in interface ObjectKey
hashCode
in class java.lang.Object
public int intValue()
ObjectKey
intValue
in interface ObjectKey
public boolean isPersisted()
ObjectKey
isPersisted
in interface ObjectKey
public boolean isAutofixup()
public void setNotPersisted()
ObjectKey
setNotPersisted
in interface ObjectKey
public void setPersisted()
public abstract void constrainQuery(NamedParameterStatement stmt, java.lang.String prmName) throws SaveException
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); }
constrainQuery
in interface Constraint
constrainQuery
in interface ObjectKey
SaveException
public abstract void initObject(java.lang.Object obj)
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); }
initObject
in interface ObjectKey
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.public abstract boolean equals(java.lang.Object o)
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; }
equals
in interface ObjectKey
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |