org.sourceforge.jemm.client
Class DelegatingObjectDatabase

java.lang.Object
  extended by org.sourceforge.jemm.client.DelegatingObjectDatabase
All Implemented Interfaces:
ObjectDatabase, ObjectSource, TypeRequestHandler
Direct Known Subclasses:
AlwaysRefreshObjectDatabase, SynchronousLockDecorator

public abstract class DelegatingObjectDatabase
extends java.lang.Object
implements ObjectDatabase

An ObjectDatabase implementation that delegates all its calls to the ObjectDatabase passed into the constructor.

Author:
Paul Keeble

Constructor Summary
DelegatingObjectDatabase(ObjectDatabase database)
           
 
Method Summary
 void acquireLock(ClientThreadId threadId, ID jemmId)
          Asynchronous request to acquire a lock.
 ClassInfo getClassInfo(ClassId classId)
          Returns the class information for the given class id.
 EnumInfo getEnumInfo(EnumId enumId)
          Returns the classname for the given enum type id.
 JEMMObject getObject(ID jemmId)
          Retrieves an object's information from the database or a local cache if the object has already been retrieved and still in memory.
 JEMMObject getRefreshedObject(ID jemmId)
          Retrieves an object's information from the database but always calls the underlying database, updating the cache.
 JEMMObject getRoot(java.lang.String rootName)
          Returns the object stored in the persistent root called 'rootName'
 ID newObject(ClassId classId, JEMMObject obj)
          Notification of a new user object creation by the client.
 TypeResponse<?> processTypeRequest(JEMMObject jemmObject, ClassId classId, TypeRequest<?> request)
           
 void refreshObject(JEMMObject obj)
          Retrieves the fields of the object again from the store and updates the passed object with all the values.
 ClassId registerClass(ClassInfo classInfo)
          Register a user class.
 EnumId registerEnum(EnumInfo enumInfo)
          Register an enumerated type.
 void releaseLock(ClientThreadId threadId, ID jemmId)
          Release the given lock held by the thread.
 void removeLockAcquiredListener(ClientId clientId)
          Remove a lock listener
 void setClientLockAcquiredListener(ClientId clientId, LockAcquiredListener listener)
          Register a lock listener
 void setRoot(java.lang.String rootName, JEMMObject newValue)
          Set the persistent root reference to the given object.
 JEMMObject setRootIfNull(java.lang.String rootName, JEMMObject newValue)
          Sets the persistent root reference to the given object, if the root is currently null.
 void synchroniseObject(JEMMObject syncData)
          Synchronise a client held object with the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingObjectDatabase

public DelegatingObjectDatabase(ObjectDatabase database)
Method Detail

acquireLock

public void acquireLock(ClientThreadId threadId,
                        ID jemmId)
Description copied from interface: ObjectDatabase
Asynchronous request to acquire a lock. This method will return immediately, but the caller should wait until notified by the LockAcquiredListener callback.

Specified by:
acquireLock in interface ObjectDatabase
Parameters:
threadId - The requesting thread.
jemmId - The id of the object to lock.

setClientLockAcquiredListener

public void setClientLockAcquiredListener(ClientId clientId,
                                          LockAcquiredListener listener)
Description copied from interface: ObjectDatabase
Register a lock listener

Specified by:
setClientLockAcquiredListener in interface ObjectDatabase
Parameters:
clientId - The client who is interested in their lock event notifications.
listener - The listener to register.

getClassInfo

public ClassInfo getClassInfo(ClassId classId)
Description copied from interface: ObjectDatabase
Returns the class information for the given class id.

Specified by:
getClassInfo in interface ObjectDatabase
Parameters:
classId - The id of the held class.
Returns:
The class information for the held class.

getEnumInfo

public EnumInfo getEnumInfo(EnumId enumId)
Description copied from interface: ObjectDatabase
Returns the classname for the given enum type id.

Specified by:
getEnumInfo in interface ObjectDatabase
Parameters:
enumId - The enum type id.
Returns:
The classname of the registered enum type.

getObject

public JEMMObject getObject(ID jemmId)
Description copied from interface: ObjectDatabase
Retrieves an object's information from the database or a local cache if the object has already been retrieved and still in memory.

