org.apache.commons.dbcp
Class DelegatingConnection

java.lang.Object
  |
  +--org.apache.commons.dbcp.AbandonedTrace
        |
        +--org.apache.commons.dbcp.DelegatingConnection
All Implemented Interfaces:
java.sql.Connection
Direct Known Subclasses:
PoolableConnection, PoolingConnection

public class DelegatingConnection
extends AbandonedTrace
implements java.sql.Connection

A base delegating implementation of Connection.

All of the methods from the Connection interface simply check to see that the Connection is active, and call the corresponding method on the "delegate" provided in my constructor.

Extends AbandonedTrace to implement Connection tracking and logging of code which created the Connection. Tracking the Connection ensures that the AbandonedObjectPool can close this connection and recycle it if its pool of connections is nearing exhaustion and this connection's last usage is older than the removeAbandonedTimeout.

Version:
$Id: DelegatingConnection.java,v 1.7 2002/06/29 17:36:37 glenn Exp $
Author:
Rodney Waldhoff
, Glenn L. Nielsen , James House (james@interobjective.com)

Field Summary
protected  boolean _closed
           
protected  java.sql.Connection _conn
          My delegate Connection.
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
DelegatingConnection(java.sql.Connection c)
          Create a wrapper for the Connectin which traces this Connection in the AbandonedObjectPool.
DelegatingConnection(java.sql.Connection c, AbandonedConfig config)
          Create a wrapper for the Connection which traces the Statements created so that any unclosed Statements can be closed when this Connection is closed.
 
Method Summary
protected  void activate()
           
protected  void checkOpen()
           
 void clearWarnings()
           
 void close()
          Closes the underlying connection, and close any Statements that were not explicitly closed.
 void commit()
           
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
           
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.sql.Connection getDelegate()
          Returns my underlying Connection.
 java.sql.Connection getInnermostDelegate()
          If my underlying Connection is not a DelegatingConnection, returns it, otherwise recursively invokes this method on my delegate.
 java.sql.DatabaseMetaData getMetaData()
           
 int getTransactionIsolation()
           
 java.util.Map getTypeMap()
           
 java.sql.SQLWarning getWarnings()
           
 boolean isClosed()
           
 boolean isReadOnly()
           
 java.lang.String nativeSQL(java.lang.String sql)
           
protected  void passivate()
           
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 void rollback()
           
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
 void setDelegate(java.sql.Connection c)
          Sets my delegate.
 void setReadOnly(boolean readOnly)
           
 void setTransactionIsolation(int level)
           
 void setTypeMap(java.util.Map map)
           
 
Methods inherited from class org.apache.commons.dbcp.AbandonedTrace
addTrace, clearTrace, getConfig, getLastUsed, getTrace, printStackTrace, removeTrace, setLastUsed, setLastUsed, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Connection
createStatement, getHoldability, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setHoldability, setSavepoint, setSavepoint
 

Field Detail

_closed

protected boolean _closed

_conn

protected java.sql.Connection _conn
My delegate Connection.

Constructor Detail

DelegatingConnection

public DelegatingConnection(java.sql.Connection c)
Create a wrapper for the Connectin which traces this Connection in the AbandonedObjectPool.

Parameters:
c - the Connection to delegate all calls to.

DelegatingConnection

public DelegatingConnection(java.sql.Connection c,
                            AbandonedConfig config)
Create a wrapper for the Connection which traces the Statements created so that any unclosed Statements can be closed when this Connection is closed.

Method Detail

activate

protected void activate()

checkOpen

protected void checkOpen()
                  throws java.sql.SQLException
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Closes the underlying connection, and close any Statements that were not explicitly closed.

Specified by:
close in interface java.sql.Connection
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
java.sql.SQLException

getDelegate

public java.sql.Connection getDelegate()
Returns my underlying Connection.

Returns:
my underlying Connection.

getInnermostDelegate

public java.sql.Connection getInnermostDelegate()
If my underlying Connection is not a DelegatingConnection, returns it, otherwise recursively invokes this method on my delegate.

Hence this method will return the first delegate that is not a DelegatingConnection, or null when no non-DelegatingConnection delegate can be found by transversing this chain.

This method is useful when you may have nested DelegatingConnections, and you want to make sure to obtain a "genuine" Connection.


getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
java.sql.SQLException

passivate

protected void passivate()
                  throws java.sql.SQLException
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
java.sql.SQLException

prepareStatement

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

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
java.sql.SQLException

setDelegate

public void setDelegate(java.sql.Connection c)
Sets my delegate.


setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
java.sql.SQLException


Copyright © 2001 Apache Software Foundation. Documenation generated August 12 2002.