org.ilrt.inkling.api
Class SQLGraph

java.lang.Object
  |
  +--org.ilrt.inkling.api.SQLGraph
All Implemented Interfaces:
GraphInterface

public class SQLGraph
extends java.lang.Object
implements GraphInterface

Copyright University of Bristol, 2003

This software is released under the W3C license:
http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231

A Graph for SQL Databases.
To add data to an SQLGraph, create a Graph and then add() to SQLGraph.
Use setdb() and setDriver() to specify the database.
See test/SQLGraphTest.java for usage.


String
db="jdbc:mysql://127.0.0.1:3306/codepict3?user=mysql";

int count=0;

SQLGraph sq = new SQLGraph();
sq.setdb(db);
sq.setDriver("com.mysql.jdbc.Driver");
Graph gr = new Graph(null, uri, Util.RDFXML);
gr.load();
sq.add(gr);

java.sql.ResultSet r=sq.askSquish(query);


Constructor Summary
SQLGraph()
           
 
Method Summary
 void add(Graph g)
          Loads in a Graph, removing existing data from that Graph first.
 java.util.Vector ask(java.lang.Object ss, java.lang.Object pp, java.lang.Object oo)
          Ask a simple query of the database (via a generated squish query)
 Graph ask(Query query)
          Ask a simple query of the database (via a generated squish query)
 java.sql.ResultSet askSquish(java.lang.String query)
          Ask a squish query of this database, returning a ResultSet.
 java.sql.ResultSet askSquish(java.lang.String query, boolean prov)
          Ask a squish query of this database, returning a ResultSet.
 boolean delete(Statement statement)
          Delete a triple or triples from the database.
 java.sql.ResultSet doSQLQuery(java.lang.String sql_query, boolean prov)
          Performs an SQL query, converting the result to a org.ilrt.inkling.query.ResultSet, so that provenance and literal, bnode etc can be identified through the extended API.
 java.sql.ResultSet doSQLQueryClean(java.lang.String sql_query)
          Performs a simple SQL query.
 java.lang.String getBase()
          The base url for an SQLGraph is the database url, e.g.
 java.lang.String getdb()
          Return the database url
 java.lang.String getDriver()
          Return the database driver
 java.util.Hashtable getGraphs()
          Get a list of all the Graphs in the database
 int getSize()
          Get the size of the database
 int getSize(java.lang.String id)
           
 java.util.Vector getStatements()
          get all the Statements in the SQLGraph
static void main(java.lang.String[] args)
           
 void makeJDBCCommand(java.lang.String command)
          Makes a command to a jdbc db - i.e.
 void remove(java.lang.String base)
           
 boolean removeAll()
          Remove all the triples from the entire SQL database.
 void setBase(java.lang.String base)
          the base url for an SQLGraph is the database url, e.g.
 void setdb(java.lang.String dburi)
          Set the database uri, for example setdb("jdbc:postgresql://localhost:5432/test?auth=password&user=postgres&password=notneeded")
 void setDriver(java.lang.String driver)
          set the database driver, e.g.
 int size()
          Get the size of the database
 void tell(Statement statement)
          Insert a statement into the database, using the ID of the database as the source id.
 void tell(Statement statement, java.lang.String id)
          Insert a statement into the database.
 void tellAll(java.util.Vector states)
          Tell all the Statements in a Vector to the SQLGraph.
 void tellAll(java.util.Vector states, java.lang.String graphid)
          Tell all the Statements in a Vector to the SQLGraph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLGraph

public SQLGraph()
Method Detail

main

public static void main(java.lang.String[] args)

setdb

public void setdb(java.lang.String dburi)
Set the database uri, for example setdb("jdbc:postgresql://localhost:5432/test?auth=password&user=postgres&password=notneeded")

setDriver

public void setDriver(java.lang.String driver)
set the database driver, e.g. setDriver("org.postgresql.Driver")

getdb

public java.lang.String getdb()
Return the database url

