org.edg.security.voms.database.connection
Class ConnectionWrapper

java.lang.Object
  |
  +--org.edg.security.voms.database.connection.ConnectionWrapper
Direct Known Subclasses:
ClientConnection, DirectUpdate

public abstract class ConnectionWrapper
extends java.lang.Object

A wrapper around java.sql.Connection for convenient handling of prepared SQL statements.

Version:
$Name: v0_7_0 $
Author:
Karoly Lorentey

Field Summary
protected  java.sql.Connection conn
          The raw database connection.
private  boolean dirty
          The dirty flag.
protected  int id
           
protected  boolean inTransaction
          True if a transaction is in progress.
protected static org.apache.log4j.Logger log
          Logger.
protected  ConnectionPool pool
           
protected  java.util.HashMap stmts
          A collection of prepared statements created using this connection.
 
Constructor Summary
ConnectionWrapper(java.sql.Connection conn, ConnectionPool pool, int id)
          Wraps a new wrapper around an already established connection.
 
Method Summary
(package private)  void beginTransaction()
           
 void close()
          Close this connection.
 java.sql.Connection getConnection()
          Returns the raw java.sql.Connection object associated with this handler.
 java.sql.PreparedStatement getStatement(java.lang.String statement)
          Converts the given SQL statement to a PreparedStatement.
 boolean isClosed()
          Returns true if this connection is closed.
 boolean isDirty()
          Returns the dirty flag.
 boolean isFunctional()
          Tries to determine if the connection is functional by executing a simple query against the database.
(package private)  boolean isInTransaction()
          Used by ConnectionPool to determine if the connection may be released back to its pool.
abstract  boolean isReadonly()
           
 void setDirty()
          Sets the dirty flag.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

conn

protected java.sql.Connection conn
The raw database connection.


id

protected final int id

pool

protected final ConnectionPool pool

inTransaction

protected boolean inTransaction
True if a transaction is in progress.


stmts

protected java.util.HashMap stmts
A collection of prepared statements created using this connection. TODO: This is not used because JDBC doesn't seem to support reusing prepared statements across transactions.


log

protected static org.apache.log4j.Logger log
Logger.


dirty

private boolean dirty
The dirty flag.

Constructor Detail

ConnectionWrapper

public ConnectionWrapper(java.sql.Connection conn,
                         ConnectionPool pool,
                         int id)
Wraps a new wrapper around an already established connection.

Method Detail

getConnection

public java.sql.Connection getConnection()
Returns the raw java.sql.Connection object associated with this handler.


getStatement

public java.sql.PreparedStatement getStatement(java.lang.String statement)
                                        throws java.sql.SQLException
Converts the given SQL statement to a PreparedStatement. This is usually equivalent to the prepareStatement method of the wrapped java.sql.Connection object.

java.sql.SQLException

isFunctional

public boolean isFunctional()
Tries to determine if the connection is functional by executing a simple query against the database. Returns true if it succeeds.


close

public void close()
Close this connection. The getStatement method is not to be called on a closed ConnectionWrapper.


isClosed

public boolean isClosed()
Returns true if this connection is closed.


isDirty

public boolean isDirty()
Returns the dirty flag. A dirty connection will not be reused for later transactions.


setDirty

public void setDirty()
Sets the dirty flag. It can not be cleared.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isReadonly

public abstract boolean isReadonly()

beginTransaction

void beginTransaction()
                throws VOMSException
VOMSException

isInTransaction

boolean isInTransaction()
Used by ConnectionPool to determine if the connection may be released back to its pool.