com.hp.hpl.mesa.rdf.jena.rdb
Class DriverGenericGeneric

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.rdb.DriverGenericGeneric
All Implemented Interfaces:
IRDBDriver
Direct Known Subclasses:
DriverGenericAttribute, DriverGenericGenericProc, DriverGenericHash, DriverGenericMMGeneric, DriverGenericProc

public class DriverGenericGeneric
extends java.lang.Object
implements IRDBDriver

Base database driver for implementing ModelRDB and StoreRDB. Different drivers are needed for different databases and different layout schemes.

This driver is a base implemention from which database-specific drivers can inherit. It is not generic in the sense that it will work on any minimal SQL store and so should be treated as if it were an abstract class.

The SQL statements which implement each of the functions are loaded in a separate file etc/[layout]_[database].sql from the classpath. See SQLCache documentation for more information on the format of this file.

Version:
$Revision: 1.5 $ on $Date: 2002/03/01 14:25:13 $
Author:
Dave Reynolds

Field Summary
static java.lang.String ANON_NAMESPACE
          Namesapce used to flag anonymous resources
 
Constructor Summary
DriverGenericGeneric()
          Create a bare instance of the driver.
 
Method Summary
 void addStatement(Statement s, ModelRDB m)
          Register a statement in the database.
 IDBID allocateModelID(java.lang.String modelName)
          Allocate a new databaseID for a new model in the same database.
 void attachStore(StoreRDB store)
          Register a store as a user of this driver.
 void cleanDB()
          Remove all RDF information from a database.
 void close()
          Close the databse connection
 IConstraints createConstraints(ModelRDB model)
          Create a constraint object appropriate for this type of database layout
 void deleteStatement(Resource subject, Property predicate, RDFNode object, ModelRDB m)
          Delete the statements in the model which match the given subject, predicate object.
 void detachStore(StoreRDB store)
          Notify that a store is no longer using this driver.
 void formatDB()
          Initialise a database ready to store RDF tables.
 java.sql.Connection getConnection()
          Return the jdbc connection to the database, opening it if necessary
 Literal getLiteral(IDBID id)
          Fetch a literal just knowing its literal rdb-id.
 IDBID getLiteralID(Literal l)
          Return the database ID for the literal, if it exists
 IDBID getModelID(java.lang.String modelName)
          Return the databaseID for an existing named model within the database.
 java.lang.String getNamespace(IDBID nsid)
          Return the namespace string corresponding to a given namespace id.
 Property getProperty(IDBID id, ModelRDB m)
          Fetch a property just knowing its resource rdb-id.
 Property getProperty(java.lang.String uri, ModelRDB m)
          Fetch a property, knowing its uri.
 Resource getResource(IDBID id, ModelRDB m)
          Fetch a resource just knowing its resource rdb-id.
 Resource getResource(java.lang.String uri, ModelRDB m)
          Fetch a resource, knowing its uri.
 IDBID getResourceID(Resource resource)
          Lookup the unique ID for a resource.
 SQLCache getSQLCache()
          Return the SQLCache used for database commands.
 void hintPropertyTable(Property p)
          Hint to the store that the given property could be stored as an attribute table.
 boolean isDBFormatOK()
          Check that the database has a legal set of RDF tables.
 boolean isStatementPresent(Resource subject, Property predicate, RDFNode object, ModelRDB m)
          Check if a statement is in the database.
 java.util.Iterator listModels()
          List the names of all models in this database
 ResultSetIterator listNamespaces(ModelRDB m)
          List all namespaces referenced in the model
 ResultSetIterator listStatements(IConstraints constraints, ModelRDB m)
          List all the statements in the given moddel which make the given set of constraints (a constraint set can be obtained using createConstraints(com.hp.hpl.mesa.rdf.jena.rdb.ModelRDB)).
 ResultSetIterator listStatements(Resource subject, Property predicate, RDFNode object, ModelRDB m)
          List all the statements in the model which match the given subject, predicate object - each of which can be null (meaning wildcard).
 ResultSetIterator listSubjects(ModelRDB m)
          List all the subject resources in the model
 void loadDatabaseDriver()
          Force a load of the jdbc driver.
 void loadProperties(java.util.Properties props)
          Load a set of configuration parameters into the driver.
 Resource makeResource(IDBID id, java.lang.String localname, IDBID nsid, ModelRDB m)
          Re-create a resource from its local name and namespace identifier
 void saveProperties()
          Store the configuration parameters onto the database layout table in the attached database
 void setConnection(IDBConnection dbcon)
          Link an existing instance of the driver to a specific jdbc connection
 boolean supportsMultipleModels()
          Returns true of the database layout supports multiple RDF models in the same database.
 java.lang.String toString()
          Printable name for the driver configuration
 IDBID wrapDBID(java.lang.Object id)
          Convert the raw SQL object used to store a database identifier into a java object which meets the IDBID interface
 java.lang.Object wrapFlag(boolean flag)
          Wrap up a boolean flag as a object which the jdbc driver can assert into a boolean/short column
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANON_NAMESPACE

