org.apache.avalon.excalibur.datasource
Class AbstractJdbcConnection
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.excalibur.datasource.AbstractJdbcConnection
- All Implemented Interfaces:
- Disposable, java.lang.reflect.InvocationHandler, LogEnabled, Poolable, PoolSettable, ProxiedJdbcConnection, Recyclable
- Direct Known Subclasses:
- Jdbc3Connection, JdbcConnection
- public class AbstractJdbcConnection
- extends AbstractLogEnabled
- implements PoolSettable, 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:
| Method Summary |
protected void |
clearAllocatedStatements()
Closes statements that were registered and removes all statements from the list of allocated ones. |
void |
close()
|
void |
dispose()
The dispose operation is called at the end of a components lifecycle. |
void |
enableLogging(Logger log)
Set the components logger. |
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()
This method should be implemented to remove all costly resources in object. |
protected void |
registerAllocatedStatement(java.sql.Statement stmt)
Adds the statement to the list of this connection. |
void |
setPool(Pool pool)
Set the pool that will be used to recycle. |
void |
setProxiedConnection(java.lang.Object proxy)
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
m_connection
protected java.sql.Connection m_connection
-
m_proxy
private java.lang.Object m_proxy
-
m_pool
protected Pool m_pool
-
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
-
m_methods
private static final java.util.Map m_methods
-
m_allocatedStatements
private final java.util.List m_allocatedStatements
-
Contains Statements created on the original jdbc connection between a
JdbcDataSource.getConnection() and Connection.close(). The statements are registered using registerAllocatedStatement(java.sql.Statement) and deallocated in close(). LinkedList was chosen because access to elements is sequential through Iterator and the number of elements is not known in advance. Synchronization is done on the Link instance itself.
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 statis 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.
initialize
public void initialize()
-
-
enableLogging
public void enableLogging(Logger log)
- Description copied from class:
AbstractLogEnabled
-
Set the components logger.
-
- Specified by:
enableLogging in interface LogEnabled
- Overrides:
enableLogging in class AbstractLogEnabled
-
- Parameters:
log - the logger
setPool
public void setPool(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()
- Description copied from interface:
Recyclable
-
This method should be implemented to remove all costly resources in object. These resources can be object references, database connections, threads, etc. What is categorised as "costly" resources is determined on a case by case analysis.
-
- Specified by:
recycle in interface 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
-
- Specified by:
isClosed in interface PoolSettable
-
- 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()
- Description copied from interface:
Disposable
-
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.
-
- Specified by:
dispose in interface 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
Please see keelframework.org for information about new Keel releases.