use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestSqlObject method testSqlUpdateWithTransaction.
@Test
public void testSqlUpdateWithTransaction() {
Handle handle = Mockito.spy(dbRule.getSharedHandle());
Dao dao = handle.attach(Dao.class);
dao.insert(1, "foo");
verify(handle, never()).begin();
assertThat(dao.findById(1)).isEqualTo(new Something(1, "foo"));
assertThat(dao.insertTransactional(2, "bar")).isEqualTo(1);
verify(handle, times(1)).begin();
assertThat(dao.findById(2)).isEqualTo(new Something(2, "bar"));
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestSqlObject method testNestedTransactionWithSameIsolation.
@Test
public void testNestedTransactionWithSameIsolation() {
Handle handle = Mockito.spy(dbRule.getSharedHandle());
Dao dao = handle.attach(Dao.class);
dao.nestedTransactionWithSameIsolation();
verify(handle, times(1)).begin();
verify(handle, times(1)).commit();
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestUseCustomHandlerFactory method setUp.
@Before
public void setUp() throws Exception {
Jdbi db = dbRule.getJdbi();
HandlerFactory defaultHandlerFactory = new HandlerFactory() {
@Override
public Optional<Handler> buildHandler(Class<?> sqlObjectType, Method method) {
return getImplementation(sqlObjectType, method).map(m -> (Handler) (target, args, handle) -> m.invoke(null, Stream.concat(Stream.of(target), Stream.of(args)).toArray()));
}
private Optional<Method> getImplementation(Class<?> type, Method method) {
return Stream.of(type.getClasses()).filter(c -> c.getSimpleName().equals("DefaultImpls")).flatMap(c -> Stream.of(c.getMethods()).filter(m -> m.getName().equals(method.getName()))).findAny();
}
};
db.configure(Handlers.class, c -> c.register(defaultHandlerFactory));
handle = db.open();
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestUseSqlParser method setUp.
@Before
public void setUp() throws Exception {
Jdbi db = dbRule.getJdbi();
// this is the default, but be explicit for sake of clarity in test
db.setSqlParser(new ColonPrefixSqlParser());
handle = db.open();
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestVavrMapCollectorWithDB method testSingleInstanceAssignmentWithSelectedKeyValue_shouldSucceed.
@Test
public void testSingleInstanceAssignmentWithSelectedKeyValue_shouldSucceed() {
Handle handle = dbRule.getSharedHandle().configure(MapEntryMappers.class, c -> c.setKeyColumn("key_c").setValueColumn("val_c"));
Optional<Tuple2<String, String>> valueMap = handle.createQuery("select val_c, key_c from keyval").mapTo(new GenericType<Tuple2<String, String>>() {
}).findFirst();
assertThat(valueMap).isNotEmpty();
assertThat(valueMap.get()).isEqualTo(Tuple.of(KEY_PREFIX + 0, VAL_PREFIX + 1));
}
Aggregations