org.apache.avalon.excalibur.datasource
Class AbstractJdbcConnection

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.excalibur.datasource.AbstractJdbcConnection
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, java.lang.reflect.InvocationHandler, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.excalibur.pool.Poolable, PoolSettable, ProxiedJdbcConnection, org.apache.avalon.excalibur.pool.Recyclable
Direct Known Subclasses:
Jdbc3Connection, JdbcConnection

public class AbstractJdbcConnection
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements PoolSettable, org.apache.avalon.framework.activity.Disposable, ProxiedJdbcConnection

The Connection object used in conjunction with the JdbcDataSource object.

Since:
4.1
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:14 $
Author:
Avalon Development Team

Field Summary
protected  java.sql.Connection m_connection
           
protected  boolean m_encounteredError
          Flag to keep track of whether or not an error has been thrown since the last time the DB was pinged.
protected  long m_lastUsed
           
protected  org.apache.avalon.excalibur.pool.Pool m_pool
           
protected  int m_testAge
          The maximum time since a connection was last used before it will be pinged.
protected  java.sql.SQLException m_testException
           
protected  java.sql.PreparedStatement m_testStatement
           
 
Constructor Summary
AbstractJdbcConnection(java.sql.Connection connection, boolean oradb)
          Deprecated. Use the version with keepAlive specified
AbstractJdbcConnection(java.sql.Connection connection, java.lang.String keepAlive)
           
AbstractJdbcConnection(java.sql.Connection connection, java.lang.String keepAlive, int keepAliveAge)
           
 
Method Summary
protected  void clearAllocatedStatements()
          Closes statements that were registered and removes all statements from the list of allocated ones.
 void close()
           
 void dispose()
           
 void enableLogging(org.apache.avalon.framework.logger.Logger log)
           
 boolean equals(java.lang.Object obj)
           
 java.sql.Connection getConnection()
           
 void initialize()
           
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
 boolean isClosed()
           
 void recycle()
           
protected  void registerAllocatedStatement(java.sql.Statement stmt)
          Adds the statement to the list of this connection.
 void setPool(org.apache.avalon.excalibur.pool.Pool pool)
          Set the pool that will be used to recycle.
 void setProxiedConnection(java.lang.Object proxy)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_connection

protected java.sql.Connection m_connection

m_pool

protected org.apache.avalon.excalibur.pool.Pool m_pool

m_encounteredError

protected boolean m_encounteredError
Flag to keep track of whether or not an error has been thrown since the last time the DB was pinged.


m_testAge

protected int m_testAge
The maximum time since a connection was last used before it will be pinged.


m_testStatement

protected java.sql.PreparedStatement m_testStatement

m_testException

protected java.sql.SQLException m_testException

m_lastUsed

protected long m_lastUsed
Constructor Detail

AbstractJdbcConnection

public AbstractJdbcConnection(java.sql.Connection connection,
                              boolean oradb)
Deprecated. Use the version with keepAlive specified


AbstractJdbcConnection

public AbstractJdbcConnection(java.sql.Connection connection,
                              java.lang.String keepAlive)
Parameters:
connection - a driver specific JDBC connection to be wrapped.
keepAlive - a query which will be used to check the statis of the connection after it has been idle. A null value will cause the keep alive feature to be disabled.

AbstractJdbcConnection

public AbstractJdbcConnection(java.sql.Connection connection,
                              java.lang.String keepAlive,
                              int keepAliveAge)
Parameters:
connection - a driver specific JDBC connection to be wrapped.
keepAlive - a query which will be used to check the status of the connection after it has been idle. A null value will cause the keep alive feature to be disabled.
keepAliveAge - the maximum age in milliseconds since a connection was last used before it must be pinged using the keepAlive query. Ignored if keepAlive is null.
Method Detail

initialize

public void initialize()

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger log)
Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled

setPool

public void setPool(org.apache.avalon.excalibur.pool.Pool pool)
Description copied from interface: PoolSettable
Set the pool that will be used to recycle.

Specified by:
setPool in interface PoolSettable
Parameters:
pool -

recycle

public void recycle()
Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable

setProxiedConnection

public void setProxiedConnection(java.lang.Object proxy)
Specified by:
setProxiedConnection in interface ProxiedJdbcConnection

getConnection

public java.sql.Connection getConnection()
Specified by:
getConnection in interface ProxiedJdbcConnection

isClosed

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

close

public void close()
           throws java.sql.SQLException
Throws:
java.sql.SQLException

clearAllocatedStatements

protected void clearAllocatedStatements()
                                 throws java.sql.SQLException
Closes statements that were registered and removes all statements from the list of allocated ones. If any statement fails to properly close, the rest of the statements is ignored. But the registration list if cleared in any case.

Holds m_allocatedStatements locked the whole time. This should not be a problem because connections are inherently single threaded objects and any attempt to use them from a different thread while it is being closed is a violation of the contract.

Throws:
java.sql.SQLException - of the first Statement.close()

registerAllocatedStatement

protected void registerAllocatedStatement(java.sql.Statement stmt)
Adds the statement to the list of this connection. Used by subclasses to ensure release of statements when connection is logically terminated and returned to the pool.


dispose

public void dispose()
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

equals

public boolean equals(java.lang.Object obj)

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.