public static final java.lang.String ANON_NAMESPACE
Namesapce used to flag anonymous resources
Constructor Detail

DriverGenericGeneric

public DriverGenericGeneric()
Create a bare instance of the driver. It is not functional until a database connection has been supplied via setConnection.
Method Detail

setConnection

public void setConnection(IDBConnection dbcon)
                   throws RDFRDBException
Link an existing instance of the driver to a specific jdbc connection
Specified by:
setConnection in interface IRDBDriver

close

public void close()
           throws RDFRDBException
Close the databse connection
Specified by:
close in interface IRDBDriver
Throws:
RDFRDBException - if there is an access problem

getConnection

public java.sql.Connection getConnection()
                                  throws RDFRDBException
Return the jdbc connection to the database, opening it if necessary
Specified by:
getConnection in interface IRDBDriver

getSQLCache

public SQLCache getSQLCache()
Return the SQLCache used for database commands.
Specified by:
getSQLCache in interface IRDBDriver

isDBFormatOK

public boolean isDBFormatOK()
                     throws RDFRDBException
Check that the database has a legal set of RDF tables. This is not a full validation check simply a test for the existence of some key tables as evidence of at least attempted formatting.
Specified by:
isDBFormatOK in interface IRDBDriver
Returns:
true if the database seems to be legally formated.
Throws:
RDFRDBException - typtically due to internal programming errors, might trap and change to logging operations in the future.

formatDB

public void formatDB()
              throws RDFRDBException
Initialise a database ready to store RDF tables. This version uses a simple generic representation based a statement table and a resource table, equivalent to the edge-based method of XML storage.
Specified by:
formatDB in interface IRDBDriver
Throws:
RDFRDBException - typtically due to internal programming errors, might trap and change to logging operations in the future.

cleanDB

public void cleanDB()
Remove all RDF information from a database. This will only work if there are no other clients us the DB so is mostly to simplify testing that a practical tool. Partial DB config or cleaning can leave the DB in a strange state hence it will continue with each cleanup phase even if earlier phases have generated errors and erros are only logged, not propagated as exceptions.
Specified by:
cleanDB in interface IRDBDriver

loadProperties

public void loadProperties(java.util.Properties props)
Load a set of configuration parameters into the driver.
Specified by:
loadProperties in interface IRDBDriver

saveProperties

public void saveProperties()
                    throws java.sql.SQLException
Store the configuration parameters onto the database layout table in the attached database

toString

public java.lang.String toString()
Printable name for the driver configuration
Overrides:
toString in class java.lang.Object

attachStore

public void attachStore(StoreRDB store)
Register a store as a user of this driver. One driver can support multiple store instances.
Specified by:
attachStore in interface IRDBDriver

detachStore

public void detachStore(StoreRDB store)
Notify that a store is no longer using this driver.
Specified by:
detachStore in interface IRDBDriver

addStatement

public void addStatement(Statement s,
                         ModelRDB m)
                  throws RDFException
Register a statement in the database.
Specified by:
addStatement in interface IRDBDriver
Parameters:
subjId - database index of the subject entry
predId - database index of the predicate entry
objId - database index of the object entry
isLiteral - if the object is a literal rather than a resource

listSubjects

public ResultSetIterator listSubjects(ModelRDB m)
                               throws RDFRDBException
List all the subject resources in the model
Specified by:
listSubjects in interface IRDBDriver
Parameters:
m - the model whose subjects are to be listed
Returns:
iterator over Resource objects

listNamespaces

public ResultSetIterator listNamespaces(ModelRDB m)
                                 throws RDFRDBException
List all namespaces referenced in the model
Specified by:
listNamespaces in interface IRDBDriver
Returns:
iterator over Strings

listStatements

public ResultSetIterator listStatements(Resource subject,
                                        Property predicate,
                                        RDFNode object,
                                        ModelRDB m)
                                 throws RDFException
List all the statements in the model which match the given subject, predicate object - each of which can be null (meaning wildcard).
Specified by:
listStatements in interface IRDBDriver

isStatementPresent

public boolean isStatementPresent(Resource subject,
                                  Property predicate,
                                  RDFNode object,
                                  ModelRDB m)
                           throws RDFException
