com.hp.hpl.guess.db
Class DBServer

java.lang.Object
  extended bycom.hp.hpl.guess.db.DBServer
All Implemented Interfaces:
StorageListener

public class DBServer
extends Object
implements StorageListener


Field Summary
static boolean EDGE
           
static Hashtable edgedefs
           
static boolean NODE
           
static Hashtable nodedefs
           
 
Constructor Summary
DBServer(String db_file_name_prefix)
           
 
Method Summary
 void addEdge(Edge e)
           
 void addField(Field f)
          add a new field to the database
 void addNode(Node node)
           
 void alter(String columnname, String query)
           
 void closeStatements()
           
 boolean containsEdge(Edge e)
           
 boolean containsEdge(Edge e, String state)
           
 boolean containsNode(Node n)
           
 boolean containsNode(Node n, String state)
           
 int createDirectedEdge(Node source, Node dest)
          adds a new edge to the database and return its ID.
 int createDirectedEdge(Node source, Node dest, int id)
          adds a new edge to the database and return its ID.
 void createEmpty()
           
 int createUndirectedEdge(Node source, Node dest)
          adds a new edge to the database and return its ID.
 int createUndirectedEdge(Node source, Node dest, int id)
          adds a new edge to the database and return its ID.
static void dump(ResultSet rs)
           
 void exportGDF(String filename)
           
 void fillSchema(EdgeSchema schema, Graph g)
          This usually gets called once to add the fields alrady present for nodes that the database knows about.
 void fillSchema(NodeSchema schema, Graph g)
          This usually gets called once to add the fields alrady present for nodes that the database knows about.
 void findMatchingEdges(Query q)
          find all matching edges for query q, q will be modified to hold the results
 void findMatchingNodes(Query q)
          find all matching nodes for query q, q will be modified to hold the results
static String fixString(String init, Hashtable defs)
           
 Object getColumn(Edge e, Field f)
          returns the value of Field f in for Edge n
 Object getColumn(Edge e, Field f, int s)
          returns the value of Field f in for Edge n
 Object getColumn(Edge e, Field f, String s)
          returns the value of Field f in for Edge n
 Object getColumn(Node n, Field f)
          returns the value of Field f in for Node n
 Object getColumn(Node n, Field f, int s)
          returns the value of Field f in for Node n
 Object getColumn(Node n, Field f, String s)
          returns the value of Field f in for Node n
 Object[] getColumns(Edge e, Field[] f)
          returns the value of Field[] f in for Edge n
 Object[] getColumns(Edge e, Field[] f, int s)
          returns the value of Field[] f in for Edge n
 Object[] getColumns(Edge e, Field[] f, String s)
          returns the value of Field[] f in for Edge n
 Object[] getColumns(Node n, Field[] f)
          returns the value of Field[] f in for Node n
 Object[] getColumns(Node n, Field[] f, int s)
          returns the value of Field[] f in for Node n
 Object[] getColumns(Node n, Field[] f, String s)
          returns the value of Field[] f in for Node n
 boolean getCommitState()
           
static DBServer getDBServer()
           
 Vector getEdgesNotInCurrent(Graph g, int statenum)
           
 Vector getEdgesNotInCurrent(Graph g, String statenum)
           
 AbstractTableModel getEdgeTable()
           
 void getNodeColumn(Hashtable ht, String column, String limit)
           
 Vector getNodesNotInCurrent(Graph g, int statenum)
           
 Vector getNodesNotInCurrent(Graph g, String statenum)
           
 AbstractTableModel getNodeTable()
           
 Statement getStatement()
           
 PreparedStatement getStatement(String prep)
           
 Set getStates()
           
 Object getStatistic(Field f, String s)
           
 Object getStatistic(Field f, String s, String state)
           
static String getTypeString(int type)
           
 int identity()
           
static DBServer init(String dbname)
           
static DBServer initInMemory()
           
 void loadFromFile(String text)
           
 void loadFromText(String text)
           
 void loadState(Graph g, int statenum)
           
 void loadState(Graph g, String statenum)
           
 void loadState(int state)
           
 void loadState(String state)
           
