uk.ac.ic.doc.automed.util.db
Class DBAccess

java.lang.Object
  extended by uk.ac.ic.doc.automed.util.db.DBAccess
Direct Known Subclasses:
DBEmbedded, DBPostgres

public abstract class DBAccess
extends java.lang.Object


Field Summary
protected  java.util.Map connections
           
protected  java.lang.String dbFQPath
           
protected  java.lang.String password
           
protected  java.util.Properties props
           
protected  java.lang.String user
           
 
Constructor Summary
DBAccess(java.lang.String dbFQPath, java.lang.String user, java.lang.String password, java.util.Properties props)
          Creates a new instance of DBAccess
 
Method Summary
 void closeConnection()
           
abstract  void commit()
          Only use this method if you want to commit changes immediately.
protected  void executeCommand(java.lang.String cmd)
          Mostly used for executing control commands, e.g.
abstract  java.sql.ResultSet executeQuery(java.lang.String expression)
          This method is used for SELECT statement
abstract  void executeStatement(java.lang.String expression)
          This method is used for making changes to data, e.g.
abstract  java.sql.Connection getConnection()
           
 java.util.Map getCurrentRow(java.sql.ResultSet rs)
          Return current row in a result set as a HashMap of column->value.
 boolean isTableExist(java.lang.String name)
          Checks whether or not a table exists in the database
 java.sql.Connection newConnection()
          Creates a new connection to add to the pool
 void printResultSet(java.sql.ResultSet rs)
          A generic implementation of debug-print of a result set
abstract  void setAutoCommit(boolean autoCommit)
          Different data sources understands auto-commit differently.
 void shutdown()
          Shutdown in-process database, closes current connection to it
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbFQPath

protected java.lang.String dbFQPath

user

protected java.lang.String user

password

protected java.lang.String password

props

protected java.util.Properties props

connections

protected java.util.Map connections
Constructor Detail

DBAccess

public DBAccess(java.lang.String dbFQPath,
                java.lang.String user,
                java.lang.String password,
                java.util.Properties props)
Creates a new instance of DBAccess

Method Detail

newConnection

public java.sql.Connection newConnection()
                                  throws java.sql.SQLException
Creates a new connection to add to the pool

Throws:
java.sql.SQLException

getConnection

public abstract java.sql.Connection getConnection()

closeConnection

public void closeConnection()

shutdown

public void shutdown()
              throws java.sql.SQLException
Shutdown in-process database, closes current connection to it

Throws:
java.sql.SQLException

setAutoCommit

public abstract void setAutoCommit(boolean autoCommit)
                            throws java.sql.SQLException
Different data sources understands auto-commit differently. This method
tries to encapsulate the operation to set auto-commit

Parameters:
autoCommit - a boolean value: true = auto-commit; false otherwise
Throws:
java.sql.SQLException

commit

public abstract void commit()
                     throws java.sql.SQLException
Only use this method if you want to commit changes immediately.

Throws:
java.sql.SQLException

isTableExist

public boolean isTableExist(java.lang.String name)
                     throws java.sql.SQLException
Checks whether or not a table exists in the database

Throws:
java.sql.SQLException

getCurrentRow

public java.util.Map getCurrentRow(java.sql.ResultSet rs)
                            throws java.sql.SQLException
Return current row in a result set as a HashMap of column->value.

Throws:
java.sql.SQLException

printResultSet

public void printResultSet(java.sql.ResultSet rs)
                    throws java.sql.SQLException
A generic implementation of debug-print of a result set

Throws:
java.sql.SQLException

executeQuery

public abstract java.sql.ResultSet executeQuery(java.lang.String expression)
                                         throws java.sql.SQLException
This method is used for SELECT statement

Parameters:
expression - is an SQL statement to use
Returns:
ResultSet object of the result data
Throws:
java.sql.SQLException

executeStatement

public abstract void executeStatement(java.lang.String expression)
                               throws java.sql.SQLException
This method is used for making changes to data, e.g. INSERT, DELETE, UPDATE

Parameters:
expression - is an SQL statement to use
Throws:
java.sql.SQLException

executeCommand

protected void executeCommand(java.lang.String cmd)
                       throws java.sql.SQLException
Mostly used for executing control commands, e.g. SHUTDOWN, SET ...

Parameters:
cmd - the command to execute
Throws:
java.sql.SQLException