Search in sources :

Example 86 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gocd by gocd.

the class DatabaseFixture method update.

public static int update(String query, H2Database h2Database) {
    BasicDataSource source = h2Database.createDataSource();
    Connection con = null;
    Statement stmt = null;
    try {
        con = source.getConnection();
        stmt = con.createStatement();
        return stmt.executeUpdate(query);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            assert stmt != null;
            stmt.close();
            con.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 87 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gocd by gocd.

the class H2DatabaseTest method shouldUseMVCCWhenRunning.

@Test
public void shouldUseMVCCWhenRunning() throws Exception {
    h2Database.startDatabase();
    h2Database.upgrade();
    BasicDataSource dataSource = h2Database.createDataSource();
    assertThat(dataSource.getUrl(), containsString("MVCC=TRUE"));
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Test(org.junit.Test)

Example 88 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gocd by gocd.

the class H2DatabaseTest method shouldUpgradeDatabase.

@Test
public void shouldUpgradeDatabase() throws SQLException {
    h2Database.shutdown();
    h2Database.startDatabase();
    BasicDataSource dataSource = h2Database.createDataSource();
    h2Database.upgrade();
    h2Database.startDatabase();
    dataSource = h2Database.createDataSource();
    Connection connection = dataSource.getConnection();
    ResultSet set = connection.getMetaData().getTables(null, null, null, null);
    assertThat(set.next(), is(true));
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Test(org.junit.Test)

Example 89 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gocd by gocd.

the class H2DatabaseTest method shouldUseParamterizedActiveAndIdleConnections.

@Test
public void shouldUseParamterizedActiveAndIdleConnections() throws Exception {
    BasicDataSource dataSource = h2Database.createDataSource();
    assertThat(dataSource.getMaxActive(), is(20));
    assertThat(dataSource.getMaxIdle(), is(10));
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Test(org.junit.Test)

Example 90 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project gocd by gocd.

the class H2Database method createDataSource.

private BasicDataSource createDataSource(Boolean mvccEnabled) {
    if (this.dataSource == null) {
        BasicDataSource source = new BasicDataSource();
        if (systemEnvironment.inDbDebugMode()) {
            String url = String.format("jdbc:h2:tcp://%s:%s/%s", configuration.getHost(), configuration.getPort(), configuration.getName());
            configureDataSource(source, url);
            LOG.info("Creating debug data source on port={}", configuration.getPort());
        } else {
            String url = dburl(mvccEnabled);
            configureDataSource(source, url);
            LOG.info("Creating data source with url={}", url);
        }
        this.dataSource = source;
    }
    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