OpMath

com.opmath.util.db
Class DBObject

java.lang.Object
  |
  +--com.opmath.util.db.DBObject
All Implemented Interfaces:
DB
Direct Known Subclasses:
DBRemoteObject

public abstract class DBObject
extends Object
implements DB

The superclass for implementations of the com.opmath.util.db.DB interface.

This class implements instance variables and methods that are likely to be common to all implementations of the com.opmath.util.db.DB interface.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3.0
Version:
DB v1.0
Author:
Bruno Beloff bruno.beloff@opmath.com

Field Summary
protected  Connection conn
          The connection object for this DB.
protected  String path
          The absolute path for this DB.
protected  String protocol
          The name of the protocol for this DB.
 
Constructor Summary
DBObject()
           
 
Method Summary
 String className()
          Returns the name of the class of this DBObject object.
 void create(String table, String values)
          Creates a new row in the named table.
 void createTable(String name, String sqlColumns)
          Create a new table within this database.
 void delete(String table, String keyName, long keyValue)
          Deletes the row (or rows) with the specfied key name and value, in the named table.
 void delete(String table, String keyName, String keyValue)
          Deletes the row (or rows) with the specfied key name and value, in the named table.
 void dropTable(String name)
          Delete a table within this database.
 Connection getConnection()
          Returns the connection object for this DB instance.
 String getPath()
          Returns the fully qualified path for the current connection.
 String getProtocol()
          Returns the protocol for the current connection.
 boolean isAvailable()
          Tests whether the database is responding.
 String maxIndex(String table, String pkName)
          Returns the highest value of the primary key for the named table.
static DB newDbConnection(String className, String path)
          A factory method for implementations of the DB interface.
 ResultSet query(String table, String where, String order)
          Returns the rows from the named table, as found by the ad hoc query given in where.
 ResultSet read(String table, String keyName, long keyValue)
          Returns the rows from the named table whose field keyName exactly matches keyValue.
 ResultSet read(String table, String keyName, String keyValue)
          Returns the rows from the named table whose field keyName exactly matches keyValue.
 ResultSet readAll(String table, String order)
          Returns all of the rows from the named table.
 void update(String table, String pkName, long pkValue, String set)
          Updates the row with the specfied primary key name and value, in the named table.
 void update(String table, String pkName, String pkValue, String set)
          Updates the row with the specfied primary key name and value, in the named table.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.opmath.util.db.DB
close, connect, getDriver
 

Field Detail

conn

protected Connection conn

The connection object for this DB.

Since:
J2SE 1.3

protocol

protected String protocol

The name of the protocol for this DB.

Since:
J2SE 1.3

path

protected String path

The absolute path for this DB.

Since:
J2SE 1.3
Constructor Detail

DBObject

public DBObject()
Method Detail

newDbConnection

public static DB newDbConnection(String className,
                                 String path)
                          throws ClassNotFoundException

A factory method for implementations of the DB interface.

NOTE: This method can only construct DB objects where a constructor of the form <ClassName>(String path) is available.

Parameters:
className - a String the name of the class implementing DB.
path - a String specifying the absolute path, including the database file or directory.
Returns:
A new object implementing DB.
Throws:
ClassNotFoundException - if it was not possible to construct the specified object.
Since:
J2SE 1.3

isAvailable

public boolean isAvailable()

Tests whether the database is responding.

NOTE: The test performed here is conn.getMetaData().supportsTransactions() - roughly the minimum possible compliance of a JDBC source.

Specified by:
isAvailable in interface DB
Returns:
A boolean indicating database availability.
Since:
J2SE 1.3

getProtocol

public String getProtocol()

Returns the protocol for the current connection. Returns null if there is no current connection.

Specified by:
getProtocol in interface DB
Returns:
A Class representing the database driver.
Since:
J2SE 1.3

getPath

public String getPath()

Returns the fully qualified path for the current connection. Returns null if there is no current connection.

Specified by:
getPath in interface DB
Returns:
A Class representing the database driver.
Since:
J2SE 1.3

getConnection

public Connection getConnection()
                         throws SQLException

Returns the connection object for this DB instance.

Specified by:
getConnection in interface DB
Returns:
A Connection object.
Since:
J2SE 1.3

className

public String className()

Returns the name of the class of this DBObject object.

Specified by:
className in interface DB
Returns:
A String naming the class.
Since:
J2SE 1.3

