Example usage for org.apache.commons.dbcp2 BasicDataSource isPoolPreparedStatements

List of usage examples for org.apache.commons.dbcp2 BasicDataSource isPoolPreparedStatements

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 BasicDataSource isPoolPreparedStatements.

Prototype

@Override
public synchronized boolean isPoolPreparedStatements() 

Source Link

Document

Returns true if we are pooling statements.

Usage

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static void initConnectionPoolSettings(final BasicDataSource dataSource,
        final ConnectionPoolInfo poolInfo) {
    if (poolInfo == null) {
        return;//w  w  w.j  a  v a 2s. co  m
    }

    dataSource.setMaxTotal(poolInfo.getMaxSize());
    dataSource.setMinIdle(poolInfo.getMinSize());
    dataSource.setMaxIdle(poolInfo.getMaxIdle());
    dataSource.setMaxWaitMillis(poolInfo.getMaxWait());
    dataSource.setDefaultCatalog(poolInfo.getDefaultCatalog());

    if (poolInfo.getInitialSize() != null) {
        dataSource.setInitialSize(poolInfo.getInitialSize());
    }

    if (isNotEmpty(poolInfo.getValidationQuery())) {
        // testOnBorrow defaults to true when this is set, but can still be forced to false
        dataSource.setTestOnBorrow(poolInfo.getTestOnBorrow() == null || poolInfo.getTestOnBorrow());
        if (poolInfo.getTestOnReturn() != null) {
            dataSource.setTestOnReturn(poolInfo.getTestOnReturn());
        }
        if (poolInfo.getTestWhileIdle() != null) {
            dataSource.setTestWhileIdle(poolInfo.getTestWhileIdle());
        }
        dataSource.setValidationQuery(poolInfo.getValidationQuery());
        if (poolInfo.getValidationQueryTimeout() != null) {
            dataSource.setValidationQueryTimeout(poolInfo.getValidationQueryTimeout());
        }
    }

    if (poolInfo.getPoolPreparedStatements() != null) {
        dataSource.setPoolPreparedStatements(poolInfo.getPoolPreparedStatements());
        if (dataSource.isPoolPreparedStatements() && poolInfo.getMaxOpenPreparedStatements() != null) {
            dataSource.setMaxOpenPreparedStatements(poolInfo.getMaxOpenPreparedStatements());
        }
    }

    if (poolInfo.getRemoveAbandonedOnBorrow() != null) {
        dataSource.setRemoveAbandonedOnBorrow(poolInfo.getRemoveAbandonedOnBorrow());
    }

    if (poolInfo.getRemoveAbandonedOnMaintanance() != null) {
        dataSource.setRemoveAbandonedOnMaintenance(poolInfo.getRemoveAbandonedOnMaintanance());
    }

    if (poolInfo.getRemoveAbandonedTimeout() != null) {
        dataSource.setRemoveAbandonedTimeout(poolInfo.getRemoveAbandonedTimeout());
    }

    if (poolInfo.getMinEvictableTimeMillis() != null) {
        dataSource.setMinEvictableIdleTimeMillis(poolInfo.getMinEvictableTimeMillis());
    }

    if (poolInfo.getNumTestsPerEvictionRun() != null) {
        dataSource.setNumTestsPerEvictionRun(poolInfo.getNumTestsPerEvictionRun());
    }

    if (poolInfo.getTimeBetweenEvictionRunsMillis() != null) {
        dataSource.setTimeBetweenEvictionRunsMillis(poolInfo.getTimeBetweenEvictionRunsMillis());
    }

}