uk.ac.bbk.dcs.automed.hdmstore
Class HdmStore

java.lang.Object
  extended by uk.ac.bbk.dcs.automed.hdmstore.HdmStore

public class HdmStore
extends java.lang.Object

A HdmStore allows data to be stored and queried in an HDM repository which is implemented in a Postgres databas).

Author:
Dean Williams (dean@dcs.bbk.ac.uk)

Field Summary
 Debug debug
           
static char edgeSpan
           
static char nodeSpan
           
 
Constructor Summary
HdmStore()
          Default constructor assumes only error messages should be displayed (not debugs)
HdmStore(Debug pDebug)
          Constructor is passed debug class to send debug & error messages to
 
Method Summary
 boolean addEdge(Edge edge)
          Takes an Edge struture and stores this in the database.
 boolean addNode(java.lang.String nodeType, java.lang.String nodeValue)
          Takes a node type and a value and adds to the database
 boolean connect()
          If connecting to the HDM store without a schema being passed assume same data source as for the MDR
 boolean connect(java.lang.String schemaName)
          Connect to the database using the access method for the named schema.
 boolean connect(java.lang.String schemaName, java.lang.String passWord)
          Connect to the database using the access method for the named schema using the access method in the repository for the schema and the password supplied.
 boolean createDBtables()
           
 boolean createDBtables(java.lang.String schemaName)
          Check to see if the repository tables are in place on the HDM store data source.
 boolean createHdmStore(java.lang.String schemaName, java.lang.String hdmStoreName)
          Create a logical HDM store for the given schema.
 boolean deleteEdge(java.lang.String edgeType, java.lang.String edgeValue)
          Check the node type is valid & and instance of the node with this value exists.
 boolean deleteNode(java.lang.String nodeType, java.lang.String nodeValue)
          Check the node type is valid & and instance of the node with this value exists.
 void dropSequence()
          Older versions of Postgres do not automatically drop sequences created for primary keys etc when the table is dropped - this loops through dropping the sequences explicitly.
 boolean edgeExists(Span span)
          Test to see if an edge exists has been passed a Span structure - split this out into type and and value and return the result.
 boolean edgeExists(java.lang.String edgeType, java.lang.String edgeValues)
          Does and edge with this type and value exist in the HDM store?
 boolean edgeInstanceExists(java.lang.String type, java.lang.String values)
          Check to see if an instance of this edge exists in the HDM store
 boolean edgeNameIsUnique(java.lang.String edgeName)
          Edge names dont have to be unique - the combination of edge name and types is unique i.e.
 boolean edgeTypeExists(java.lang.String edgeType)
          Given an edge type e.g.
 java.lang.String edgeTypeForName(java.lang.String edgeName)
          Assuming edge name is unique (which need to be checked before calling) return its edge type e.g.
 java.util.LinkedList getEdgeInstances(java.lang.String edgeType)
          Return all the instances of the passed edge type as a LinkedList of Span elements, each Span representing an instance of an edge.
 java.util.LinkedList getNodeInstances(java.lang.String nodeType)
          Given a node type return all the instances in the HDM store as a LinkedList with elements of type Span, each element representing an instance
 java.util.LinkedList getSpans(int hid, int eid)
          For the edge specified return a LinkedList with each element of type Span representing a span in that edge.
 boolean hdmStoreExists(java.lang.String hdmStoreName)
          Is there an HDM store with the passed name in the repository?
 int hid(java.lang.String hdmStoreName)
          Given an HDM store name return its row id number (or -1 if it does not exist)
 void listNodes()
          Want to display all the nodes so pass just a wildcard as a the pattern
 void listNodes(java.lang.String nodeType)
          List the instance nodes of the passed nodeType (or wildcard)
 boolean nodeExists(Span span)
          For the node instance specifed in the Span data structure check if it exists in the HDM store
 boolean nodeExists(java.lang.String nodeType, java.lang.String nodeValue)
          For the node instance specifed by node type & value, check if it exists in the HDM store
 boolean nodeTypeExists(java.lang.String nodeType)
          Check whether any instances of this node type are currently stored in the HDM store
 int numberOfRowsInResultSet(java.sql.ResultSet rset)
          Given a result set - how many rows are in it?
 boolean okToAddEdge(Edge edge)
          Given an Edge is it OK to add the edge e.g.
 java.lang.String schemaName(java.lang.String hdmStoreName)
          Given an HDM store name return the name of the schema it stores data for
 void setAddMissingNodes(boolean pAddMissingNodes)
          If you try to add an instance of an edge then all the nodes and edges that are spans of the new edge must already exist in the database.
 boolean setDatatype(java.lang.String nodeType, java.lang.String datatype)
          The meta data for an HDM store is contained in the associated AutoMed schema except for the data type of the nodes in the schema which are set with this method (initially they default to String)
 boolean use(java.lang.String hdmStoreName)
          Use the named HDM store - subsequent calls to this HdmStore will use this store as default
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeSpan

public static final char nodeSpan
See Also:
Constant Field Values

edgeSpan

public static final char edgeSpan
See Also:
Constant Field Values

debug

public Debug debug
Constructor Detail

HdmStore

public HdmStore()
Default constructor assumes only error messages should be displayed (not debugs)


HdmStore

public HdmStore(Debug pDebug)
Constructor is passed debug class to send debug & error messages to

