Search in sources :

Example 11 with JdbcDataSource

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

Example 12 with JdbcDataSource

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);
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JdbcDataSource (org.h2.jdbcx.JdbcDataSource)12 Connection (java.sql.Connection)3 BeforeClass (org.junit.BeforeClass)2 NamingMixIn (org.switchyard.component.test.mixins.naming.NamingMixIn)2 File (java.io.File)1 StringReader (java.io.StringReader)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 InitialContext (javax.naming.InitialContext)1 BasicManagedDataSource (org.apache.commons.dbcp.managed.BasicManagedDataSource)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 DatasourceConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl)1 JtaTransactionCoordinatorBuilderImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl)1 Nullable (org.jetbrains.annotations.Nullable)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Block (ratpack.func.Block)1 ExecHarness (ratpack.test.exec.ExecHarness)1