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);
}
}
}
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"));
}
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));
}
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));
}
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;
}
Aggregations