commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (DBCP-423) PoolingDataSource should implement Closeable
Date Fri, 16 Jan 2015 16:08:35 GMT


Sebb commented on DBCP-423:

There are two aspects to this: if the code sometimes wraps and sometimes doesn't it's not
immediately clear that the unwrapped Exceptions were properly dealt with.
It's potentially harder for higher level code to unravel as well.

The other aspect is that the wrapper Exception should have a message that describes how the
original exception affected the method and what has been done about it, i.e. it needs to add
useful context.

An analogy might be EOF or IOE when reading a file. By itself it means little, so the caller
needs to wrap it e.g. to say what it was trying to do when the error occurred (e.g. read the
trailer). The caller's caller may in turn need to wrap again to give context to the specific
file being processed. Etc.

> PoolingDataSource should implement Closeable
> --------------------------------------------
>                 Key: DBCP-423
>                 URL:
>             Project: Commons Dbcp
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Christian Schneider
>             Fix For: 2.1
>         Attachments: DBCP-423.patch
> Currently PoolingDataSource only implements DataSource. 
> I have the following case in ops4j pax-jdbc. I offer a DataSourceFactory in one bundle
that can create a pooling DataSource.
> Then in another bundle I create DataSources based on config in ConfigurationAdmin. So
when the config appears I create the DataSource, when the config goes away I have to destroy
> It is important to correctly dispose the DataSource as the pool has to be closed. As
I can not depend on dbcp in the bundle that destroys the DataSource I currently have no simple
way to destroy the DataSource.
> This is where I create the DataSource:
> I was able to solve it by a kind of hack. I extended the PoolingDataSource with a class
that supports Closeable. So from the other bundle I could check if the object implements Closeable
and call close.
> It would be a lot easier if PoolingDataSource would implement Closeable like I did. The
same is true for GenericObjectPool and the other pools. If they would implement Closeable
then handling them would be a lot easier.
> They already support a close method so it would be a small change.
> ----
> public class CloseablePoolingDataSource<C extends Connection> extends PoolingDataSource<C>
implements Closeable {
>     public CloseablePoolingDataSource(ObjectPool<C> pool) {
>         super(pool);
>     }
>     @Override
>     public void close() throws IOException {
>         getPool().close();
>     }
> }

This message was sent by Atlassian JIRA

View raw message