List of usage examples for org.apache.commons.dbcp BasicDataSource close
public synchronized void close() throws SQLException
From source file:com.alibaba.otter.node.etl.common.datasource.impl.DBDataSourceService.java
public void destroy(Long pipelineId) { Map<DbMediaSource, DataSource> sources = dataSources.remove(pipelineId); if (sources != null) { for (DataSource source : sources.values()) { try { // for filter to destroy custom datasource if (letHandlerDestroyIfSupport(pipelineId, source)) { continue; }/*w w w .ja va2 s .c o m*/ // fallback for regular destroy // TODO need to integrate to handler BasicDataSource basicDataSource = (BasicDataSource) source; basicDataSource.close(); } catch (SQLException e) { logger.error("ERROR ## close the datasource has an error", e); } } sources.clear(); } }
From source file:com.googlecode.flyway.maven.AbstractFlywayMojoTest.java
/** * Asserts that this mojo does not leak DB connections when executed. * * @param mojo The mojo to check./*from ww w . j av a 2s.c o m*/ */ private void assertNoConnectionLeak(AbstractFlywayMojo mojo) throws Exception { mojo.driver = "org.h2.Driver"; mojo.url = "jdbc:h2:mem:flyway_leak_test"; mojo.user = "SA"; try { mojo.execute(); } catch (Exception e) { // Ignoring. The exception is not what we're testing. } BasicDataSource dataSource = mojo.createDataSource(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); H2DbSupport h2DbSupport = new H2DbSupport(jdbcTemplate); boolean tableStillPresent = h2DbSupport.tableExists(h2DbSupport.getCurrentSchema(), "schema_version"); dataSource.close(); assertFalse(tableStillPresent); }
From source file:com.alibaba.otter.common.push.datasource.media.MediaPushDataSource.java
public synchronized void destory() throws SQLException { if (delegate != null) { BasicDataSource basicDataSource = (BasicDataSource) delegate; basicDataSource.close(); delegate = null;// w w w .j ava 2s . co m } if (dataSourceSupplier != null) { dataSourceSupplier.stop(); dataSourceSupplier = null; } }
From source file:com.alibaba.otter.node.etl.common.datasource.impl.DBDataSourceService.java
public DBDataSourceService() { // soft//from w w w.ja va2s. com GenericMapMaker mapMaker = new MapMaker().softValues(); mapMaker = ((MapMaker) mapMaker) .evictionListener(new MapEvictionListener<Long, Map<DbMediaSource, DataSource>>() { public void onEviction(Long pipelineId, Map<DbMediaSource, DataSource> dataSources) { if (dataSources == null) { return; } for (DataSource dataSource : dataSources.values()) { // for filter to destroy custom datasource if (letHandlerDestroyIfSupport(pipelineId, dataSource)) { continue; } BasicDataSource basicDataSource = (BasicDataSource) dataSource; try { basicDataSource.close(); } catch (SQLException e) { logger.error("ERROR ## close the datasource has an error", e); } } } }); // map dataSources = new MapMaker().makeComputingMap(new Function<Long, Map<DbMediaSource, DataSource>>() { public Map<DbMediaSource, DataSource> apply(final Long pipelineId) { // map return new MapMaker().makeComputingMap(new Function<DbMediaSource, DataSource>() { public DataSource apply(DbMediaSource dbMediaSource) { // ,? dataSource DataSource customDataSource = preCreate(pipelineId, dbMediaSource); if (customDataSource != null) { return customDataSource; } return createDataSource(dbMediaSource.getUrl(), dbMediaSource.getUsername(), dbMediaSource.getPassword(), dbMediaSource.getDriver(), dbMediaSource.getType(), dbMediaSource.getEncode()); } }); } }); }
From source file:com.mirth.connect.connectors.jdbc.JdbcConnector.java
private void shutdownDataSource() throws Exception { BasicDataSource bds = (BasicDataSource) dataSource; bds.close(); }
From source file:io.apiman.gateway.engine.impl.DefaultJdbcComponentTest.java
@Test public void testDataSource() throws Throwable { DefaultJdbcComponent component = new DefaultJdbcComponent(); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:testDataSource;DB_CLOSE_DELAY=-1"); try {//from www . ja v a2s .c o m IJdbcClient client = component.create(ds); doAllTests(client); } finally { try { ds.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:net.firejack.platform.model.config.hibernate.HibernateFactoryBean.java
public void destroy() { for (String name : databases.keySet()) { try {// w ww . j a v a2 s . c om BasicDataSource dataSource = context.getBean(name + HIBERNATE_DATA_SOURCE_SUFFIX, BasicDataSource.class); dataSource.close(); } catch (Exception e) { logger.error(e); } } for (String name : xaDatabases.keySet()) { try { AtomikosDataSourceBean dataSource = context.getBean(name + HIBERNATE_DATA_SOURCE_SUFFIX, AtomikosDataSourceBean.class); dataSource.close(); } catch (Exception e) { logger.error(e); } } for (DisposableBean bean : disposableBeans) { try { bean.destroy(); } catch (Exception e) { logger.error(e); } } }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSource.java
/** * Close all connections/*w w w .j av a2 s . c o m*/ */ public void close() { if (ds instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) ds; try { bds.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSource.java
/** * Close all connections/*from www . j ava 2 s . com*/ */ @Override public void close() { if (ds instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) ds; try { bds.close(); } catch (SQLException e) { LOG.log(Level.INFO, null, e); } } }
From source file:herddb.jdbc.CommonsDBCPTest.java
@Test public void test() throws Exception { try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) { server.start();/*from w w w. j a v a2 s .co m*/ BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:herddb:server:localhost:7000?"); dataSource.setDriverClassName(Driver.class.getName()); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) { int count = 0; while (rs.next()) { System.out.println("table: " + rs.getString(1)); count++; } assertTrue(count > 0); } dataSource.close(); } }