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

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.rdb.DBConnection
All Implemented Interfaces:
IDBConnection

public class DBConnection
extends java.lang.Object
implements IDBConnection

Encapsulate the specification of a jdbc connection, mostly used to simplify the calling pattern for ModelRDB factory methods.

Version:
$Revision: 1.2 $ on $Date: 2001/11/26 18:20:08 $
Author:
Dave Reynolds

Fields inherited from interface com.hp.hpl.mesa.rdf.jena.rdb.IDBConnection
DATABASE_TYPE, DRIVER_CLASSNAME, LAYOUT_TYPE
 
Constructor Summary
DBConnection(java.sql.Connection connection)
          Create a connection specification that just wraps up an existing database connection.
DBConnection(java.lang.String url, java.lang.String user, java.lang.String password)
          Create a connection specification based on jdbc address and appropriate authentication information.
 
Method Summary
 void addProperty(java.lang.String propname, java.lang.String value)
          Add a new property value to both RDF_LAYOUT_INFO table.
 void close()
          Close the jdbc connection.
 java.sql.Connection getConnection()
          Return the jdbc connection or null if we no longer have access to a connection.
 IRDBDriver getDriver()
          Return an IRDBDriver suitable for this database connection.
 IRDBDriver getDriver(java.lang.String layout, java.lang.String database)
          Helper function to locate and instantiate the driver class corresponding to a given layout and database name Throws an RDFRDBexception if the driver can't be instantiated
 java.util.Properties getProperties()
          Returns a set of property values for the database at the end of the connection.
 java.lang.String getProperty(java.lang.String propname)
          Returns a property value for the database at the end of the connection.
 boolean isFormatOK()
          Return true if the database seems to be formated for RDF storage.
 void setDriver(IRDBDriver driver)
          Set the IRDBDriver to use for this connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBConnection

public DBConnection(java.lang.String url,
                    java.lang.String user,
                    java.lang.String password)
Create a connection specification based on jdbc address and appropriate authentication information.
Parameters:
url - the jdbc url for the database, note that the format of this is database dependent and that the appropriate jdbc driver will need to be specified either in the jdbc.drivers property or via the standard pattern
     Class.forName("my.sql.driver");
 
user - the user name to log on with
password - the password corresponding to this user

DBConnection

public DBConnection(java.sql.Connection connection)
Create a connection specification that just wraps up an existing database connection.
Parameters:
connection - the open jdbc connection to use
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Return the jdbc connection or null if we no longer have access to a connection.
Specified by:
getConnection in interface IDBConnection

close

public void close()
           throws java.sql.SQLException
Close the jdbc connection. It might be reopend with a getConnection() if the full database uri, user and password were provided.
Specified by:
close in interface IDBConnection

isFormatOK

public boolean isFormatOK()
                   throws RDFRDBException
Return true if the database seems to be formated for RDF storage. This is not an integrity check this is simply a flag recording that a base level table exists. Any access errors are treated as the database not being formated.
Specified by:
isFormatOK in interface IDBConnection

getProperty

public java.lang.String getProperty(java.lang.String propname)
                             throws java.sql.SQLException
Returns a property value for the database at the end of the connection. This is used to retrieve appropriate formating and driver information from a standard RDF_LAYOUT_INFO table. For a database that has not been formatted all calls will return null. Any access errors are treated as the database not being formated.
Specified by:
getProperty in interface IDBConnection

getProperties

public java.util.Properties getProperties()
                                   throws java.sql.SQLException
Returns a set of property values for the database at the end of the connection. This is used to retrieve appropriate formating and driver information from a standard RDF_LAYOUT_INFO table. For a database that has not been formatted all calls will return null. Any access errors are treated as the database not being formated.
Specified by:
getProperties in interface IDBConnection

getDriver

public IRDBDriver getDriver()
                     throws RDFRDBException
Return an IRDBDriver suitable for this database connection. This is only usable for a preformatted database, returns null if the database has not been formatted or is corrupt or the driver is not loadable. Throws and Exception if can't even connect to the database.
Specified by:
getDriver in interface IDBConnection

setDriver

public void setDriver(IRDBDriver driver)
Set the IRDBDriver to use for this connection. Useful to enable external drivers to be registered outside of the standard driver package.
Specified by:
setDriver in interface IDBConnection

getDriver

public IRDBDriver getDriver(java.lang.String layout,
                            java.lang.String database)
                     throws RDFRDBException
Helper function to locate and instantiate the driver class corresponding to a given layout and database name Throws an RDFRDBexception if the driver can't be instantiated
Specified by:
getDriver in interface IDBConnection

addProperty

public void addProperty(java.lang.String propname,
                        java.lang.String value)
                 throws java.sql.SQLException
Add a new property value to both RDF_LAYOUT_INFO table. Only works if the database has already been formated.
Specified by:
addProperty in interface IDBConnection


Copyright © 2001 Hewlett-Packard. All Rights Reserved.