org.enhydra.jdbc.standard
Class StandardConnectionHandle

java.lang.Object
  |
  +--org.enhydra.jdbc.core.CoreConnection
        |
        +--org.enhydra.jdbc.standard.StandardConnectionHandle
All Implemented Interfaces:
java.sql.Connection
Direct Known Subclasses:
StandardXAConnectionHandle

public class StandardConnectionHandle
extends CoreConnection

This is an implementation of java.sql.Connection which simply delegates almost everything to an underlying physical implemention of the same interface. It relies on a StandardPooledConnection to create it and to supply the physical connection and a cache of PreparedStatements. This class will try to re-use PreparedStatements wherever possible and will add to the cache when totally new PreparedStatements get created.


Field Summary
 java.util.Hashtable inUse
           
protected  java.util.Hashtable masterPrepStmtCache
           
protected  LRUCache preparedStatementCache
           
 
Fields inherited from class org.enhydra.jdbc.core.CoreConnection
con
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
StandardConnectionHandle(StandardPooledConnection pooledCon, java.util.Hashtable preparedStatementCache, int preparedStmtCacheSize)
          Constructor.
 
Method Summary
 void catchInvoke(java.sql.SQLException e)
          Exception management : catch or throw the exception
 void close()
          Closes this StandardConnectionHandle and prevents it from being reused.
protected  java.sql.PreparedStatement createPreparedStatement(java.lang.String sql, int type, int concurrency)
           
 boolean isClosed()
           
 void preInvoke()
          Pre-invokation of the delegation, in case of connection is closed, we throw an exception
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Creates a PreparedStatement for the given SQL.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Creates a PreparedStatement for the given SQL, type and concurrency.
protected  void setupPreparedStatementCache()
           
 
Methods inherited from class org.enhydra.jdbc.core.CoreConnection
clearWarnings, commit, createStatement, createStatement, getAutoCommit, getCatalog, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isReadOnly, nativeSQL, prepareCall, rollback, setAutoCommit, setCatalog, setReadOnly, setTransactionIsolation, setTypeMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

masterPrepStmtCache

protected java.util.Hashtable masterPrepStmtCache

preparedStatementCache

protected LRUCache preparedStatementCache

inUse

public java.util.Hashtable inUse
Constructor Detail

StandardConnectionHandle

public StandardConnectionHandle(StandardPooledConnection pooledCon,
                                java.util.Hashtable preparedStatementCache,
                                int preparedStmtCacheSize)
Constructor.
Method Detail

setupPreparedStatementCache

protected void setupPreparedStatementCache()

preInvoke

public void preInvoke()
               throws java.sql.SQLException
Pre-invokation of the delegation, in case of connection is closed, we throw an exception
Overrides:
preInvoke in class CoreConnection

catchInvoke

public void catchInvoke(java.sql.SQLException e)
                 throws java.sql.SQLException
Exception management : catch or throw the exception
Overrides:
catchInvoke in class CoreConnection

close

public void close()
           throws java.sql.SQLException
Closes this StandardConnectionHandle and prevents it from being reused. It also returns used PreparedStatements to the PreparedStatement cache and notifies all listeners.
Overrides:
close in class CoreConnection

createPreparedStatement

protected java.sql.PreparedStatement createPreparedStatement(java.lang.String sql,
                                                             int type,
                                                             int concurrency)
                                                      throws java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Creates a PreparedStatement for the given SQL. If possible, the statement is fetched from the cache.
Overrides:
prepareStatement in class CoreConnection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Creates a PreparedStatement for the given SQL, type and concurrency. If possible, the statement is fetched from the cache.
Overrides:
prepareStatement in class CoreConnection

isClosed

public boolean isClosed()
                 throws java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException