Class DBReaderWriter

All Implemented Interfaces:
GraphReaderWriter

public abstract class DBReaderWriter extends AbstractReaderWriter
An implementation of GraphReaderWriter used for reading and writing graph objects to and from a database.

Upon reading, the database is queried using the getQuery() template method, and a representation of the objects to be modelled by the graph are returned through a standard ResultSet. From each tuple in the result set, the object is recreated via the template method readInternal(ResultSet). The object is then passed to an underlying graph generator and the graph components used to model the object are constructed.

Upon writing, the graph is read component by component based on set properties. If the NODES property is set, nodes will be written. If the EDGES property is set, edges will be written as well. As each component is processed, it is passed to the repspective template methods writeNode(Statement,Node) and writeEdge(Statement,Edge). The methods then execute a statement to create the database representation of the graph component.
Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
  • Field Details

  • Constructor Details

    • DBReaderWriter

      public DBReaderWriter()
  • Method Details

    • read

      public Graph read() throws Exception
      Performs a graph read by querying the database and processing each tuple returned in the query. As each tuple is processed, the graph components represented by the tuple are created by an underlying GraphGenerator.
      Returns:
      The represented graph.
      Throws:
      Exception
      See Also:
    • write

      public void write(Graph g) throws Exception
      Performs a write on the graph out to the database. If the NODES property is set, the nodes of the graph will be written, and if the EDGES property is set, the edges of the graph will be written.

      * @see GraphGenerator#write()

      Parameters:
      g - The graph to be
      Throws:
      Exception
    • getConnection

      protected Connection getConnection() throws Exception
      Opens a connection to the database, based on set properties.
      Returns:
      Connection to the database.
      Throws:
      Exception
    • writeNode

      protected void writeNode(Statement st, Node node)
      Template method used to write a node into the database.
      Parameters:
      st - Statement used to execute write statement.
      node - Node to write.
    • writeEdge

      protected void writeEdge(Statement st, Edge edge)
      Template method used to write an edge into the database.
      Parameters:
      st - Statement used to execute write statement.
      edge - Edge to write.
    • getQuery

      protected abstract String getQuery()
      Template method which returns the query to execute in order to read a graph from the database.
      Returns:
      SQL query.
    • readInternal

      protected abstract Object readInternal(ResultSet rs) throws Exception
      Template method used to create the object represented by a tuple returned by the database query.
      Parameters:
      rs - ResultSet of query.
      Returns:
      Object represented by current tuple of result set.
      Throws:
      Exception