You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Daniel Baldes <db...@open.ch> on 2011/05/03 16:07:27 UTC

[dbcp] connection events / connection close hook

Hi,

I'd like to run some connection-specific clean-up code when a physical 
database connection is closed by the connection 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.

Is there any way to do that with DBCP? (Or any other workable connection 
pool implementation that you know?)

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


Re: [dbcp] connection events / connection close hook

Posted by Daniel Baldes <db...@open.ch>.
On Tue, 03 May 2011 08:54:32 -0700 Phil Steitz <ph...@gmail.com> 
wrote:
> 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?

Yes.

>>
>> 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.

Thanks for these hints. In the meantime, I found two database 
connection pools which seem to support this via listener interfaces: 
Proxool and BoneCP. The latter seems to be actually actively 
developed. Maybe you want to have a look at those if you plan to 
implement such an enhancement. I might open a JIRA, depending on the 
upcoming decision whether we will stick with DBCP.

Best regards,
Daniel

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


Re: [dbcp] connection events / connection close hook

Posted by Phil Steitz <ph...@gmail.com>.
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