Search in sources :

Example 66 with BasicDataSource

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;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) SQLException(java.sql.SQLException)

Example 67 with BasicDataSource

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();
    }
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 68 with BasicDataSource

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("--------------------------------------------");
    }
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 69 with BasicDataSource

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();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 70 with BasicDataSource

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;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

BasicDataSource (org.apache.commons.dbcp.BasicDataSource)141 Connection (java.sql.Connection)25 Test (org.junit.Test)13 SQLException (java.sql.SQLException)12 Properties (java.util.Properties)12 DataSource (javax.sql.DataSource)10 Platform (org.apache.ddlutils.Platform)8 Database (org.apache.ddlutils.model.Database)8 DdlGenerator (siena.jdbc.ddl.DdlGenerator)8 Statement (java.sql.Statement)7 Bean (org.springframework.context.annotation.Bean)6 ResultSet (java.sql.ResultSet)5 Before (org.junit.Before)5 JdbcPersistenceManager (siena.jdbc.JdbcPersistenceManager)5 Config (com.typesafe.config.Config)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3