Search in sources :

Example 1 with ExecHarness

use of ratpack.test.exec.ExecHarness 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();
        }
    }
}
Also used : Statement(java.sql.Statement) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) Block(ratpack.func.Block) ExecHarness(ratpack.test.exec.ExecHarness)

Aggregations

Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 Block (ratpack.func.Block)1 ExecHarness (ratpack.test.exec.ExecHarness)1