Search in sources :

Example 81 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project hibernate-orm by hibernate.

the class DataSourceUtils method createBasicDataSource.

private void createBasicDataSource() {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(jdbcDriver);
    bds.setUrl(jdbcUrl);
    bds.setUsername(jdbcUser);
    bds.setPassword(jdbcPass);
    dataSource = bds;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 82 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project sonarqube by SonarSource.

the class H2Database method startDatabase.

private void startDatabase() {
    try {
        datasource = new BasicDataSource();
        datasource.setDriverClassName("org.h2.Driver");
        datasource.setUsername("sonar");
        datasource.setPassword("sonar");
        datasource.setUrl("jdbc:h2:mem:" + name);
    } catch (Exception e) {
        throw new IllegalStateException("Fail to start H2", e);
    }
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) SQLException(java.sql.SQLException)

Example 83 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gerrit by GerritCodeReview.

the class JdbcAccountPatchReviewStore method createDataSource.

protected static DataSource createDataSource(String url) {
    BasicDataSource datasource = new BasicDataSource();
    if (url.contains("postgresql")) {
        datasource.setDriverClassName("org.postgresql.Driver");
    } else if (url.contains("h2")) {
        datasource.setDriverClassName("org.h2.Driver");
    } else if (url.contains("mysql")) {
        datasource.setDriverClassName("com.mysql.jdbc.Driver");
    } else if (url.contains("mariadb")) {
        datasource.setDriverClassName("org.mariadb.jdbc.Driver");
    }
    datasource.setUrl(url);
    datasource.setMaxActive(50);
    datasource.setMinIdle(4);
    datasource.setMaxIdle(16);
    long evictIdleTimeMs = 1000 * 60;
    datasource.setMinEvictableIdleTimeMillis(evictIdleTimeMs);
    datasource.setTimeBetweenEvictionRunsMillis(evictIdleTimeMs / 2);
    return datasource;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 84 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gerrit by GerritCodeReview.

the class DataSourceProvider method open.

private DataSource open(final Config cfg, final Context context, final DataSourceType dst) {
    ConfigSection dbs = new ConfigSection(cfg, "database");
    String driver = dbs.optional("driver");
    if (Strings.isNullOrEmpty(driver)) {
        driver = dst.getDriver();
    }
    String url = dbs.optional("url");
    if (Strings.isNullOrEmpty(url)) {
        url = dst.getUrl();
    }
    String username = dbs.optional("username");
    String password = dbs.optional("password");
    String interceptor = dbs.optional("dataSourceInterceptorClass");
    boolean usePool;
    if (context == Context.SINGLE_USER) {
        usePool = false;
    } else {
        usePool = cfg.getBoolean("database", "connectionpool", dst.usePool());
    }
    if (usePool) {
        final BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        if (username != null && !username.isEmpty()) {
            ds.setUsername(username);
        }
        if (password != null && !password.isEmpty()) {
            ds.setPassword(password);
        }
        int poolLimit = threadSettingsConfig.getDatabasePoolLimit();
        ds.setMaxActive(poolLimit);
        ds.setMinIdle(cfg.getInt("database", "poolminidle", 4));
        ds.setMaxIdle(cfg.getInt("database", "poolmaxidle", Math.min(poolLimit, 16)));
        ds.setMaxWait(ConfigUtil.getTimeUnit(cfg, "database", null, "poolmaxwait", MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
        ds.setInitialSize(ds.getMinIdle());
        ds.setValidationQuery(dst.getValidationQuery());
        ds.setValidationQueryTimeout(5);
        exportPoolMetrics(ds);
        return intercept(interceptor, ds);
    }
    //
    try {
        final Properties p = new Properties();
        p.setProperty("driver", driver);
        p.setProperty("url", url);
        if (username != null) {
            p.setProperty("user", username);
        }
        if (password != null) {
            p.setProperty("password", password);
        }
        return intercept(interceptor, new SimpleDataSource(p));
    } catch (SQLException se) {
        throw new ProvisionException("Database unavailable", se);
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) SQLException(java.sql.SQLException) SimpleDataSource(com.google.gwtorm.jdbc.SimpleDataSource) ConfigSection(com.google.gerrit.server.config.ConfigSection) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 85 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project rhino by PLOS.

the class TestConfiguration method dataSource.

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    return dataSource;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) LocalSessionFactoryBean(org.springframework.orm.hibernate3.LocalSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

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