createTable

public void createTable(String name,
                        String sqlColumns)
                 throws SQLException

Create a new table within this database.

Specified by:
createTable in interface DB
Parameters:
name - a String the name of the new table.
sqlColumns - a String carrying the SQL-92 code, specifying the table's column names and SQL-92 types.
Throws:
SQLException - if the table could not be created.
Since:
J2SE 1.3

dropTable

public void dropTable(String name)
               throws SQLException

Delete a table within this database.

Specified by:
dropTable in interface DB
Parameters:
name - a String the name of the new table.
Throws:
SQLException - if the table could not be deleted.
Since:
J2SE 1.3

maxIndex

public String maxIndex(String table,
                       String pkName)
                throws SQLException

Returns the highest value of the primary key for the named table. The value is returned as a String, irrespective of its actual stored type. If the table has no rows, this method returns null.

Specified by:
maxIndex in interface DB
Parameters:
table - a String naming the table.
pkName - a String specifying the name of the primary key field.
Throws:
SQLException - if the operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

create

public void create(String table,
                   String values)
            throws SQLException

Creates a new row in the named table.

The String values is used within the VALUES(..) SQL sub-clause of the INSERT statement, and is a comma-separated list of values that must be appropriate to the table definition.

Specified by:
create in interface DB
Parameters:
table - a String the name of the table.
values - a String the field values for the new row.
Throws:
SQLException - if the create operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

read

public ResultSet read(String table,
                      String keyName,
                      long keyValue)
               throws SQLException

Returns the rows from the named table whose field keyName exactly matches keyValue. All columns are returned.

Specified by:
read in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the key field.
keyValue - a long specifying the value of the key field.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the read operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

read

public ResultSet read(String table,
                      String keyName,
                      String keyValue)
               throws SQLException

Returns the rows from the named table whose field keyName exactly matches keyValue. All columns are returned.

Specified by:
read in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the key field.
keyValue - a String specifying the value of the key field.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the read operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

readAll

public ResultSet readAll(String table,
                         String order)
                  throws SQLException

Returns all of the rows from the named table. All columns are returned.

The String order is a comma-seperated list of field names (most significant field first), each with sort direction.

Specified by:
readAll in interface DB
Parameters:
table - a String naming the table.
order - a String specifying the sort field order.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the read operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

query

public ResultSet query(String table,
                       String where,
                       String order)
                throws SQLException

Returns the rows from the named table, as found by the ad hoc query given in where. The String where is used within the WHERE SQL sub-clause of the SELECT statement, each with sort direction.

The String order is a comma-seperated list of field names (most significant field first). The sort direction is ascending only.

Specified by:
query in interface DB
Parameters:
table - a String naming the table.
where - a String specifying the sort field order.
order - a String specifying the sort field order.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the query operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

update

public void update(String table,
                   String pkName,
                   long pkValue,
                   String set)
            throws SQLException

Updates the row with the specfied primary key name and value, in the named table. The String where is used within the SET SQL sub-clause of the UPDATE statement.

Specified by:
update in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the primary key field.
keyValue - a long specifying the value of the primary key field.
set - a String specifying the name-value pairs for the updated fields.
Throws:
SQLException - if the update operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

update

public void update(String table,
                   String pkName,
                   String pkValue,
                   String set)
            throws SQLException

Updates the row with the specfied primary key name and value, in the named table. The String where is used within the SET SQL sub-clause of the UPDATE statement.

Specified by:
update in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the primary key field.
keyValue - a String specifying the value of the primary key field.
set - a String specifying the name-value pairs for the updated fields.
Throws:
SQLException - if the update operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

delete

public void delete(String table,
                   String keyName,
                   long keyValue)
            throws SQLException

Deletes the row (or rows) with the specfied key name and value, in the named table.

Specified by:
delete in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the primary key field.
keyValue - a long specifying the value of the primary key field.
Throws:
SQLException - if the delete operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

delete

public void delete(String table,
                   String keyName,
                   String keyValue)
            throws SQLException

Deletes the row (or rows) with the specfied key name and value, in the named table.

Specified by:
delete in interface DB
Parameters:
table - a String naming the table.
keyName - a String specifying the name of the primary key field.
keyValue - a String specifying the value of the primary key field.
Throws:
SQLException - if the delete operation could not be completed.
Since:
JDBC 2.0, J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK