Probably a solution (or workaround) would be to have a initial decorator which doesn't delegate the unwrap() method to the tomcat data source and instead just returns the org.apache.tomcat.jdbc.pool.DataSource instance.
The downside is that this needs to be the very first decorator applied. On Fri, Mar 2, 2012 at 11:53 AM, amit shah <amits...@gmail.com> wrote: > Hello, > I am using the tomcat7 jdbc pool independently by deploying the > jdbc pool and juli jars with my web application. I would like to get > suggestions on how to close the connection pool when the application server > is stopped. > The below code doesn't work as expected > > public void shutdown(DataSource dataSource) { > org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = > null; > try { > tomcatDataSource = > dataSource.unwrap(org.apache.tomcat.jdbc.pool.DataSource.class); > } catch (SQLException e) { > throw new RuntimeException(e); > } > tomcatDataSource.close(); > } > > > The reason being the unwrap implementation > in org.apache.tomcat.jdbc.pool.DataSource returns null. Hence a NPE. > Casting the dataSource instance to > directly org.apache.tomcat.jdbc.pool.DataSource isn't an option because > during creation we decorate the data source for various reasons like > logging, changing the isolation level etc. > > Any ideas on how could the close method be called? > > Thank you. >