static void main(String[] args)
           
 String prettyPrintResult(String query)
           
 void q(String expression)
           
 void query(String expression)
          executes the query specified by expression
 void refresh(Graph g)
          call this to load up all the nodes/edges from the database into the graph.
 void remove(Edge edge)
           
 void remove(Node node)
           
 void removeComplete(Edge edge)
           
 void removeComplete(Node node)
           
static void resetSingleton()
           
 void saveCSV(String filename, String expression)
           
 void saveState(int statenum)
           
 void saveState(String statenum)
           
 void setCommitState(boolean state)
           
 void shutdown()
          shutdown operator, once you call this don't assume you can do anything with the StorageListener
 void shutdownConn()
           
static String[] stringSplit(String line)
           
 void undelete(Edge e)
           
 void undelete(Node node)
           
 void update(String expression)
           
 void update(String expression, Statement st)
           
 void updateColumn(Edge n, Field f, Object value)
          call this to update the value for field f for Edge n.
 void updateColumn(Node n, Field f, Object value)
          call this to update the value for field f for Node n.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE

public static final boolean NODE
See Also:
Constant Field Values

EDGE

public static final boolean EDGE
See Also:
Constant Field Values

nodedefs

public static Hashtable nodedefs

edgedefs

public static Hashtable edgedefs
Constructor Detail

DBServer

public DBServer(String db_file_name_prefix)
         throws Exception
Method Detail

getStatement

public Statement getStatement()
                       throws SQLException
Throws:
SQLException

getStates

public Set getStates()
Specified by:
getStates in interface StorageListener

setCommitState

public void setCommitState(boolean state)

getCommitState

public boolean getCommitState()

getColumn

public Object getColumn(Node n,
                        Field f)
Description copied from interface: StorageListener
returns the value of Field f in for Node n

Specified by:
getColumn in interface StorageListener
Parameters:
n - the node you want the result for
f - the field

getColumn

public Object getColumn(Edge e,
                        Field f)
Description copied from interface: StorageListener
returns the value of Field f in for Edge n

Specified by:
getColumn in interface StorageListener
Parameters:
f - the field

getColumn

public Object getColumn(Node n,
                        Field f,
                        String s)
Description copied from interface: StorageListener
returns the value of Field f in for Node n

Specified by:
getColumn in interface StorageListener
Parameters:
n - the node you want the result for
f - the field
s - the state to retrieve from

getStatistic

public Object getStatistic(Field f,
                           String s)
Specified by:
getStatistic in interface StorageListener

getStatistic

public Object getStatistic(Field f,
                           String s,
                           String state)

getColumn

public Object getColumn(Edge e,
                        Field f,
                        String s)
Description copied from interface: StorageListener
returns the value of Field f in for Edge n

Specified by:
getColumn in interface StorageListener
Parameters:
f - the field
s - the state to retrieve from

getColumn

public Object getColumn(Node n,
                        Field f,
                        int s)
Description copied from interface: StorageListener
returns the value of Field f in for Node n

Specified by:
getColumn in interface StorageListener
Parameters:
n - the node you want the result for
f - the field
s - the state to retrieve from

getColumn

public Object getColumn(Edge e,
                        Field f,
                        int s)
Description copied from interface: StorageListener
returns the value of Field f in for Edge n

Specified by:
getColumn in interface StorageListener
Parameters:
f - the field
s - the state to retrieve from

getColumns

public Object[] getColumns(Node n,
                           Field[] f)
Description copied from interface: StorageListener
returns the value of Field[] f in for Node n

Specified by:
getColumns in interface StorageListener
Parameters:
n - the node you want the result for
f - the field

getColumns

public Object[] getColumns(Edge e,
                           Field[] f)
Description copied from interface: StorageListener
returns the value of Field[] f in for Edge n

Specified by:
getColumns in interface StorageListener
Parameters:
f - the field

getColumns

public Object[] getColumns(Edge e,
                           Field[] f,
                           String s)
Description copied from interface: StorageListener
returns the value of Field[] f in for Edge n

Specified by:
getColumns in interface StorageListener
Parameters:
f - the field
s - the state to retrieve from

getColumns

public Object[] getColumns(Node n,
                           Field[] f,
                           String s)
Description copied from interface: StorageListener
returns the value of Field[] f in for Node n

Specified by:
getColumns in interface StorageListener
Parameters:
n - the node you want the result for
f - the field
s - the state to retrieve from

getColumns

public Object[] getColumns(Node n,
                           Field[] f,
                           int s)
