use of org.h2.jdbcx.JdbcDataSource in project ratpack by ratpack.
the class Example method main.
public static void main(String[] args) throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:transactionExamples;DB_CLOSE_DELAY=-1");
txDs = Transaction.dataSource(ds);
tx = Transaction.create(ds::getConnection);
try (Connection connection = txDs.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE tbl (value VARCHAR(50)) ");
}
}
List<Block> examples = Arrays.asList(Example::singleTransactionExample, Example::singleTransactionRollbackExample, Example::nestedTransactionExample, Example::nestedTransactionRollbackExample, () -> manualTransactionExample(true), () -> manualTransactionExample(false));
try (ExecHarness harness = ExecHarness.harness()) {
for (Block example : examples) {
harness.execute(Operation.of(example));
reset();
}
}
}
use of org.h2.jdbcx.JdbcDataSource in project logging-log4j2 by apache.
the class LoggerPrintWriterJdbcH2Test method testDataSource_setLogWriter.
@Test
@Ignore("DataSource#setLogWriter() has no effect in H2, it uses its own internal logging and an SLF4J bridge.")
public void testDataSource_setLogWriter() throws SQLException {
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setUrl(H2_URL);
dataSource.setUser(USER_ID);
dataSource.setPassword(PASSWORD);
dataSource.setLogWriter(createLoggerPrintWriter());
// dataSource.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
try (final Connection conn = dataSource.getConnection()) {
conn.prepareCall("select 1");
}
Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
}
Aggregations