|
OpMath | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.opmath.util.db.DBObject
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.
| 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 |
|
| Methods inherited from interface com.opmath.util.db.DB |
close, connect, getDriver |
| Field Detail |
protected Connection conn
The connection object for this DB.
protected String protocol
The name of the protocol for this DB.
protected String path
The absolute path for this DB.
| Constructor Detail |
public DBObject()
| Method Detail |
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.
className - a String the name of the class
implementing DB.path - a String specifying the absolute path,
including the database file or directory.DB.ClassNotFoundException - if it was not possible to construct
the specified object.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.
isAvailable in interface DBboolean indicating database availability.public String getProtocol()
Returns the protocol for the current connection.
Returns null if there is no current connection.
getProtocol in interface DBClass representing the database driver.public String getPath()
Returns the fully qualified path for the current connection.
Returns null if there is no current connection.
getPath in interface DBClass representing the database driver.
public Connection getConnection()
throws SQLException
Returns the connection object for this DB instance.
getConnection in interface DBConnection object.public String className()
Returns the name of the class of this DBObject object.
className in interface DBString naming the class.
public void createTable(String name,
String sqlColumns)
throws SQLException
Create a new table within this database.
createTable in interface DBname - 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.SQLException - if the table could not be created.
public void dropTable(String name)
throws SQLException
Delete a table within this database.
dropTable in interface DBname - a String the name of the new table.SQLException - if the table could not be deleted.
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.
maxIndex in interface DBtable - a String naming the table.pkName - a String specifying the name of the primary key field.SQLException - if the operation could not be completed.
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.
create in interface DBtable - a String the name of the table.values - a String the field values for the new row.SQLException - if the create operation could not be completed.
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.
read in interface DBtable - 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.ResultSet carrying the retrieved data.SQLException - if the read operation could not be completed.
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.
read in interface DBtable - 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.ResultSet carrying the retrieved data.SQLException - if the read operation could not be completed.
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.
readAll in interface DBtable - a String naming the table.order - a String specifying the sort field order.ResultSet carrying the retrieved data.SQLException - if the read operation could not be completed.
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.
query in interface DBtable - a String naming the table.where - a String specifying the sort field order.order - a String specifying the sort field order.ResultSet carrying the retrieved data.SQLException - if the query operation could not be completed.
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.
update in interface DBtable - 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.SQLException - if the update operation could not be completed.
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.
update in interface DBtable - 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.SQLException - if the update operation could not be completed.
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.
delete in interface DBtable - 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.SQLException - if the delete operation could not be completed.
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.
delete in interface DBtable - 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.SQLException - if the delete operation could not be completed.
|
OpMath | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||