Package org.geotools.graph.io.standard
Class DBReaderWriter
- Object
-
- AbstractReaderWriter
-
- 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
Fields Modifier and Type Field Description static String
DBNAME
Database name key *static String
DRIVERCLASS
JDBC driver class name key *static String
DRIVERURL
JDBC driver url *static String
PORT
Database port key *static String
SERVER
Database server key *static String
TABLENAME
Table key *static String
USERNAME
User name key *-
Fields inherited from class AbstractReaderWriter
BUILDER, EDGES, GENERATOR, NODES
-
-
Constructor Summary
Constructors Constructor Description DBReaderWriter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Connection
getConnection()
Opens a connection to the database, based on set properties.protected abstract 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 Object
readInternal(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(Statement st, Edge edge)
Template method used to write an edge into the database.protected void
writeNode(Statement st, Node node)
Template method used to write a node into the database.-
Methods inherited from class AbstractReaderWriter
getProperty, setProperty, setProperty
-
-
-
-
Field Detail
-
DRIVERCLASS
public static final String DRIVERCLASS
JDBC driver class name key *- See Also:
- Constant Field Values
-
DRIVERURL
public static final String DRIVERURL
JDBC driver url *- See Also:
- Constant Field Values
-
SERVER
public static final String SERVER
Database server key *- See Also:
- Constant Field Values
-
PORT
public static final String PORT
Database port key *- See Also:
- Constant Field Values
-
DBNAME
public static final String DBNAME
Database name key *- See Also:
- Constant Field Values
-
USERNAME
public static final String USERNAME
User name key *- See Also:
- Constant Field Values
-
TABLENAME
public static final String TABLENAME
Table key *- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
GraphReaderWriter.read()
-
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.
-
-