@Override public void close() { if (db != null) { db.close(); } db = null; }
@Override public void stop() { PGPoolingDataSource ds = this.ds; this.ds = null; if ( ds != null ) { ds.close(); } }
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class MyClass implements ServletContextListener { private String db = "foo"; @Override public void contextDestroyed(ServletContextEvent sce) { PGPoolingDataSource connectionPool = (PGPoolingDataSource)new InitialContext().lookup(db); if(connectionPool != null) { connectionPool.close(); new InitialContext().unbind(db); } } }
/** * {@inheritDoc} */ @Override public void finalize() throws Throwable { super.finalize(); if (datasource instanceof com.zaxxer.hikari.HikariDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((com.zaxxer.hikari.HikariDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.ds.PGPoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.jdbc2.optional.PoolingDataSource) datasource).close(); } else { LOG.warn("Finalise - Could not close datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader() + " - " + datasource.getClass().toString()); } }
/** * {@inheritDoc} */ @Override public void finalize() throws Throwable { super.finalize(); if (datasource instanceof com.zaxxer.hikari.HikariDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((com.zaxxer.hikari.HikariDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.ds.PGPoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.jdbc2.optional.PoolingDataSource) datasource).close(); } else { LOG.warn("Finalise - Could not close datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader() + " - " + datasource.getClass().toString()); } }
LOG.info("Shutdown - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Shutdown - Closing datasource for Database " + getURL() + "(" + toString()
LOG.info("Shutdown - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Shutdown - Closing datasource for Database " + getURL() + "(" + toString()
old.close(); } catch (Exception e) { log.debug("[IGNORED] Exception while closing the datasource: ", e);