Check if a statement is in the database.
Specified by:
isStatementPresent in interface IRDBDriver

listStatements

public ResultSetIterator listStatements(IConstraints constraints,
                                        ModelRDB m)
                                 throws RDFException
List all the statements in the given moddel which make the given set of constraints (a constraint set can be obtained using createConstraints(com.hp.hpl.mesa.rdf.jena.rdb.ModelRDB)).
Specified by:
listStatements in interface IRDBDriver

createConstraints

public IConstraints createConstraints(ModelRDB model)
Create a constraint object appropriate for this type of database layout
Specified by:
createConstraints in interface IRDBDriver

deleteStatement

public void deleteStatement(Resource subject,
                            Property predicate,
                            RDFNode object,
                            ModelRDB m)
                     throws RDFException
Delete the statements in the model which match the given subject, predicate object.
Specified by:
deleteStatement in interface IRDBDriver

getResource

public Resource getResource(java.lang.String uri,
                            ModelRDB m)
                     throws RDFException
Fetch a resource, knowing its uri.
Specified by:
getResource in interface IRDBDriver

getProperty

public Property getProperty(java.lang.String uri,
                            ModelRDB m)
                     throws RDFException
Fetch a property, knowing its uri.
Specified by:
getProperty in interface IRDBDriver

supportsMultipleModels

public boolean supportsMultipleModels()
Returns true of the database layout supports multiple RDF models in the same database.
Specified by:
supportsMultipleModels in interface IRDBDriver

allocateModelID

public IDBID allocateModelID(java.lang.String modelName)
                      throws RDFRDBException
Allocate a new databaseID for a new model in the same database.
Specified by:
allocateModelID in interface IRDBDriver

getModelID

public IDBID getModelID(java.lang.String modelName)
                 throws RDFRDBException
Return the databaseID for an existing named model within the database. Throws RDFRDBException if the driver does not support multiple models per db.
Specified by:
getModelID in interface IRDBDriver

listModels

public java.util.Iterator listModels()
                              throws RDFRDBException
List the names of all models in this database
Specified by:
listModels in interface IRDBDriver

getNamespace

public java.lang.String getNamespace(IDBID nsid)
                              throws RDFRDBException
Return the namespace string corresponding to a given namespace id. Can be null if the ID can from a hash function and namespace isn't registered yet.
Specified by:
getNamespace in interface IRDBDriver

getLiteral

public Literal getLiteral(IDBID id)
                   throws RDFException
Fetch a literal just knowing its literal rdb-id. Can be null if the ID can from a hash function and literal isn't registered yet.
Specified by:
getLiteral in interface IRDBDriver

getLiteralID

public IDBID getLiteralID(Literal l)
                   throws RDFRDBException
Return the database ID for the literal, if it exists
Specified by:
getLiteralID in interface IRDBDriver

getResourceID

public IDBID getResourceID(Resource resource)
                    throws RDFException
Lookup the unique ID for a resource. Return null if it does not have one yet.
Specified by:
getResourceID in interface IRDBDriver

getResource

public Resource getResource(IDBID id,
                            ModelRDB m)
                     throws RDFException
Fetch a resource just knowing its resource rdb-id. Can be null if the ID can from a hash function and resource isn't registered yet.
Specified by:
getResource in interface IRDBDriver

getProperty

public Property getProperty(IDBID id,
                            ModelRDB m)
                     throws RDFException
Fetch a property just knowing its resource rdb-id. Can be null if the ID can from a hash function and resource isn't registered yet.
Specified by:
getProperty in interface IRDBDriver

wrapDBID

public IDBID wrapDBID(java.lang.Object id)
               throws RDFRDBException
Convert the raw SQL object used to store a database identifier into a java object which meets the IDBID interface
Specified by:
wrapDBID in interface IRDBDriver

wrapFlag

public java.lang.Object wrapFlag(boolean flag)
Wrap up a boolean flag as a object which the jdbc driver can assert into a boolean/short column

makeResource

public Resource makeResource(IDBID id,
                             java.lang.String localname,
                             IDBID nsid,
                             ModelRDB m)
                      throws RDFException
Re-create a resource from its local name and namespace identifier
Specified by:
makeResource in interface IRDBDriver

loadDatabaseDriver

public void loadDatabaseDriver()
                        throws RDFRDBException
Force a load of the jdbc driver.
Throws:
RDFRDBException - if the driver fails to load

hintPropertyTable

public void hintPropertyTable(Property p)
                       throws RDFException
Hint to the store that the given property could be stored as an attribute table.
Specified by:
hintPropertyTable in interface IRDBDriver


Copyright 2001 Hewlett-Packard. All Rights Reserved.