org.enhydra.jdbc.standard
Class StandardConnectionHandle

java.lang.Object
  extended by org.enhydra.jdbc.util.JdbcUtil
      extended by org.enhydra.jdbc.core.CoreConnection
          extended by org.enhydra.jdbc.standard.StandardConnectionHandle
All Implemented Interfaces:
java.sql.Connection
Direct Known Subclasses:
InformixConnectionHandle, StandardXAConnectionHandle, SybaseConnectionHandle

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
           
 boolean isReallyUsed
           
protected  java.util.Hashtable masterPrepStmtCache
           
protected  LRUCache preparedStatementCache
           
 
Fields inherited from class org.enhydra.jdbc.core.CoreConnection
con
 
Fields inherited from class org.enhydra.jdbc.util.JdbcUtil
log
 
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 autogeneratedkeys)
           
protected  java.sql.PreparedStatement createPreparedStatement(java.lang.String sql, int type, int concurrency, int holdability)
           
 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.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
protected  void setupPreparedStatementCache()
           
 
Methods inherited from class org.enhydra.jdbc.core.CoreConnection
clearWarnings, commit, createStatement, createStatement, createStatement, getAutoCommit, getCatalog, getHoldability, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isReadOnly, nativeSQL, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap
 
Methods inherited from class org.enhydra.jdbc.util.JdbcUtil
setLogger
 
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

isReallyUsed

public boolean isReallyUsed
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

Specified by:
preInvoke in class CoreConnection
Throws:
java.sql.SQLException

catchInvoke

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

Specified by:
catchInvoke in class CoreConnection
Throws:
java.sql.SQLException

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.

Specified by:
close in interface java.sql.Connection
Overrides:
close in class CoreConnection
Throws:
java.sql.SQLException

createPreparedStatement

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

createPreparedStatement

protected java.sql.PreparedStatement createPreparedStatement(java.lang.String sql,
                                                             int autogeneratedkeys)
                                                      throws java.sql.SQLException
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.

Specified by:
prepareStatement in interface java.sql.Connection
Overrides:
prepareStatement in class CoreConnection
Throws:
java.sql.SQLException

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.

Specified by:
prepareStatement in interface java.sql.Connection
Overrides:
prepareStatement in class CoreConnection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Overrides:
prepareStatement in class CoreConnection
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

prepareCall

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