[ 
https://issues.apache.org/jira/browse/DBCP-423?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14277809#comment-14277809
 ] 

Thomas Neidhart commented on DBCP-423:
--------------------------------------

It is unfortunate that we can not touch the exception behavior but this should 
be done in another major release imho.

On a second thought, the approach in BDS should be further improved as it now 
catches a generic Exception and wraps it into a SQLException. If the pool will 
throw an exception in its close method it will most likely be already a 
SQLException (coming from the PoolableConnection implementation for example).

Thus we should not wrap a SQLException inside a SQLException but propagate the 
SQLException. The same is already done in the PoolableConnection.close() method.

> PoolingDataSource should implement Closeable
> --------------------------------------------
>
>                 Key: DBCP-423
>                 URL: https://issues.apache.org/jira/browse/DBCP-423
>             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.
> 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:
> https://github.com/ops4j/org.ops4j.pax.jdbc/blob/master/pax-jdbc-pool/src/main/java/org/ops4j/pax/jdbc/pool/impl/PooledDataSourceFactory.java
> 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
(v6.3.4#6332)

Reply via email to