Search in sources :

Example 16 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple1UsingRegisteredRowMapper_shouldSucceed.

@Test
public void testMapTuple1UsingRegisteredRowMapper_shouldSucceed() throws SQLException {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(new SomethingMapper());
    Tuple1<Something> result = handle.createQuery("select id, name from something where id = 1").mapTo(new GenericType<Tuple1<Something>>() {
    }).findOnly();
    assertThat(result._1).isEqualTo(new Something(1, "eric"));
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) GenericType(org.jdbi.v3.core.generic.GenericType) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 17 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestConditionalStringTemplateLocator method setUp.

@Before
public void setUp() throws Exception {
    Handle handle = dbRule.getSharedHandle();
    handle.execute("insert into something (id, name) values (1, 'Martin')");
    handle.execute("insert into something (id, name) values (3, 'David')");
    handle.execute("insert into something (id, name) values (2, 'Joe')");
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Example 18 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrValueArgumentFactoryWithDB method createTestData.

@Before
public void createTestData() {
    Handle handle = dbRule.openHandle();
    handle.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
    handle.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Example 19 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class JdbiUtil method getHandle.

/**
 * Obtain a Handle instance, either the transactionally bound one if we are in a transaction,
 * or a new one otherwise.
 * @param jdbi the Jdbi instance from which to obtain the handle
 *
 * @return the Handle instance
 */
public static Handle getHandle(Jdbi jdbi) {
    Handle bound = (Handle) TransactionSynchronizationManager.getResource(jdbi);
    if (bound == null) {
        bound = jdbi.open();
        if (TransactionSynchronizationManager.isSynchronizationActive()) {
            TransactionSynchronizationManager.bindResource(jdbi, bound);
            TransactionSynchronizationManager.registerSynchronization(new Adapter(jdbi, bound));
            TRANSACTIONAL_HANDLES.add(bound);
        }
    }
    return bound;
}
Also used : TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Handle(org.jdbi.v3.core.Handle)

Example 20 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestOracleReturning method testReturningDmlNamedParams.

@Test
public void testReturningDmlNamedParams() {
    Handle h = dbRule.getSharedHandle();
    List<Integer> ids = h.createUpdate("insert into something(id, name) values (:id, :name) returning id into :result").bindBean(new Something(17, "Brian")).addCustomizer(returnParameters().register("result", OracleTypes.INTEGER)).execute(returningDml()).mapTo(int.class).list();
    assertThat(ids).containsExactly(17);
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Handle (org.jdbi.v3.core.Handle)134 Test (org.junit.Test)124 Jdbi (org.jdbi.v3.core.Jdbi)36 Something (org.jdbi.v3.core.Something)29 Before (org.junit.Before)21 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 Namespace (net.sourceforge.argparse4j.inf.Namespace)11 Test (org.junit.jupiter.api.Test)11 SQLException (java.sql.SQLException)10 Query (org.jdbi.v3.core.statement.Query)8 Map (java.util.Map)7 Update (org.jdbi.v3.core.statement.Update)7 GenericType (org.jdbi.v3.core.generic.GenericType)6 Rule (org.junit.Rule)5 List (java.util.List)4 BrokenDao (org.jdbi.v3.sqlobject.subpackage.BrokenDao)4 SomethingDao (org.jdbi.v3.sqlobject.subpackage.SomethingDao)4 ArrayList (java.util.ArrayList)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 JdbiPlugin (org.jdbi.v3.core.spi.JdbiPlugin)3