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