openfuture.util.database
Class DBServer

java.lang.Object
  |
  +--openfuture.util.database.DBServer
Direct Known Subclasses:
HyperSQLServer, MySqlServer

public abstract class DBServer
extends java.lang.Object

Abstract JDBC database server.

Created: Tue Feb 08 05:52:56 2000

Version:
$Revision: 1.5 $
Author:
Wolfgang Reissenberger

Field Summary
static java.lang.String AUTO_INCREMENT
          Datatype AUTO_INCREMENT.
static java.lang.String BLOB
          Datatype BLOB.
static java.lang.String LAST_INSERT_ID
          Datatype LAST_INSERT_ID.
protected static java.lang.String[] usertables
           
 
Constructor Summary
DBServer()
           
 
Method Summary
 void closeConnection(java.sql.Connection con)
          Close a database connection.
 void closeStatement(java.sql.Statement statement)
          Close an SQL statement.
 void commitTransaction(java.sql.Connection con)
          Commit the current transaction.
 java.lang.Integer executeIndexedQuery(java.sql.Statement statement, java.lang.String sqlcommand)
          Execute an SQL query, that inserts a row into a table with an auto increment column.
 java.sql.Connection getConnection()
          Retrieve a new database connection.
protected  java.lang.String getPassword()
          Get the value of password.
protected  java.lang.String getUrl()
          Get the database connection string.
protected  java.lang.String getUser()
          Get the value of user.
abstract  void init(java.lang.String url, java.lang.String userid, java.lang.String password)
          Initialize the database pointed at by url for the given database driver
protected  void init(java.lang.String url, java.lang.String driverClass, java.lang.String userid, java.lang.String password)
          Initialize the database pointed at by url for the given database driver
 void openTransaction(java.sql.Connection con)
          Open a new transaction.
 void rollbackTransaction(java.sql.Connection con)
          Rollback the current transaction.
protected  void setPassword(java.lang.String v)
          Set the value of password.
protected  void setUrl(java.lang.String newUrl)
          Set the database connection string.
protected  void setUser(java.lang.String v)
          Set the value of user.
 java.lang.String sqlTranslate(java.lang.String s)
          Translate SQL constructs into database specific syntax.
 boolean tableExists(java.sql.Connection connection, java.lang.String name)
          Check, if the table name exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOB

public static final java.lang.String BLOB
Datatype BLOB.

LAST_INSERT_ID

public static final java.lang.String LAST_INSERT_ID
Datatype LAST_INSERT_ID.

AUTO_INCREMENT

public static final java.lang.String AUTO_INCREMENT
Datatype AUTO_INCREMENT.

usertables

protected static final java.lang.String[] usertables
Constructor Detail

DBServer

public DBServer()
Method Detail

init

public abstract void init(java.lang.String url,
                          java.lang.String userid,
                          java.lang.String password)
                   throws I18NException
Initialize the database pointed at by url for the given database driver
Parameters:
url - URL of the database. The URL must be of the form "jdbc:<database type>:<position>"
userid - database user ID for the database connection
password - database user password for the database connection
Throws:
I18NException - if an error occurs

init

protected void init(java.lang.String url,
                    java.lang.String driverClass,
                    java.lang.String userid,
                    java.lang.String password)
             throws I18NException
Initialize the database pointed at by url for the given database driver
Parameters:
url - URL of the database. The URL must be of the form "jdbc:<database type>:<position>"
driverClass - driver class name.
userid - database user ID for the database connection
password - database user password for the database connection
Throws:
I18NException - if something went wrong

sqlTranslate

public java.lang.String sqlTranslate(java.lang.String s)
Translate SQL constructs into database specific syntax. This method implements the identity. Override this method in super classes for database specifics.
Parameters:
s - SQL text
Returns:
database specific translation

tableExists

public boolean tableExists(java.sql.Connection connection,
                           java.lang.String name)
Check, if the table name exists. In order to check this, the connection is used.
Parameters:
connection - connection to the database
name - table name
Returns:
true, if the table exists

getConnection

public java.sql.Connection getConnection()
                                  throws I18NException
Retrieve a new database connection.
Returns:
the current database connection
Throws:
I18NException - if an error occurs

closeConnection

public void closeConnection(java.sql.Connection con)
                     throws I18NException
Close a database connection.
Parameters:
con - the current database connection
Throws:
I18NException - if an error occurs

closeStatement

public void closeStatement(java.sql.Statement statement)
                    throws I18NException
Close an SQL statement.
Parameters:
statement - a Statement value
Throws:
I18NException - if an error occurs

openTransaction

public void openTransaction(java.sql.Connection con)
                     throws I18NException
Open a new transaction.
Parameters:
con - the current database connection
Throws:
I18NException - if an error occurs

rollbackTransaction

public void rollbackTransaction(java.sql.Connection con)
                         throws I18NException
Rollback the current transaction.
Parameters:
con - the current database connection
Throws:
I18NException - if an error occurs

commitTransaction

public void commitTransaction(java.sql.Connection con)
                       throws I18NException
Commit the current transaction.
Parameters:
con - the current database connection
Throws:
I18NException - if an error occurs

executeIndexedQuery

public java.lang.Integer executeIndexedQuery(java.sql.Statement statement,
                                             java.lang.String sqlcommand)
                                      throws java.sql.SQLException
Execute an SQL query, that inserts a row into a table with an auto increment column.
Parameters:
statement - database statement
sqlcommand - command to be executed
Returns:
index of the row
Throws:
java.sql.SQLException - if an error occurs

getUser

protected java.lang.String getUser()
Get the value of user.
Returns:
Value of user.

setUser

protected void setUser(java.lang.String v)
Set the value of user.
Parameters:
v - Value to assign to user.

getPassword

protected java.lang.String getPassword()
Get the value of password.
Returns:
Value of password.

setPassword

protected void setPassword(java.lang.String v)
Set the value of password.
Parameters:
v - Value to assign to password.

getUrl

protected java.lang.String getUrl()
Get the database connection string.
Returns:
the database connection string.

setUrl

protected void setUrl(java.lang.String newUrl)
Set the database connection string.
Parameters:
newUrl - the new database connection string.


Copyright © 2000 -- 2003 openfuture.de. All Rights Reserved.