Description copied from interface: StorageListener
returns the value of Field[] f in for Node n

Specified by:
getColumns in interface StorageListener
Parameters:
n - the node you want the result for
f - the field
s - the state to retrieve from

getColumns

public Object[] getColumns(Edge e,
                           Field[] f,
                           int s)
Description copied from interface: StorageListener
returns the value of Field[] f in for Edge n

Specified by:
getColumns in interface StorageListener
Parameters:
f - the field
s - the state to retrieve from

getStatement

public PreparedStatement getStatement(String prep)
                               throws SQLException
Throws:
SQLException

closeStatements

public void closeStatements()

fillSchema

public void fillSchema(NodeSchema schema,
                       Graph g)
Description copied from interface: StorageListener
This usually gets called once to add the fields alrady present for nodes that the database knows about. Once this is done new Fields (e.g. columns) should not be added to the underlying datastore without informing the schema.

Specified by:
fillSchema in interface StorageListener
See Also:
com.hp.hpl.Schema#addFieldToSL(Field), #addFieldToSL(Field);

fillSchema

public void fillSchema(EdgeSchema schema,
                       Graph g)
Description copied from interface: StorageListener
This usually gets called once to add the fields alrady present for nodes that the database knows about. Once this is done new Fields (e.g. columns) should not be added to the underlying datastore without informing the schema.

Specified by:
fillSchema in interface StorageListener
See Also:
com.hp.hpl.Schema#addFieldToSL(Field), #addFieldToSL(Field);

updateColumn

public void updateColumn(Node n,
                         Field f,
                         Object value)
Description copied from interface: StorageListener
call this to update the value for field f for Node n.

Specified by:
updateColumn in interface StorageListener
Parameters:
n - the node that is being modified
f - the field that you want changed (e.g. column)
value - the new value

updateColumn

public void updateColumn(Edge n,
                         Field f,
                         Object value)
Description copied from interface: StorageListener
call this to update the value for field f for Edge n.

Specified by:
updateColumn in interface StorageListener
Parameters:
n - the edge that is being modified
f - the field that you want changed (e.g. column)
value - the new value

addField

public void addField(Field f)
Description copied from interface: StorageListener
add a new field to the database

Specified by:
addField in interface StorageListener
Parameters:
f - the field to add

getTypeString

public static String getTypeString(int type)

shutdownConn

public void shutdownConn()
                  throws SQLException
Throws:
SQLException

q

public void q(String expression)
       throws SQLException
Throws:
SQLException

saveCSV

public void saveCSV(String filename,
                    String expression)
             throws Exception
Throws:
Exception

query

public void query(String expression)
           throws SQLException
executes the query specified by expression

Parameters:
expression -
Throws:
SQLException

identity

public int identity()
             throws SQLException
Throws:
SQLException

update

public void update(String expression,
                   Statement st)
            throws SQLException
Throws:
SQLException

update

public void update(String expression)
            throws SQLException
Throws:
SQLException

prettyPrintResult

public String prettyPrintResult(String query)

dump

public static void dump(ResultSet rs)
                 throws SQLException
Throws:
SQLException

getNodeColumn

public void getNodeColumn(Hashtable ht,
                          String column,
                          String limit)
                   throws Exception
Throws:
Exception

findMatchingNodes

public void findMatchingNodes(Query q)
Description copied from interface: StorageListener
find all matching nodes for query q, q will be modified to hold the results

Specified by:
findMatchingNodes in interface StorageListener
Parameters:
q - the query to evaluate

findMatchingEdges

public void findMatchingEdges(Query q)
Description copied from interface: StorageListener
find all matching edges for query q, q will be modified to hold the results

Specified by:
findMatchingEdges in interface StorageListener
Parameters:
q - the query to evaluate

refresh

public void refresh(Graph g)
Description copied from interface: StorageListener
call this to load up all the nodes/edges from the database into the graph.

Specified by:
refresh in interface StorageListener
Parameters:
g - the graph to load the results into

init

public static DBServer init(String dbname)
                     throws Exception
Throws:
Exception

getDBServer

public static DBServer getDBServer()

initInMemory

public static DBServer initInMemory()
                             throws Exception
Throws:
Exception

resetSingleton

public static void resetSingleton()

shutdown