Method Detail

addEdge

public boolean addEdge(Edge edge)
Takes an Edge struture and stores this in the database. Returned boolean indicates if successful.


addNode

public boolean addNode(java.lang.String nodeType,
                       java.lang.String nodeValue)
Takes a node type and a value and adds to the database


connect

public boolean connect()
If connecting to the HDM store without a schema being passed assume same data source as for the MDR


connect

public boolean connect(java.lang.String schemaName)
Connect to the database using the access method for the named schema. As no password has been supplied assume its null.


connect

public boolean connect(java.lang.String schemaName,
                       java.lang.String passWord)
Connect to the database using the access method for the named schema using the access method in the repository for the schema and the password supplied.


createDBtables

public boolean createDBtables()

createDBtables

public boolean createDBtables(java.lang.String schemaName)
Check to see if the repository tables are in place on the HDM store data source. If not, create them.


createHdmStore

public boolean createHdmStore(java.lang.String schemaName,
                              java.lang.String hdmStoreName)
Create a logical HDM store for the given schema. Check schema exists and add default node type of String for all the nodes in the schema.


deleteEdge

public boolean deleteEdge(java.lang.String edgeType,
                          java.lang.String edgeValue)
Check the node type is valid & and instance of the node with this value exists. If it does - delete it.


deleteNode

public boolean deleteNode(java.lang.String nodeType,
                          java.lang.String nodeValue)
Check the node type is valid & and instance of the node with this value exists. If it does - delete it.


dropSequence

public void dropSequence()
Older versions of Postgres do not automatically drop sequences created for primary keys etc when the table is dropped - this loops through dropping the sequences explicitly.


edgeExists

public boolean edgeExists(Span span)
Test to see if an edge exists has been passed a Span structure - split this out into type and and value and return the result.


edgeExists

public boolean edgeExists(java.lang.String edgeType,
                          java.lang.String edgeValues)
Does and edge with this type and value exist in the HDM store?


edgeInstanceExists

public boolean edgeInstanceExists(java.lang.String type,
                                  java.lang.String values)
Check to see if an instance of this edge exists in the HDM store


edgeNameIsUnique

public boolean edgeNameIsUnique(java.lang.String edgeName)
Edge names dont have to be unique - the combination of edge name and types is unique i.e. you could have both edges <> and <> (though its probably a bad idea if you have) Given an edge name e.g. 'worksIn' return a boolean to indicate if its unique


edgeTypeExists

public boolean edgeTypeExists(java.lang.String edgeType)
Given an edge type e.g. <> does that edge exist in the schema?


edgeTypeForName

public java.lang.String edgeTypeForName(java.lang.String edgeName)
Assuming edge name is unique (which need to be checked before calling) return its edge type e.g. passed livesAt return <>


getEdgeInstances

public java.util.LinkedList getEdgeInstances(java.lang.String edgeType)
Return all the instances of the passed edge type as a LinkedList of Span elements, each Span representing an instance of an edge.


getNodeInstances

public java.util.LinkedList getNodeInstances(java.lang.String nodeType)
Given a node type return all the instances in the HDM store as a LinkedList with elements of type Span, each element representing an instance


getSpans

public java.util.LinkedList getSpans(int hid,
                                     int eid)
For the edge specified return a LinkedList with each element of type Span representing a span in that edge.


hdmStoreExists

public boolean hdmStoreExists(java.lang.String hdmStoreName)
Is there an HDM store with the passed name in the repository?


hid

public int hid(java.lang.String hdmStoreName)
Given an HDM store name return its row id number (or -1 if it does not exist)


listNodes

public void listNodes()
Want to display all the nodes so pass just a wildcard as a the pattern


listNodes

public void listNodes(java.lang.String nodeType)
List the instance nodes of the passed nodeType (or wildcard)


nodeExists

public boolean nodeExists(Span span)
For the node instance specifed in the Span data structure check if it exists in the HDM store


nodeExists

public boolean nodeExists(java.lang.String nodeType,
                          java.lang.String nodeValue)
For the node instance specifed by node type & value, check if it exists in the HDM store


nodeTypeExists

public boolean nodeTypeExists(java.lang.String nodeType)
Check whether any instances of this node type are currently stored in the HDM store


numberOfRowsInResultSet

public int numberOfRowsInResultSet(java.sql.ResultSet rset)
Given a result set - how many rows are in it?


okToAddEdge

public boolean okToAddEdge(Edge edge)
Given an Edge is it OK to add the edge e.g. are all the spans valid type & do the instances exist?


schemaName

public java.lang.String schemaName(java.lang.String hdmStoreName)
Given an HDM store name return the name of the schema it stores data for


setAddMissingNodes

public void setAddMissingNodes(boolean pAddMissingNodes)
If you try to add an instance of an edge then all the nodes and edges that are spans of the new edge must already exist in the database. Setting add missing nodes will insert any missing nodes that would otherwise cause an add edge to fail.


setDatatype

public boolean setDatatype(java.lang.String nodeType,
                           java.lang.String datatype)
The meta data for an HDM store is contained in the associated AutoMed schema except for the data type of the nodes in the schema which are set with this method (initially they default to String)


use

public boolean use(java.lang.String hdmStoreName)
Use the named HDM store - subsequent calls to this HdmStore will use this store as default