com.landawn.abacus.dataSource.DBCPConnectionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* Copyright (c) 2015, Haiyang Li. All rights reserved.
*/
package com.landawn.abacus.dataSource;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.DRIVER;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.INITIAL_SIZE;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.JNDI_NAME;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.MAX_ACTIVE;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.MAX_IDLE;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.MAX_OPEN_PREPARED_STATEMENTS_PER_CONNECTION;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.MAX_WAIT_TIME;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.MIN_IDLE;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.PASSWORD;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.TEST_ON_BORROW;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.TEST_ON_RETURN;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.URL;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.USER;
import static com.landawn.abacus.dataSource.DataSourceConfiguration.VALIDATION_QUERY;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.sql.DataSource;
import com.landawn.abacus.exception.AbacusException;
import com.landawn.abacus.exception.UncheckedSQLException;
import com.landawn.abacus.logging.Logger;
import com.landawn.abacus.logging.LoggerFactory;
import com.landawn.abacus.util.N;
/**
*
* @since 0.8
*
* @author Haiyang Li
*/
class DBCPConnectionManager extends AbstractConnectionManager {
static final Logger logger = LoggerFactory.getLogger(DBCPConnectionManager.class);
private final DataSource ds;
private final org.apache.commons.dbcp.BasicDataSource bds;
public DBCPConnectionManager(Map props) {
super(props);
if (properties.containsKey(JNDI_NAME)) {
ds = createJNDIDataSource(properties);
bds = null;
} else {
try {
bds = (org.apache.commons.dbcp.BasicDataSource) org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(new Properties());
} catch (Exception e) {
throw N.toRuntimeException(e);
}
bds.setDriverClassName(properties.get(DRIVER));
bds.setUrl(properties.get(URL));
bds.setUsername(properties.get(USER));
bds.setPassword(properties.get(PASSWORD));
bds.setInitialSize(Integer.valueOf(properties.get(INITIAL_SIZE)));
bds.setMinIdle(Integer.valueOf(properties.get(MIN_IDLE)));
bds.setMaxIdle(Integer.valueOf(properties.get(MAX_IDLE)));
bds.setMaxActive(Integer.valueOf(properties.get(MAX_ACTIVE)));
bds.setMaxOpenPreparedStatements(Integer.valueOf(properties.get(MAX_OPEN_PREPARED_STATEMENTS_PER_CONNECTION)));
bds.setMaxWait(Long.valueOf(properties.get(MAX_WAIT_TIME)));
bds.setTestOnBorrow(Boolean.valueOf(properties.get(TEST_ON_BORROW)));
bds.setTestOnReturn(Boolean.valueOf(properties.get(TEST_ON_RETURN)));
bds.setValidationQuery(properties.get(VALIDATION_QUERY));
String st = "";
Set