List of usage examples for org.apache.commons.dbcp BasicDataSource close
public synchronized void close() throws SQLException
From source file:org.apache.jackrabbit.core.util.db.ConnectionFactory.java
/** * *///from w w w . j av a2 s. com public void close() { synchronized (lock) { sanityCheck(); for (BasicDataSource ds : created) { try { ds.close(); } catch (SQLException e) { log.error("failed to close " + ds, e); } } keyToDataSource.clear(); nameToDataSource.clear(); nameToDataSourceDef.clear(); created.clear(); closed = true; } }
From source file:org.apache.torque.JndiConfigurationTest.java
/** * Tests whether our home-made Data Source works. * @throws Exception if the test fails./*from w w w . jav a 2 s . com*/ */ public void testDataSource() throws Exception { BasicDataSource dataSource = null; try { dataSource = getDataSource(); dataSourceConnect(dataSource); } finally { if (dataSource != null) { dataSource.close(); } } }
From source file:org.apache.torque.JndiConfigurationTest.java
/** * unbinds and closes the BasicDataSource in jndi. * @throws Exception if creation or binfding fails. *//*from ww w . j a v a2 s .c om*/ protected void unbindDataSource() throws Exception { Context context = getInitialContext(); BasicDataSource dataSource = (BasicDataSource) context.lookup(JNDI_PATH); try { if (dataSource != null) { dataSource.close(); } } finally { context.unbind(JNDI_PATH); } }
From source file:org.bzewdu.tools.perftrend.data.oracledalHelper.java
/** * * @param ds// w w w . ja v a 2 s.c o m * @throws SQLException */ public static void shutdownDataSource(final DataSource ds) throws SQLException { BasicDataSource bds; if (ds != null) { bds = (BasicDataSource) ds; } else { bds = (BasicDataSource) oracledalHelper.dataSource; } bds.close(); }
From source file:org.danann.cernunnos.sql.BasicDataSourceTemplate.java
public final void perform(TaskRequest req, TaskResponse res) { //Get the JDBC properties final String driverClassName = (String) this.driverPhrase.evaluate(req, res); final String url = (String) this.urlPhrase.evaluate(req, res); final String username = (String) this.usernamePhrase.evaluate(req, res); final String password = (String) this.passwordPhrase.evaluate(req, res); final String dataSourceInfo = "driverClassName='" + driverClassName + "', url='" + url + "', username='" + username + "'"; this.logger.debug("Creating DataSource for " + dataSourceInfo + "."); final BasicDataSource dataSource = new BasicDataSource(); try {//from ww w .j a v a 2 s. co m //Configure the pooling DataSource dataSource.setUrl(url); dataSource.setDriverClassName(driverClassName); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setPoolPreparedStatements(true); dataSource.setMaxActive(-1); dataSource.setMaxIdle(32); //Provide the DataSource on the response environment final String dataSourceAttrName = (String) this.attributeNamePhrase.evaluate(req, res); res.setAttribute(dataSourceAttrName, dataSource); this.logger.debug("Attached DataSource '" + dataSource + "' for " + dataSourceInfo + " to response under attribute '" + dataSourceAttrName + "'."); //Execute subtasks this.performWithDataSource(req, res, dataSource); } finally { try { //Cleanup after the subtasks dataSource.close(); this.logger.debug("Closed DataSource '" + dataSource + "' for " + dataSourceInfo + "."); } catch (SQLException e) { throw new RuntimeException( "Failed to close BasicDataSource '" + dataSource + "' for " + dataSourceInfo + ".", e); } } }
From source file:org.geotools.data.jdbc.ds.UnWrapperTest.java
public void testDBCPUnwrapper() throws SQLException, IOException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl("jdbc:h2:mem:test_mem"); ds.setAccessToUnderlyingConnectionAllowed(true); Connection conn = ds.getConnection(); UnWrapper uw = DataSourceFinder.getUnWrapper(conn); assertNotNull(uw);/* w w w . j av a2 s .c om*/ assertTrue(uw.canUnwrap(conn)); Connection unwrapped = uw.unwrap(conn); assertNotNull(unwrapped); assertTrue(unwrapped instanceof org.h2.jdbc.JdbcConnection); Statement st = conn.createStatement(); uw = DataSourceFinder.getUnWrapper(st); assertNotNull(uw); assertTrue(uw.canUnwrap(st)); Statement uwst = uw.unwrap(st); assertNotNull(uwst); assertTrue(uwst instanceof org.h2.jdbc.JdbcStatement); st.close(); PreparedStatement ps = conn.prepareStatement("select curtime()"); uw = DataSourceFinder.getUnWrapper(ps); assertNotNull(uw); assertTrue(uw.canUnwrap(ps)); PreparedStatement uwps = (PreparedStatement) uw.unwrap(ps); assertNotNull(uwps); assertTrue(uwps instanceof org.h2.jdbc.JdbcPreparedStatement); ps.close(); conn.close(); ds.close(); }
From source file:org.geotools.jdbc.JDBCTestSetup.java
public void tearDown() throws Exception { final String leakMessage = "Expected no active connection, either there is a connection leak " + "or you forgot to close some object holding onto connections in the tests (e.g., a reader, an iterator)"; if (dataSource instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) dataSource; assertEquals(leakMessage, 0, bds.getNumActive()); } else if (dataSource instanceof DBCPDataSource) { BasicDataSource bds = (BasicDataSource) ((DBCPDataSource) dataSource).getWrapped(); assertEquals(leakMessage, 0, bds.getNumActive()); }//from w ww .j a va 2 s . c o m if (dataSource instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) dataSource; bds.close(); } else if (dataSource instanceof ManageableDataSource) { ((ManageableDataSource) dataSource).close(); } }
From source file:org.gogoego.util.db.DBSessionFactory.java
public static void unregisterDataSource(final String name) { BasicDataSource ds = (BasicDataSource) knownDataSources.get(name); if (ds == null) return;//from w ww .ja va 2 s .co m try { ds.close(); } catch (SQLException exception) { System.err.println("Unable to close data source " + name); } knownDataSources.remove(name); dbSessions.remove(name); }
From source file:org.jumpmind.db.platform.AbstractJdbcDatabasePlatform.java
public void resetDataSource() { if (dataSource instanceof BasicDataSource) { BasicDataSource dbcp = (BasicDataSource) dataSource; try {//from ww w . j a va2 s. co m dbcp.close(); } catch (SQLException e) { throw sqlTemplate.translate(e); } } }
From source file:org.jumpmind.metl.ui.common.DbResource.java
public void close() { if (platform != null) { BasicDataSource ds = (BasicDataSource) platform.getDataSource(); if (ds != null) { try { ds.close(); } catch (SQLException e) { }/*from w w w . j ava 2 s. com*/ } } }