public void shutdown()
Description copied from interface: StorageListener
shutdown operator, once you call this don't assume you can do anything with the StorageListener

Specified by:
shutdown in interface StorageListener

alter

public void alter(String columnname,
                  String query)

fixString

public static String fixString(String init,
                               Hashtable defs)

loadFromFile

public void loadFromFile(String text)
Specified by:
loadFromFile in interface StorageListener

loadFromText

public void loadFromText(String text)
Specified by:
loadFromText in interface StorageListener

createEmpty

public void createEmpty()
Specified by:
createEmpty in interface StorageListener

stringSplit

public static String[] stringSplit(String line)

saveState

public void saveState(int statenum)
Specified by:
saveState in interface StorageListener

saveState

public void saveState(String statenum)
Specified by:
saveState in interface StorageListener

getNodesNotInCurrent

public Vector getNodesNotInCurrent(Graph g,
                                   int statenum)
Specified by:
getNodesNotInCurrent in interface StorageListener

getNodesNotInCurrent

public Vector getNodesNotInCurrent(Graph g,
                                   String statenum)
Specified by:
getNodesNotInCurrent in interface StorageListener

getEdgesNotInCurrent

public Vector getEdgesNotInCurrent(Graph g,
                                   int statenum)
Specified by:
getEdgesNotInCurrent in interface StorageListener

getEdgesNotInCurrent

public Vector getEdgesNotInCurrent(Graph g,
                                   String statenum)
Specified by:
getEdgesNotInCurrent in interface StorageListener

loadState

public void loadState(int state)
Specified by:
loadState in interface StorageListener

loadState

public void loadState(String state)
Specified by:
loadState in interface StorageListener

loadState

public void loadState(Graph g,
                      int statenum)
Specified by:
loadState in interface StorageListener

loadState

public void loadState(Graph g,
                      String statenum)
Specified by:
loadState in interface StorageListener

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

containsEdge

public boolean containsEdge(Edge e)
Specified by:
containsEdge in interface StorageListener

containsEdge

public boolean containsEdge(Edge e,
                            String state)
Specified by:
containsEdge in interface StorageListener

containsNode

public boolean containsNode(Node n)
Specified by:
containsNode in interface StorageListener

containsNode

public boolean containsNode(Node n,
                            String state)
Specified by:
containsNode in interface StorageListener

addEdge

public void addEdge(Edge e)
Specified by:
addEdge in interface StorageListener

createDirectedEdge

public int createDirectedEdge(Node source,
                              Node dest)
Description copied from interface: StorageListener
adds a new edge to the database and return its ID.

Specified by:
createDirectedEdge in interface StorageListener

createDirectedEdge

public int createDirectedEdge(Node source,
                              Node dest,
                              int id)
Description copied from interface: StorageListener
adds a new edge to the database and return its ID. Forces specific __edgeid

Specified by:
createDirectedEdge in interface StorageListener

createUndirectedEdge

public int createUndirectedEdge(Node source,
                                Node dest,
                                int id)
Description copied from interface: StorageListener
adds a new edge to the database and return its ID. Forces specific __edgeid

Specified by:
createUndirectedEdge in interface StorageListener

createUndirectedEdge

public int createUndirectedEdge(Node source,
                                Node dest)
Description copied from interface: StorageListener
adds a new edge to the database and return its ID.

Specified by:
createUndirectedEdge in interface StorageListener

undelete

public void undelete(Edge e)
Specified by:
undelete in interface StorageListener

undelete

public void undelete(Node node)
Specified by:
undelete in interface StorageListener

addNode

public void addNode(Node node)
Specified by:
addNode in interface StorageListener

remove

public void remove(Edge edge)
Specified by:
remove in interface StorageListener

removeComplete

public void removeComplete(Edge edge)
Specified by:
removeComplete in interface StorageListener

removeComplete

public void removeComplete(Node node)
Specified by:
removeComplete in interface StorageListener

remove

public void remove(Node node)
Specified by:
remove in interface StorageListener

getNodeTable

public AbstractTableModel getNodeTable()
Specified by:
getNodeTable in interface StorageListener

getEdgeTable

public AbstractTableModel getEdgeTable()
Specified by:
getEdgeTable in interface StorageListener

exportGDF

public void exportGDF(String filename)
Specified by:
exportGDF in interface StorageListener