nz.ac.waikato.mcennis.rat.graph.link
Class DBLink

java.lang.Object
  extended by nz.ac.waikato.mcennis.rat.graph.model.ModelShell
      extended by nz.ac.waikato.mcennis.rat.graph.link.DBLink
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Link, Listener, Model

public class DBLink
extends ModelShell
implements Link, Listener

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class nz.ac.waikato.mcennis.rat.graph.model.ModelShell
listener
 
Fields inherited from interface nz.ac.waikato.mcennis.rat.graph.link.Link
ALL, DESTINATION, RELATION, SOURCE, STRENGTH
 
Constructor Summary
DBLink()
          Creates a new instance of DerbyActor
 
Method Summary
 void add(Property prop)
          Add the given property to this link
protected  int compareProperties(Link right)
          Compare properties of this actor with the given actor.
 int compareTo(java.lang.Object o)
          Throws ClassCastException when the parameter is not an Link.
protected  int getActorID(Actor u)
          Get thye numerical ID that uniquely describes this Actor in the database
 Actor getDestination()
          Returns the actor where the link (edge, arc) terminates.
 java.util.List<Property> getProperty()
          Return all properties associated with this link.
 Property getProperty(java.lang.String ID)
          Get the property with the given name.
 java.lang.String getRelation()
          Returns the type (relation) of the link.
 Actor getSource()
          Returns the actor from which the link (edge, arc) begins.
 double getStrength()
          return the strength of this link.
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.
 DBLink prototype()
           
 void publishChange(Model m, int type, int argument)
          Saves to database the changes in a property.
 void removeProperty(java.lang.String ID)
           
 void set(Actor l, double strength, Actor r)
          sets all aspects of the link at once
 void set(double str)
          Sets the strength that this link has.
static void setDatabase(java.lang.String db)
          Set which database to access
 void setDestination(Actor u)
          Sets the destination of this link.
static void setDirectory(java.lang.String dir)
          Set the location of the Derby database directory
 void setRelation(java.lang.String type)
          Sets the type (relation) of the link.
 void setSource(Actor u)
          Sets the source of this link.
 
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.model.Model
addListener
 

Constructor Detail

DBLink

public DBLink()
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

getProperty

public java.util.List<Property> getProperty()
Description copied from interface: Link
Return all properties associated with this link. Returns null if no properties are associated with this link.

Specified by:
getProperty in interface Link
Returns:
array of properties associated with this object.

getProperty

public Property getProperty(java.lang.String ID)
Description copied from interface: Link
Get the property with the given name. Returns null if no property with that id exists.

Specified by:
getProperty in interface Link
Parameters:
ID - id of the property to be returned
Returns:
property with the given id

removeProperty

public void removeProperty(java.lang.String ID)
Specified by:
removeProperty in interface Link

add

public void add(Property prop)
Description copied from interface: Link
Add the given property to this link

Specified by:
add in interface Link

setRelation

public void setRelation(java.lang.String type)
Description copied from interface: Link
Sets the type (relation) of the link.

Specified by:
setRelation in interface Link
Parameters:
type - string describing the type

getRelation

public java.lang.String getRelation()
Description copied from interface: Link
Returns the type (relation) of the link.

Specified by:
getRelation in interface Link
Returns:
typer (relation) of this link.

compareTo

public int compareTo(java.lang.Object o)
Throws ClassCastException when the parameter is not an Link. 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(Link 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

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

getStrength

public double getStrength()
Description copied from interface: Link
return the strength of this link. This can be positive or negative or non-numeric values such as NaN, -Infinity, or Inifinity for links where only the existance of the link is important.

Specified by:
getStrength in interface Link
Returns:
strength of the link

getSource

public Actor getSource()
Description copied from interface: Link
Returns the actor from which the link (edge, arc) begins.

Specified by:
getSource in interface Link
Returns:
source actor

getDestination

public Actor getDestination()
Description copied from interface: Link
Returns the actor where the link (edge, arc) terminates.

Specified by:
getDestination in interface Link
Returns:
destination actor

set

public void set(Actor l,
                double strength,
                Actor r)
Description copied from interface: Link
sets all aspects of the link at once

Specified by:
set in interface Link
Parameters:
l - source actor
strength - strength of this length
r - destination actor

setSource

public void setSource(Actor u)
Description copied from interface: Link
Sets the source of this link. This may not be null.

Specified by:
setSource in interface Link
Parameters:
u - actor source

setDestination

public void setDestination(Actor u)
Description copied from interface: Link
Sets the destination of this link. This may not be null.

Specified by:
setDestination in interface Link
Parameters:
u - destination actor.

set

public void set(double str)
Description copied from interface: Link
Sets the strength that this link has. This may be a non-numeric value.

Specified by:
set in interface Link
Parameters:
str - sterngth of this link.

getActorID

protected int getActorID(Actor u)
Get thye numerical ID that uniquely describes this Actor in the database


prototype

public DBLink prototype()
Specified by:
prototype in interface Link

init

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

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