List of usage examples for org.apache.commons.dbcp AbandonedObjectPool setFactory
public void setFactory(PoolableObjectFactory factory) throws IllegalStateException
From source file:com.haulmont.yarg.loaders.factory.DefaultLoaderFactory.java
public static DataSource setupDataSource(String driver, String connectURI, String username, String password, Integer maxActive, Integer maxIdle, Integer maxWait) { try {// w w w . j a v a2s .c om Class.forName(driver); final AbandonedConfig config = new AbandonedConfig(); config.setLogAbandoned(true); AbandonedObjectPool connectionPool = new AbandonedObjectPool(null, config); connectionPool.setMaxIdle(maxIdle); connectionPool.setMaxActive(maxActive); if (maxWait != null) { connectionPool.setMaxWait(maxWait); } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); connectionPool.setFactory(poolableConnectionFactory); PoolingDataSource dataSource = new PoolingDataSource(connectionPool); return dataSource; } catch (ClassNotFoundException e) { throw new InitializationException("An error occurred during creation of new datasource object", e); } }
From source file:com.haulmont.yarg.console.PropertiesSqlLoaderFactory.java
protected DataSource setupDataSource(String driver, String connectURI, String username, String password, Integer maxActive, Integer maxIdle, Integer maxWait) { try {// ww w . j a v a2 s.c o m Class.forName(driver); final AbandonedConfig config = new AbandonedConfig(); config.setLogAbandoned(true); AbandonedObjectPool connectionPool = new AbandonedObjectPool(null, config); connectionPool.setMaxIdle(maxIdle); connectionPool.setMaxActive(maxActive); if (maxWait != null) { connectionPool.setMaxWait(maxWait); } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); connectionPool.setFactory(poolableConnectionFactory); return new PoolingDataSource(connectionPool); } catch (ClassNotFoundException e) { throw new InitializationException("An error occurred during creation of new datasource object", e); } }