org.geotools.graph.io.standard
Class DBReaderWriter

java.lang.Object
  extended byorg.geotools.graph.io.standard.AbstractReaderWriter
      extended byorg.geotools.graph.io.standard.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 Summary
static java.lang.String DBNAME
          Database name key
static java.lang.String DRIVERCLASS
          JDBC driver class name key
static java.lang.String DRIVERURL
          JDBC driver url
static java.lang.String PORT
          Database port key
static java.lang.String SERVER
          Database server key
static java.lang.String TABLENAME
          Table key
static java.lang.String USERNAME
          User name key
 
Fields inherited from class org.geotools.graph.io.standard.AbstractReaderWriter
BUILDER, EDGES, GENERATOR, NODES
 
Constructor Summary
DBReaderWriter()
           
 
Method Summary
protected  java.sql.Connection getConnection()
          Opens a connection to the database, based on set properties.
protected abstract  java.lang.String getQuery()
          Template method which returns the query to execute in order to read a graph from the database.
 Graph read()
          Performs a graph read by querying the database and processing each tuple returned in the query.
protected abstract  java.lang.Object readInternal(java.sql.ResultSet rs)
          Template method used to create the object represented by a tuple returned by the database query.
 void write(Graph g)
          Performs a write on the graph out to the database.
protected  void writeEdge(java.sql.Statement st, Edge edge)
          Template method used to write an edge into the database.
protected  void writeNode(java.sql.Statement st, Node node)
          Template method used to write a node into the database.
 
Methods inherited from class org.geotools.graph.io.standard.AbstractReaderWriter
getProperty, setProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRIVERCLASS

public static final java.lang.String DRIVERCLASS
JDBC driver class name key

See Also:
Constant Field Values

DRIVERURL

public static final java.lang.String DRIVERURL
JDBC driver url

See Also:
Constant Field Values

SERVER

public static final java.lang.String SERVER
Database server key

See Also:
Constant Field Values

PORT

public static final java.lang.String PORT
Database port key

See Also:
Constant Field Values

DBNAME

public static final java.lang.String DBNAME
Database name key

See Also:
Constant Field Values

USERNAME

public static final java.lang.String USERNAME
User name key

See Also:
Constant Field Values

TABLENAME

public static final java.lang.String TABLENAME
Table key

See Also:
Constant Field Values
Constructor Detail

DBReaderWriter

public DBReaderWriter()
Method Detail

read

public Graph read()
           throws java.lang.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:
java.lang.Exception
See Also:
GraphReaderWriter.read()

write

public void write(Graph g)
           throws java.lang.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:
java.lang.Exception

getConnection

protected java.sql.Connection getConnection()
                                     throws java.lang.Exception
Opens a connection to the database, based on set properties.

Returns:
Connection to the database.
Throws:
java.lang.Exception

writeNode

protected void writeNode(java.sql.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(java.sql.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 java.lang.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 java.lang.Object readInternal(java.sql.ResultSet rs)
                                          throws java.lang.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:
java.lang.Exception


Copyright © GeoTools. All Rights Reserved.