Specified by:
getObject in interface ObjectDatabase
Specified by:
getObject in interface ObjectSource
Parameters:
jemmId - The id of the object to retrieve.
Returns:
The object information (class type, field values etc.).

getRefreshedObject

public JEMMObject getRefreshedObject(ID jemmId)
Description copied from interface: ObjectDatabase
Retrieves an object's information from the database but always calls the underlying database, updating the cache.

Specified by:
getRefreshedObject in interface ObjectDatabase
Parameters:
jemmId - The id of the object to retrieve.
Returns:
The object information (class type, field values etc.).

getRoot

public JEMMObject getRoot(java.lang.String rootName)
Description copied from interface: ObjectDatabase
Returns the object stored in the persistent root called 'rootName'

Specified by:
getRoot in interface ObjectDatabase
Parameters:
rootName - The name of the persistent root.
Returns:
The ID of the object stored in the persistent root, or null if none.

newObject

public ID newObject(ClassId classId,
                    JEMMObject obj)
Description copied from interface: ObjectDatabase
Notification of a new user object creation by the client.

Specified by:
newObject in interface ObjectDatabase
Parameters:
classId - The class id of the new object (must be previously registered).
Returns:
The ID assigned to the new object.

registerClass

public ClassId registerClass(ClassInfo classInfo)
                      throws StructureModifiedException
Description copied from interface: ObjectDatabase
Register a user class.

Specified by:
registerClass in interface ObjectDatabase
Parameters:
classInfo - The information about the loaded user class (name/fields).
Returns:
The class id of the registered class.
Throws:
StructureModifiedException - if the class has been modified and the Database does not accept the change

registerEnum

public EnumId registerEnum(EnumInfo enumInfo)
                    throws StructureModifiedException
Description copied from interface: ObjectDatabase
Register an enumerated type.

Specified by:
registerEnum in interface ObjectDatabase
Parameters:
enumInfo - The enumeration type information
Returns:
Returns the id of the registered enum type.
Throws:
StructureModifiedException - If a modification to the enum is detected.

releaseLock

public void releaseLock(ClientThreadId threadId,
                        ID jemmId)
Description copied from interface: ObjectDatabase
Release the given lock held by the thread.

Specified by:
releaseLock in interface ObjectDatabase
Parameters:
threadId - The thread currently holding the lock.
jemmId - The id of the object to release.

removeLockAcquiredListener

public void removeLockAcquiredListener(ClientId clientId)
Description copied from interface: ObjectDatabase
Remove a lock listener

Specified by:
removeLockAcquiredListener in interface ObjectDatabase
Parameters:
clientId - The id the the client who is no longer interested in lock events.

setRoot

public void setRoot(java.lang.String rootName,
                    JEMMObject newValue)
Description copied from interface: ObjectDatabase
Set the persistent root reference to the given object.

Specified by:
setRoot in interface ObjectDatabase
Parameters:
rootName - The name of the persistent root.
newValue - The new value of the root.

setRootIfNull

public JEMMObject setRootIfNull(java.lang.String rootName,
                                JEMMObject newValue)
Description copied from interface: ObjectDatabase
Sets the persistent root reference to the given object, if the root is currently null. This is an atomic operation.

Specified by:
setRootIfNull in interface ObjectDatabase
Parameters:
rootName - The name of the persistent root.
newValue - The new value of the root.
Returns:
The old value if it was not null, or the recently set value.

synchroniseObject

public void synchroniseObject(JEMMObject syncData)
Description copied from interface: ObjectDatabase
Synchronise a client held object with the server. Passing in the current client version and any updated fields this method returns the new version number of the object and any fields updated remotely (by another client).

Specified by:
synchroniseObject in interface ObjectDatabase
Parameters:
syncData - The object being synchronized.

refreshObject

public void refreshObject(JEMMObject obj)
Description copied from interface: ObjectDatabase
Retrieves the fields of the object again from the store and updates the passed object with all the values. This call may never be cached as its intention is to make sure everything is up to date in a locked scenario.

Specified by:
refreshObject in interface ObjectDatabase
Parameters:
obj - The object to retrieve and update

processTypeRequest

public TypeResponse<?> processTypeRequest(JEMMObject jemmObject,
                                          ClassId classId,
                                          TypeRequest<?> request)
Specified by:
processTypeRequest in interface TypeRequestHandler


Copyright © 2009. All Rights Reserved.