getDriver

public java.lang.String getDriver()
Return the database driver

add

public void add(Graph g)
Loads in a Graph, removing existing data from that Graph first. Graph should be previously populated using load()

remove

public void remove(java.lang.String base)

tellAll

public void tellAll(java.util.Vector states)
Tell all the Statements in a Vector to the SQLGraph. It's better to create a Graph object and use add() than using this method.
Specified by:
tellAll in interface GraphInterface

tellAll

public void tellAll(java.util.Vector states,
                    java.lang.String graphid)
Tell all the Statements in a Vector to the SQLGraph. It's better to create a Graph object and use add() than using this method.

tell

public void tell(Statement statement)
Insert a statement into the database, using the ID of the database as the source id.
Specified by:
tell in interface GraphInterface

tell

public void tell(Statement statement,
                 java.lang.String id)
Insert a statement into the database. id is usually the data source or url. Note that literals are stored with a " in front of them. This is to speed identification of literals. blank nodes start with _: As a hardcoded feature, all foaf:mboxes are converted to foaf:mbox_sha1sum as an extra triple.

makeJDBCCommand

public void makeJDBCCommand(java.lang.String command)
                     throws java.sql.SQLException
Makes a command to a jdbc db - i.e. inserts, deletes

doSQLQuery

public java.sql.ResultSet doSQLQuery(java.lang.String sql_query,
                                     boolean prov)
Performs an SQL query, converting the result to a org.ilrt.inkling.query.ResultSet, so that provenance and literal, bnode etc can be identified through the extended API. In this case it also sets whether SQL database returns provenance or not. If true, may be slower, and contain duplicates, so defaults to false.

doSQLQueryClean

public java.sql.ResultSet doSQLQueryClean(java.lang.String sql_query)
Performs a simple SQL query. Use this for straightfoward SQL queries. Use doSQLQuery to squish queries only.

askSquish

public java.sql.ResultSet askSquish(java.lang.String query)
Ask a squish query of this database, returning a ResultSet.
Specified by:
askSquish in interface GraphInterface

askSquish

public java.sql.ResultSet askSquish(java.lang.String query,
                                    boolean prov)
Ask a squish query of this database, returning a ResultSet. Prov is whether you want the SQL database to return provenace information or not. If so, this makes it slower and causes duplicates, so defaults to false.

ask

public java.util.Vector ask(java.lang.Object ss,
                            java.lang.Object pp,
                            java.lang.Object oo)
Ask a simple query of the database (via a generated squish query)
Specified by:
ask in interface GraphInterface

ask

public Graph ask(Query query)
Ask a simple query of the database (via a generated squish query)
Specified by:
ask in interface GraphInterface

getSize

public int getSize(java.lang.String id)

getSize

public int getSize()
Get the size of the database

size

public int size()
Get the size of the database

getGraphs

public java.util.Hashtable getGraphs()
Get a list of all the Graphs in the database

getStatements

public java.util.Vector getStatements()
get all the Statements in the SQLGraph
Specified by:
getStatements in interface GraphInterface

getBase

public java.lang.String getBase()
The base url for an SQLGraph is the database url, e.g. jdbc:postgresql://localhost:5432/test?auth=password&user=postgres&password=notneeded
Specified by:
getBase in interface GraphInterface

setBase

public void setBase(java.lang.String base)
the base url for an SQLGraph is the database url, e.g. jdbc:postgresql://localhost:5432/test?auth=password&user=postgres&password=notneeded
Specified by:
setBase in interface GraphInterface

delete

public boolean delete(Statement statement)
Delete a triple or triples from the database. Be warned that this operation will delete every occurrance of the triples from the database.
Specified by:
delete in interface GraphInterface

removeAll

public boolean removeAll()
Remove all the triples from the entire SQL database. Use with care. Use public void remove(String base) to remove only those triples form a particular base url.
Specified by:
removeAll in interface GraphInterface