use of org.apache.commons.dbcp.BasicDataSource in project wechat by dllwh.
the class DataTableHelper method getDataSource.
/**
* @方法描述: 获取数据源并加载相关配置
* @return
*/
private synchronized DataSource getDataSource() {
if (null == dataSource) {
try {
BasicDataSource dbcpDataSource = new BasicDataSource();
dbcpDataSource.setUrl(dbUrl);
dbcpDataSource.setDriverClassName(jdbcName);
dbcpDataSource.setUsername(dbUserName);
dbcpDataSource.setPassword(dbPassword);
dbcpDataSource.setDefaultAutoCommit(true);
dbcpDataSource.setMaxActive(100);
dbcpDataSource.setMaxIdle(30);
dbcpDataSource.setMaxWait(500L);
dataSource = dbcpDataSource;
} catch (Exception ex) {
logger.info("dbcp数据源初始化失败:" + ex.getMessage(), ex);
}
}
return dataSource;
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class DBCPTest method test_dbcp.
public void test_dbcp() throws Exception {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(MockDriver.class.getName());
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setMaxOpenPreparedStatements(100);
dataSource.setPoolPreparedStatements(true);
final String sql = "selelct 1";
{
Connection conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall(sql);
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall(sql);
stmt.close();
conn.close();
}
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class TestPSCache method f_test_dbcp.
public void f_test_dbcp() throws Exception {
BasicDataSource ds = new BasicDataSource();
ds.setUrl("jdbc:mock:test");
ds.setMaxIdle(10);
ds.setPoolPreparedStatements(true);
ds.setMaxOpenPreparedStatements(10);
for (int i = 0; i < 10; ++i) {
f(ds, 5);
System.out.println("--------------------------------------------");
}
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class Test0 method test_idle.
public void test_idle() throws Exception {
MockDriver driver = MockDriver.instance;
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
dataSource.setInitialSize(0);
dataSource.setMaxActive(4);
dataSource.setMaxIdle(4);
dataSource.setMinIdle(1);
dataSource.setMinEvictableIdleTimeMillis(5000 * 1);
dataSource.setTimeBetweenEvictionRunsMillis(10);
dataSource.setTestWhileIdle(false);
dataSource.setTestOnBorrow(false);
dataSource.setValidationQuery("SELECT 1");
{
Connection conn = dataSource.getConnection();
// Assert.assertEquals(dataSource.getInitialSize(), driver.getConnections().size());
System.out.println("raw size : " + driver.getConnections().size());
conn.close();
System.out.println("raw size : " + driver.getConnections().size());
}
{
Connection conn = dataSource.getConnection();
// Assert.assertEquals(dataSource.getInitialSize(), driver.getConnections().size());
System.out.println("raw size : " + driver.getConnections().size());
conn.close();
System.out.println("raw size : " + driver.getConnections().size());
}
dataSource.close();
}
use of org.apache.commons.dbcp.BasicDataSource in project gerrit by GerritCodeReview.
the class JdbcAccountPatchReviewStore method createDataSource.
private static DataSource createDataSource(Config cfg, SitePaths sitePaths, ThreadSettingsConfig threadSettingsConfig) {
BasicDataSource datasource = new BasicDataSource();
String url = getUrl(cfg, sitePaths);
int poolLimit = threadSettingsConfig.getDatabasePoolLimit();
datasource.setUrl(url);
datasource.setDriverClassName(getDriverFromUrl(url));
datasource.setMaxActive(cfg.getInt(ACCOUNT_PATCH_REVIEW_DB, "poolLimit", poolLimit));
datasource.setMinIdle(cfg.getInt(ACCOUNT_PATCH_REVIEW_DB, "poolminidle", 4));
datasource.setMaxIdle(cfg.getInt(ACCOUNT_PATCH_REVIEW_DB, "poolmaxidle", Math.min(poolLimit, 16)));
datasource.setInitialSize(datasource.getMinIdle());
datasource.setMaxWait(ConfigUtil.getTimeUnit(cfg, ACCOUNT_PATCH_REVIEW_DB, null, "poolmaxwait", MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
long evictIdleTimeMs = 1000L * 60;
datasource.setMinEvictableIdleTimeMillis(evictIdleTimeMs);
datasource.setTimeBetweenEvictionRunsMillis(evictIdleTimeMs / 2);
return datasource;
}
Aggregations