Example usage for org.apache.commons.dbcp AbandonedConfig getRemoveAbandoned

List of usage examples for org.apache.commons.dbcp AbandonedConfig getRemoveAbandoned

Introduction

In this page you can find the example usage for org.apache.commons.dbcp AbandonedConfig getRemoveAbandoned.

Prototype

public boolean getRemoveAbandoned() 

Source Link

Document

Flag to remove abandoned connections if they exceed the removeAbandonedTimeout.

Usage

From source file:org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.java

protected ObjectPool createConnectionPool(GenericObjectPool.Config config, AbandonedConfig ac) {
    final GenericObjectPool connectionPool;
    final boolean doRemoveAbandoned = ac != null && ac.getRemoveAbandoned();

    if (doRemoveAbandoned) {
        connectionPool = new AbandonedObjectPool(null, ac);
    } else {/*from www  .j av a 2  s . c  o  m*/
        connectionPool = new GenericObjectPool();
    }
    connectionPool.setMaxActive(config.maxActive);
    connectionPool.setMaxIdle(config.maxIdle);
    connectionPool.setMinIdle(config.minIdle);
    connectionPool.setMaxWait(config.maxWait);
    connectionPool.setTestOnBorrow(config.testOnBorrow);
    connectionPool.setTestOnReturn(config.testOnReturn);
    connectionPool.setTimeBetweenEvictionRunsMillis(config.timeBetweenEvictionRunsMillis);
    connectionPool.setNumTestsPerEvictionRun(config.numTestsPerEvictionRun);
    connectionPool.setMinEvictableIdleTimeMillis(config.minEvictableIdleTimeMillis);
    connectionPool.setTestWhileIdle(config.testWhileIdle);
    return connectionPool;
}

From source file:org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.java

/**
 * Wraps the specified object pool for connections as a DataSource.
 *
 * @param jcd the OJB connection descriptor for the pool to be wrapped
 * @param connectionPool the connection pool to be wrapped
 * @return a DataSource attached to the connection pool.
 * Connections will be wrapped using DBCP PoolGuard, that will not allow
 * unwrapping unless the "accessToUnderlyingConnectionAllowed=true" configuration
 * is specified.//w  w  w.  j  av a2 s  . co m
 */
protected DataSource wrapAsDataSource(JdbcConnectionDescriptor jcd, ObjectPool connectionPool) {
    final boolean allowConnectionUnwrap;
    if (jcd == null) {
        allowConnectionUnwrap = false;
    } else {
        final Properties properties = jcd.getConnectionPoolDescriptor().getDbcpProperties();
        final String allowConnectionUnwrapParam;
        allowConnectionUnwrapParam = properties.getProperty(PARAM_NAME_UNWRAP_ALLOWED);
        allowConnectionUnwrap = allowConnectionUnwrapParam != null
                && Boolean.valueOf(allowConnectionUnwrapParam).booleanValue();
    }
    final PoolingDataSource dataSource;
    dataSource = new PoolingDataSource(connectionPool);
    dataSource.setAccessToUnderlyingConnectionAllowed(allowConnectionUnwrap);

    if (jcd != null) {
        final AbandonedConfig ac = jcd.getConnectionPoolDescriptor().getAbandonedConfig();
        if (ac.getRemoveAbandoned() && ac.getLogAbandoned()) {
            final LoggerWrapperPrintWriter loggerPiggyBack;
            loggerPiggyBack = new LoggerWrapperPrintWriter(log, Logger.ERROR);
            dataSource.setLogWriter(loggerPiggyBack);
        }
    }
    return dataSource;
}