org.elkoserver.objdb
Class ObjDBLocal

java.lang.Object
  extended by org.elkoserver.objdb.ObjDBLocal
All Implemented Interfaces:
TypeResolver, ObjDB

public class ObjDBLocal
extends Object

Asynchronous access to a local instance of the object database. This is implemented as a separate run queue thread synchronously accessing a local object store.


Constructor Summary
ObjDBLocal(BootProperties props, String propRoot, Trace appTrace)
          Create an object to access a local object store.
 
Method Summary
 void addClass(String tag, Class<?> type)
          Inform the object database about a mapping from a JSON object type tag string to a Java class.
protected  Object decodeJSONObject(JSONObject jsonObj)
          Convert a parsed JSON object description into the object it describes.
 void getObject(String ref, String collectionName, ArgRunnable handler)
          Fetch an object from the store.
 void putObject(String ref, Encodable obj, String collectionName, boolean requireNew, ArgRunnable handler)
          Store an object into the store.
 void queryObjects(JSONObject template, String collectionName, int maxResults, ArgRunnable handler)
          Query the object store.
 void removeObject(String ref, String collectionName, ArgRunnable handler)
          Delete an object from the store.
 Class<?> resolveType(Class<?> baseType, String typeName)
          Get the class associated with a given JSON type tag string.
 void shutdown()
          Shutdown the object database.
 void updateObject(String ref, int version, Encodable obj, String collectionName, ArgRunnable handler)
          Update an object in the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjDBLocal

public ObjDBLocal(BootProperties props,
                  String propRoot,
                  Trace appTrace)
Create an object to access a local object store.

The property "propRoot.objstore" may specify the fully qualified Java class name of the object store implementation to use. If unspecified, the default, "org.elkoserver.objdb.store.filestore.FileObjectStore", will be used.

The property "propRoot.classdesc" may specify a (comma-separated) list of references to class description objects to read from the store at startup time.

Other properties may be interpreted as appropriate for the particular object store implementation selected.

Parameters:
props - Properties that the hosting server was configured with
propRoot - Prefix string for selecting relevant configuration properties.
appTrace - Trace object for event logging.
Method Detail

getObject

public void getObject(String ref,
                      String collectionName,
                      ArgRunnable handler)
Fetch an object from the store.

Parameters:
ref - Reference string naming the object desired.
collectionName - Name of collection to get from, or null to take the configured default (or the db doesn't use this abstraction).
handler - Handler to be called with the result. The result will be the object requested, or null if the object could not be retrieved.

putObject

public void putObject(String ref,
                      Encodable obj,
                      String collectionName,
                      boolean requireNew,
                      ArgRunnable handler)
Store an object into the store.

Parameters:
ref - Reference string naming the object to be stored.
obj - The object to be stored.
collectionName - Name of collection to put into, or null to take the configured default (or the db doesn't use this abstraction).
requireNew - If true, require that the object with the given ref not already exist
handler - Handler to be called with the result. The result will be a status indicator: an error message string if there was an error, or null if the operation was successful.

updateObject

public void updateObject(String ref,
                         int version,
                         Encodable obj,
                         String collectionName,
                         ArgRunnable handler)
Update an object in the store.

Parameters:
ref - Reference string naming the object to be stored.
version - Version number of the object to be updated
obj - The object to be stored.
collectionName - Name of collection to put into, or null to take the configured default (or the db doesn't use this abstraction).
handler - Handler to be called with the result. The result will be a status indicator: an error message string if there was an error, or null if the operation was successful.

queryObjects

public void queryObjects(JSONObject template,
                         String collectionName,
                         int maxResults,
                         ArgRunnable handler)
Query the object store.

Parameters:
template - Query template indicating the object(s) desired.
collectionName - Name of collection to query, or null to take the configured default.
maxResults - Maximum number of result objects to return, or 0 to indicate no fixed limit.
handler - Handler to be called with the results. The results will be an array of the object(s) requested, or null if no objects could be retrieved.

removeObject

public void removeObject(String ref,
                         String collectionName,
                         ArgRunnable handler)
Delete an object from the store. Note that it is not considered an error to attempt to remove an object that is not there; such an operation always succeeds.

Parameters:
ref - Reference string naming the object to remove.
collectionName - Name of collection to delete from, or null to take the configured default (or the db doesn't use this abstraction).
handler - Handler to be called with the result. The result will be a status indicator: an error message string if there was an error, or null if the operation was successful.

shutdown

public void shutdown()
Shutdown the object database.


addClass

public void addClass(String tag,
                     Class<?> type)
Inform the object database about a mapping from a JSON object type tag string to a Java class.

Specified by:
addClass in interface ObjDB
Parameters:
tag - The JSON object type tag string.
type - The class that 'tag' labels.

decodeJSONObject

protected Object decodeJSONObject(JSONObject jsonObj)
Convert a parsed JSON object description into the object it describes.

Parameters:
jsonObj - The object being decoded.
Returns:
the object described by 'jsonObj'.

resolveType

public Class<?> resolveType(Class<?> baseType,
                            String typeName)
Get the class associated with a given JSON type tag string.

Specified by:
resolveType in interface TypeResolver
Parameters:
baseType - Base class from which result class must be derived.
typeName - JSON type tag identifying the desired class.
Returns:
a class named by 'typeName' suitable for assignment to a method or constructor parameter of class 'baseType'.