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(Page page)
          FIXME: Not implemented yet.
 void add(Property prop)
          Add the given property to this user.
protected  int comparePages(Actor right)
          Compare pages of this actor with the given actor.
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.
 Actor duplicate()
          Return a copy of this Actor that is equal by compareTo()
 java.lang.String getID()
          Return the id (unique within its type)
protected  void getNumericalID()
          Get thye numerical ID that uniquely describes this Actor in the database
 Page[] getPage()
          FIXME: Not implemented yet.
 Page getPage(java.lang.String ID)
          FIXME: Not implemented yet.
 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.
 java.lang.String getType()
          Returns the type (mode) of this actor
static void init()
          static initialization method that sets up the global connection objects.
static boolean isInitialized()
          Has this object been Initialized yet.
 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 setType(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 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

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.

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

getPage

public Page[] getPage()
FIXME: Not implemented yet.

Specified by:
getPage in interface Actor
Returns:
array of Page objects

getPage

public Page getPage(java.lang.String ID)
FIXME: Not implemented yet.

Specified by:
getPage in interface Actor
Parameters:
ID - id of the page to be returned
Returns:
page with the given id

add

public void add(Page page)
FIXME: Not implemented yet.

Specified by:
add in interface Actor
Parameters:
page - Page to be added.

setType

public void setType(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:
setType in interface Actor
Parameters:
type - new type (mode) of this actor

getType

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

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

duplicate

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

Specified by:
duplicate 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

comparePages

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

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

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