org.sourceforge.jemm.database.components
Class DefaultDBObjectHandler

java.lang.Object
  extended by org.sourceforge.jemm.database.components.DefaultDBObjectHandler
All Implemented Interfaces:
DBObjectHandler, ObjectAccessor

public class DefaultDBObjectHandler
extends java.lang.Object
implements DBObjectHandler, ObjectAccessor

Default implementation of DBObjectHandler used by BaseDatabase based implementations.

Author:
Rory Graves

Constructor Summary
DefaultDBObjectHandler(StorageEngine storageEngine, DBClassHandler classHandler, DBClientRefHandler clientRefHandler)
          Creates a DefaultDBObjectHandler instance with the given parameters.
 
Method Summary
 boolean checkExists(ID objectId)
           
 ID createObject(ClientId clientId, ClassId classId)
          Creates a new user object with the given class type.
 StoredListObject getListObject(ID objectId)
          Returns the stored jemm list object referred to by 'id'
 StoredMapObject getMapObject(ID objectId)
          Returns the stored jemm map object referred to by 'id'
 int getNoLocksHeld()
          Debug method to return the number of locks currently held
 StoredObject getObject(ID objectId)
           
 java.util.Set<ID> getObjectChildren(ID id)
           
 int getObjectCount()
           
 StoredSetObject getSetObject(ID objectId)
          Returns the stored jemm set object referred to by 'id'
 StoredUserObject getUserObject(ID objectId)
          Returns the stored user object referred to by 'id'
 java.util.Iterator<ID> idIterator()
          Returns an iterator over the currently active ID set
 void registerType(ClassId classId, TypeHandler handler)
          Register a type handler for the given type class.
 void release(StoredObject object)
           
 void removeObject(ID id)
          Remote the object with the given id.
protected  void saveObject(StoredObject object)
           
 void setObjectStatusListener(ObjectStatusListener objectStatusListener)
          Sets the object status listener.
 ObjectSyncResp synchroniseObject(ID objectId, ObjectSyncData syncData)
           
 void update(StoredObject object)
          Update the given stored object, persisting its state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDBObjectHandler

public DefaultDBObjectHandler(StorageEngine storageEngine,
                              DBClassHandler classHandler,
                              DBClientRefHandler clientRefHandler)
Creates a DefaultDBObjectHandler instance with the given parameters.

Parameters:
storageEngine - The underlying storage engine.
classHandler - The class handler to use.
clientRefHandler - The client reference handler to use.
Method Detail

setObjectStatusListener

public void setObjectStatusListener(ObjectStatusListener objectStatusListener)
Description copied from interface: DBObjectHandler
Sets the object status listener.

Specified by:
setObjectStatusListener in interface DBObjectHandler
Parameters:
objectStatusListener - The new object status listener to use.

getObject

public StoredObject getObject(ID objectId)
Specified by:
getObject in interface DBObjectHandler
Specified by:
getObject in interface ObjectAccessor

update

public void update(StoredObject object)
Description copied from interface: DBObjectHandler
Update the given stored object, persisting its state.

Specified by:
update in interface DBObjectHandler
Parameters:
object - The object to update

getUserObject

public StoredUserObject getUserObject(ID objectId)
Returns the stored user object referred to by 'id'

Specified by:
getUserObject in interface DBObjectHandler
Specified by:
getUserObject in interface ObjectAccessor
Parameters:
objectId - The id of the object to retrieve.
Throws:
java.lang.IllegalArgumentException - If 'id' is null or is not UOBJECT type id.
java.lang.IllegalStateException - If the object is not in the database (an internal error), or the type of the retrieved object is not a user object.

getListObject

public StoredListObject getListObject(ID objectId)
Description copied from interface: ObjectAccessor
Returns the stored jemm list object referred to by 'id'

Specified by:
getListObject in interface DBObjectHandler
Specified by:
getListObject in interface ObjectAccessor

getSetObject

public StoredSetObject getSetObject(ID objectId)
Description copied from interface: ObjectAccessor
Returns the stored jemm set object referred to by 'id'

Specified by:
getSetObject in interface DBObjectHandler
Specified by:
getSetObject in interface ObjectAccessor
Parameters:
objectId - The id of the set to retrieve.

getMapObject

public StoredMapObject getMapObject(ID objectId)
Description copied from interface: ObjectAccessor
Returns the stored jemm map object referred to by 'id'

Specified by:
getMapObject in interface DBObjectHandler
Specified by:
getMapObject in interface ObjectAccessor
Parameters:
objectId - The id of the map to retrieve.

createObject

public ID createObject(ClientId clientId,
                       ClassId classId)
Creates a new user object with the given class type.

N.b. Once initialisation is complete - caller should call objectAccessor.initialisationFinished on the returned id.

Specified by:
createObject in interface DBObjectHandler
Specified by:
createObject in interface ObjectAccessor
Parameters:
classId - The classId of the new object.
Returns:
The id of the newly created object.

synchroniseObject

public ObjectSyncResp synchroniseObject(ID objectId,
                                        ObjectSyncData syncData)
Specified by:
synchroniseObject in interface DBObjectHandler
Parameters:
objectId - The id of the object being synchronized
syncData - The synchronisation data, containing updated fields and current client version.
Returns:
The synchronized object response data.

removeObject

public void removeObject(ID id)
Description copied from interface: DBObjectHandler
Remote the object with the given id.

Specified by:
removeObject in interface DBObjectHandler
Specified by:
removeObject in interface ObjectAccessor
Parameters:
id - The id of the object to remove.

getObjectCount

public int getObjectCount()
Specified by:
getObjectCount in interface DBObjectHandler
Returns:
The number of objects held in this database.

checkExists

public boolean checkExists(ID objectId)
Specified by:
checkExists in interface DBObjectHandler
Specified by:
checkExists in interface ObjectAccessor

release

public void release(StoredObject object)
Specified by:
release in interface DBObjectHandler
Specified by:
release in interface ObjectAccessor

saveObject

protected void saveObject(StoredObject object)

getNoLocksHeld

public int getNoLocksHeld()
Description copied from interface: DBObjectHandler
Debug method to return the number of locks currently held

Specified by:
getNoLocksHeld in interface DBObjectHandler
Returns:
The number of lock currently held

idIterator

public java.util.Iterator<ID> idIterator()
Description copied from interface: ObjectAccessor
Returns an iterator over the currently active ID set

Specified by:
idIterator in interface ObjectAccessor
Returns:
An iterator over valid IDs

getObjectChildren

public java.util.Set<ID> getObjectChildren(ID id)
Specified by:
getObjectChildren in interface ObjectAccessor

registerType

public void registerType(ClassId classId,
                         TypeHandler handler)
Description copied from interface: DBObjectHandler
Register a type handler for the given type class.

Specified by:
registerType in interface DBObjectHandler
Parameters:
classId - The class id of the type class being handled.
handler - The registered handler.


Copyright © 2009. All Rights Reserved.