com.ashridgetech.prevdb.client
Class AbstractPersistentObject

java.lang.Object
  |
  +--com.ashridgetech.prevdb.client.AbstractPersistentObject
All Implemented Interfaces:
Persistent
Direct Known Subclasses:
TestClassA, TestClassB, TestClassC

public abstract class AbstractPersistentObject
extends Object
implements Persistent

A convenient base class for classes that want to implement Persistent. Holds an oid. Cooperates with its PersistentManager.

Version:
1.0
Author:
paulb

Field Summary
 Object oid
           
static PersistentField OID
           
protected static PersistentField[] PERSISTENT_FIELDS
           
 
Constructor Summary
protected AbstractPersistentObject(PersistentManager manager)
           
protected AbstractPersistentObject(PersistentManager manager, Object oid)
           
protected AbstractPersistentObject(PrevDb prevDb, Class thisClass)
           
 
Method Summary
 Object getField(PersistentField field)
          Get the value of a single field.
 FieldMap getFields()
          Get a map of all the persistent fields in this object.
protected  Object getJavaField(Field javaField)
          Get the value of a Java field.
 PersistentManager getManager()
          Get the PersistentManager for this class
 Object getOid()
          Get the oid of this object.
static PersistentField getPersistentField(PersistentField[] persistentFields, String name)
          Get a PersistentField from an array by name.
protected  PersistentField[] getPersistentFields()
          Provide an array of PersistentFields for this object.
protected  int notifyUpdate(PersistentField field, int oldValue, int newValue)
           
protected  Object notifyUpdate(PersistentField field, Object oldValue, Object newValue)
          Convenience method to allow a subclass setter method to call PersistentManager.notifyFieldUpdate(com.ashridgetech.prevdb.client.Persistent, com.ashridgetech.prevdb.client.PersistentField, java.lang.Object, java.lang.Object).
protected  String notifyUpdate(PersistentField field, String oldValue, String newValue)
           
 void setField(PersistentField field, Object value)
          Set the value of a single field.
 void setFields(FieldMap fields)
          Set some or all of the fields in this object.
protected  void setJavaField(Field javaField, Object value)
          Set the value of a Java field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oid

public Object oid

OID

public static final PersistentField OID

PERSISTENT_FIELDS

protected static final PersistentField[] PERSISTENT_FIELDS
Constructor Detail

AbstractPersistentObject

protected AbstractPersistentObject(PersistentManager manager,
                                   Object oid)

AbstractPersistentObject

protected AbstractPersistentObject(PersistentManager manager)

AbstractPersistentObject

protected AbstractPersistentObject(PrevDb prevDb,
                                   Class thisClass)
Method Detail

getOid

public Object getOid()
Description copied from interface: Persistent
Get the oid of this object. This is the unique identifier for objects of this object's class.

Specified by:
getOid in interface Persistent
Returns:
the oid

getManager

public PersistentManager getManager()
Get the PersistentManager for this class

Specified by:
getManager in interface Persistent
Returns:
the PersistentManager

getFields

public FieldMap getFields()
Description copied from interface: Persistent
Get a map of all the persistent fields in this object.

Specified by:
getFields in interface Persistent
Returns:
the field map

setFields

public void setFields(FieldMap fields)
Description copied from interface: Persistent
Set some or all of the fields in this object.

Specified by:
setFields in interface Persistent
Parameters:
fields - the fields to set

getField

public Object getField(PersistentField field)
Description copied from interface: Persistent
Get the value of a single field.

Specified by:
getField in interface Persistent
Parameters:
field - the PersistentFieldwhose value is required
Returns:
the field value

setField

public void setField(PersistentField field,
                     Object value)
Description copied from interface: Persistent
Set the value of a single field.

Specified by:
setField in interface Persistent
Parameters:
field - the PersistentFieldwhose value is to be set
value - the field value

notifyUpdate

protected Object notifyUpdate(PersistentField field,
                              Object oldValue,
                              Object newValue)
Convenience method to allow a subclass setter method to call PersistentManager.notifyFieldUpdate(com.ashridgetech.prevdb.client.Persistent, com.ashridgetech.prevdb.client.PersistentField, java.lang.Object, java.lang.Object). Returns the new value so that the notification and assignment can be done in one line eg
    public void setBalance( BigDecimal balance ) {
        this.balance = noyifyUpdate( this.balance, balance );
    }
 

Parameters:
field - the persistent field being updated
oldValue - the existing value of the field
newValue - the new value of the field
Returns:
the new value

notifyUpdate

protected String notifyUpdate(PersistentField field,
                              String oldValue,
                              String newValue)
See Also:
notifyUpdate( PersistentField, Object, Object )

notifyUpdate

protected int notifyUpdate(PersistentField field,
                           int oldValue,
                           int newValue)
See Also:
notifyUpdate( PersistentField, Object, Object )

getJavaField

protected Object getJavaField(Field javaField)
                       throws IllegalAccessException
Get the value of a Java field. Must be duplicated in each subclass to avoid access restrictions. The code required is simply return javaField.get( this );

Parameters:
javaField - the Field to get the value of
Returns:
the value
IllegalAccessException

setJavaField

protected void setJavaField(Field javaField,
                            Object value)
                     throws IllegalAccessException
Set the value of a Java field. Must be duplicated in each subclass to avoid access restrictions. The code required is simply javaField.set( this, value );

Parameters:
javaField - the Field to set the value of
value - the value to set
IllegalAccessException

getPersistentFields

protected PersistentField[] getPersistentFields()
Provide an array of PersistentFields for this object. Must include the persistent fields of the superclass, if any

Returns:
the array of PersistentFields

getPersistentField

public static PersistentField getPersistentField(PersistentField[] persistentFields,
                                                 String name)
Get a PersistentField from an array by name.

Parameters:
persistentFields - the fields to select from
name - the name of the field
Returns:
the field
Throws:
IllegalArgumentException - if no field called name exists in persistentFields


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.