commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: [dbcp] connection events / connection close hook
Date Tue, 03 May 2011 15:54:32 GMT
On 5/3/11 7:07 AM, Daniel Baldes wrote:
> Hi,
>
> I'd like to run some connection-specific clean-up code when a
> physical database connection is closed by the connection pool.

You mean really closed, as in destroyed, or just returned to the pool?
>
> I found ConnectionEventListener and
> PooledConnection.addConnectionEventListener() in the JDBC API,
> however I think this is just used internally by JDBC drivers? At
> least I found no reasonable way to attach my own listener to new
> connections.

Right, these are not in general exposed.
>
> Is there any way to do that with DBCP? (Or any other workable
> connection pool implementation that you know?)

No direct way at least that I can think of.  If you are using DBCP
1.3+, you can may be able to get the behavior that you want by:

0) subclass PoolableConnectionFactory and override either
passivateObject (what is called when a connection is returned to the
pool) or destroyObject to do the cleanup (assuming you can make
available all of the references needed in the context of these methods)
1) subclass BasicDataSource and override
createPoolableConnectionFactory to use the subclassed factory from 0)

Sorry I can't see a simple way to do this.  Seems a reasonable
enhancement request.  Please feel free to open a JIRA.

Phil
>
> Thanks in advance!
>
> Regards,
> Daniel Baldes
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message