nz.ac.waikato.mcennis.rat.graph.actor
Class DBActor

java.lang.Object
  extended by nz.ac.waikato.mcennis.rat.graph.model.ModelShell
      extended by nz.ac.waikato.mcennis.rat.graph.actor.DBActor
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Actor, Listener, Model, ParsedObject

public class DBActor
extends ModelShell
implements Actor, Listener

Class that implemnts an actor backed by a DerbyDB database. Fixes problems of inconsistencies between the database and the in-memory data when using BasicUser class.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class nz.ac.waikato.mcennis.rat.graph.model.ModelShell
listener
 
Constructor Summary
DBActor()
          Creates a new instance of DerbyActor
 
Method Summary
 void add(Property prop)
          Add the given property to this user.
protected  int compareProperties(Actor right)
          Compare properties of this actor with the given actor.
 int compareTo(java.lang.Object o)
          Throws ClassCastException when the parameter is not an Actor.
 java.lang.String getID()
          Return the id (unique within its type)
 java.lang.String getMode()
          Returns the type (mode) of this actor
protected  void getNumericalID()
          Get thye numerical ID that uniquely describes this Actor in the database
 java.util.List<Property> getProperty()
          Return an array of all properties associated with this actor.
 Property getProperty(java.lang.String ID)
          Return the property with the given value.
static void init()
          static initialization method that sets up the global connection objects.
 void init(Properties properties)
           
static boolean isInitialized()
          Has this object been Initialized yet.
 DBActor prototype()
          Return a copy of this Actor that is equal by compareTo()
 void publishChange(Model m, int type, int argument)
          Saves to database the changes in a property.
 void removeProperty(java.lang.String ID)
          Remove a given property from this actor
static void setDatabase(java.lang.String db)
          Set which database to access
static void setDirectory(java.lang.String dir)
          Set the location of the Derby database directory
 void setID(java.lang.String id)
          Sets an id unique (which must be its type).
 void setMode(java.lang.String type)
          Set the type (mode) of this actor.
 
Methods inherited from class nz.ac.waikato.mcennis.rat.graph.model.ModelShell
addListener, fireChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nz.ac.waikato.mcennis.rat.graph.actor.Actor
equals
 

Constructor Detail

DBActor

public DBActor()
Creates a new instance of DerbyActor

Method Detail

init

public static void init()
static initialization method that sets up the global connection objects. This static connection should ultimately be replaced by a database connection pool.


isInitialized

public static boolean isInitialized()
Has this object been Initialized yet.

Returns:
is initialized or not

getID

public java.lang.String getID()
Description copied from interface: Actor
Return the id (unique within its type)

Specified by:
getID in interface Actor
Returns:
ID of this actor

setID

public void setID(java.lang.String id)
Description copied from interface: Actor
Sets an id unique (which must be its type).

Specified by:
setID in interface Actor
Parameters:
id - ID this actor should be set to

getProperty

public java.util.List<Property> getProperty()
Description copied from interface: Actor
Return an array of all properties associated with this actor. Returns null if no properties are attached.

Specified by:
getProperty in interface Actor
Returns:
array of properties

getProperty

public Property getProperty(java.lang.String ID)
Description copied from interface: Actor
Return the property with the given value. Returns null if no properties are attached.

Specified by:
getProperty in interface Actor
Parameters:
ID - key-name for the property.
Returns:
Property object having this key or null

add

public void add(Property prop)
Description copied from interface: Actor
Add the given property to this user. If a property with this name already exists, it is replaced by this property.

Specified by:
add in interface Actor
Parameters:
prop - property to be added

setMode

public void setMode(java.lang.String type)
Description copied from interface: Actor
Set the type (mode) of this actor. User ID's must be unique within a type.

Specified by:
setMode in interface Actor
Parameters:
type - new type (mode) of this actor

getMode

public java.lang.String getMode()
Description copied from interface: Actor
Returns the type (mode) of this actor

Specified by:
getMode in interface Actor
Returns:
type (mode) of this actor

prototype

public DBActor prototype()
Description copied from interface: Actor
Return a copy of this Actor that is equal by compareTo()

Specified by:
prototype in interface Actor
Returns:
new duplicate Actor

compareTo

public int compareTo(java.lang.Object o)
Throws ClassCastException when the parameter is not an Actor. Comparisons are:
  1. String compareTo on type (mode)
  2. String compareTo on ID
  3. Property comparison: return compareTo on the first pair of properties that do not return 0
  4. Page comparison: return compareTo on the first pair of pages that do not return 0
  5. return 0

Specified by:
compareTo in interface java.lang.Comparable

compareProperties

protected int compareProperties(Actor right)
Compare properties of this actor with the given actor. Sort the property arrays and compare sequentially, returning the first non-zero value or returning zero if all properties are equal.

Parameters:
right - actor to be compared against
Returns:
compareTo over all properties

getNumericalID

protected void getNumericalID()
Get thye numerical ID that uniquely describes this Actor in the database


setDirectory

public static void setDirectory(java.lang.String dir)
Set the location of the Derby database directory

Parameters:
dir - directory where thye datbases are stored

setDatabase

public static void setDatabase(java.lang.String db)
Set which database to access

Parameters:
db - name of the datbase to open

publishChange

public void publishChange(Model m,
                          int type,
                          int argument)
Saves to database the changes in a property.

Specified by:
publishChange in interface Listener
Parameters:
m - Property that changed
type - currently only 0 (Changed) is fired

init

public void init(Properties properties)
Specified by:
init in interface Actor

removeProperty

public void removeProperty(java.lang.String ID)
Description copied from interface: Actor
Remove a given property from this actor

Specified by:
removeProperty in interface Actor
Parameters:
ID - key-name of property to remove.

Get Relational Analysis Toolkit at SourceForge.net. Fast, secure and Free Open Source software downloads