com.ashridgetech.prevdb.client
Class PersistentManager

java.lang.Object
  |
  +--com.ashridgetech.prevdb.client.PersistentManager

public class PersistentManager
extends Object

A manager (factory) object for one class of Persistent objects.

Version:
1.0
Author:
paulb

Field Summary
protected  int lastOid
           
 
Constructor Summary
PersistentManager(PrevDb prevDb, Class persistentClass, PersistentField oidField)
          Create a PersistentManager for a class.
 
Method Summary
protected  void addNewObject(Persistent obj)
          Add a new object to this manager.
 Object allocateOid()
          Allocate a new object id for a new object.
protected  void applyChanges(FieldChangeMap fieldChanges)
          Put an object back into its state after a transaction.
 void defineNonUniqueIndex(PersistentField field)
          Define a non-unique index required for the class managed by this PersistentManager.
 Persistent findByOid(Object oid)
          Find an object by its oid.
 List findIndexedCollection(PersistentField field, Object fieldValue)
          Find the collection of objects that have a given value in a given indexed.
protected  Iterator getObjectIterator()
          Get an iterator over a notional set of FieldMaps for the objects in this PersistentManager
 PersistentField getOidField()
          Get the PersistentField that holds the oid of the class which this PersistentManager manages.
 Class getPersistentClass()
          Get the class which this PersistentManager manages
 PrevDb getPrevDb()
          Get the PrevDb that owns this PersistentManager
protected  void loadObject(FieldMap fieldMap)
          Load a persistent object into the PrevDb.
 void loadOid(Object oid)
          For any Integer oid, set the next oid returned by allocateOid() to one greater, if it is not already greater.
 void notifyFieldUpdate(Persistent obj, PersistentField field, Object oldValue, Object newValue)
          Notify this manager that a field in one of its persistent objects has been updated.
 void notifyNewObject(Persistent obj)
          Notify this manager that a new persistent object has been created.
protected  void rollbackNewObject(FieldMap fieldMap)
          Remove a new object added within the current transaction.
protected  void rollbackObject(FieldChangeMap fieldChanges)
          Put an object back into its state before a transaction.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lastOid

protected int lastOid
Constructor Detail

PersistentManager

public PersistentManager(PrevDb prevDb,
                         Class persistentClass,
                         PersistentField oidField)
Create a PersistentManager for a class.

Parameters:
prevDb - the PrevDb that owns this PersistentManager
persistentClass - the class which this PersistentManager manages
oidField - the oid field of the class which this PersistentManager manages
Method Detail

getPrevDb

public PrevDb getPrevDb()
Get the PrevDb that owns this PersistentManager

Returns:
the PrevDb

getPersistentClass

public Class getPersistentClass()
Get the class which this PersistentManager manages

Returns:
the class

getOidField

public PersistentField getOidField()
Get the PersistentField that holds the oid of the class which this PersistentManager manages. This is the unique identifier for objects of this object's class.

Returns:
the field

allocateOid

public Object allocateOid()
Allocate a new object id for a new object. This implementation allocates an Integer with the next in a series of numbers that starts at one, but is then set to one greater than the highest Integer oid passed to loadOid(java.lang.Object). If this method is overridden, loadOid(java.lang.Object) should also be overridden.

Returns:
the new oid
See Also:
loadOid(java.lang.Object)

loadOid

public void loadOid(Object oid)
For any Integer oid, set the next oid returned by allocateOid() to one greater, if it is not already greater. Non-integer oids are ignored.

Parameters:
oid - the oid
See Also:
allocateOid()

findByOid

public Persistent findByOid(Object oid)
Find an object by its oid. This is the unique identifier for objects of that object's class.

Parameters:
oid - the oid - must be a valid oid for the class managed by this PersistentManager
Throws:
ObjectNotFoundException - if there is no object with the given oid

defineNonUniqueIndex

public void defineNonUniqueIndex(PersistentField field)
Define a non-unique index required for the class managed by this PersistentManager.

Parameters:
field - the field to be indexed

findIndexedCollection

public List findIndexedCollection(PersistentField field,
                                  Object fieldValue)
Find the collection of objects that have a given value in a given indexed.

Parameters:
field - the indexed field - must have an index defined with defineNonUniqueIndex(com.ashridgetech.prevdb.client.PersistentField).
fieldValue - the value of the field for which the collection of objects is required

notifyNewObject

public void notifyNewObject(Persistent obj)
Notify this manager that a new persistent object has been created.

Parameters:
obj - the new object

addNewObject

protected void addNewObject(Persistent obj)
Add a new object to this manager.

Parameters:
obj - the new object

notifyFieldUpdate

public void notifyFieldUpdate(Persistent obj,
                              PersistentField field,
                              Object oldValue,
                              Object newValue)
Notify this manager that a field in one of its persistent objects has been updated.

Parameters:
obj - the new object
field - the field changed
oldValue - the value of the field before this change
newValue - the value of the field after this change

toString

public String toString()
Overrides:
toString in class Object

loadObject

protected void loadObject(FieldMap fieldMap)
                   throws DataException
Load a persistent object into the PrevDb.

Parameters:
fieldMap - the fields of the object to load.
DataException

getObjectIterator

protected Iterator getObjectIterator()
Get an iterator over a notional set of FieldMaps for the objects in this PersistentManager

Returns:
the iterator

applyChanges

protected void applyChanges(FieldChangeMap fieldChanges)
Put an object back into its state after a transaction.

Parameters:
fieldChanges - the changes made

rollbackObject

protected void rollbackObject(FieldChangeMap fieldChanges)
Put an object back into its state before a transaction.

Parameters:
fieldChanges - the changes made

rollbackNewObject

protected void rollbackNewObject(FieldMap fieldMap)
Remove a new object added within the current transaction.

Parameters:
fieldMap - the fieldMap of the new object's fields


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.