use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class FieldMapperTest method testColumnNameAnnotation.
@Test
public void testColumnNameAnnotation() {
Handle handle = dbRule.getSharedHandle();
handle.execute("insert into something (id, name) values (1, 'foo')");
ColumnNameThing thing = handle.createQuery("select * from something").map(FieldMapper.of(ColumnNameThing.class)).findOnly();
assertThat(thing.i).isEqualTo(1);
assertThat(thing.s).isEqualTo("foo");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class FieldMapperTest method testNested.
@Test
public void testNested() {
Handle handle = dbRule.getSharedHandle();
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.registerRowMapper(FieldMapper.factory(NestedThing.class)).select("SELECT id, name FROM something").mapTo(NestedThing.class).findOnly()).extracting("nested.i", "nested.s").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestReducing method setUp.
@Before
public void setUp() {
Handle h = dbRule.getSharedHandle();
h.execute("CREATE TABLE something_location (id int, location varchar)");
h.execute("INSERT INTO something (id, name) VALUES (1, 'tree')");
h.execute("INSERT INTO something (id, name) VALUES (2, 'apple')");
h.execute("INSERT INTO something_location (id, location) VALUES (1, 'outside')");
h.execute("INSERT INTO something_location (id, location) VALUES (2, 'tree')");
h.execute("INSERT INTO something_location (id, location) VALUES (2, 'pie')");
h.registerRowMapper(new SomethingMapper());
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestResultBearing method setUp.
@Before
public void setUp() throws Exception {
Handle h = dbRule.getSharedHandle();
h.execute("CREATE TABLE reduce (u INT)");
for (int u = 0; u < 5; u++) {
h.execute("INSERT INTO reduce VALUES (?)", u);
}
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestBindList method testBindListWithHashPrefixParser.
@Test
public void testBindListWithHashPrefixParser() throws Exception {
Jdbi jdbi = Jdbi.create(dbRule.getConnectionFactory());
jdbi.setSqlParser(new HashPrefixSqlParser());
jdbi.useHandle(handle -> {
handle.registerRowMapper(FieldMapper.factory(Thing.class));
handle.createUpdate("insert into thing (<columns>) values (<values>)").defineList("columns", "id", "foo").bindList("values", 3, "abc").execute();
List<Thing> list = handle.createQuery("select id, foo from thing where id in (<ids>)").bindList("ids", 1, 3).mapTo(Thing.class).list();
assertThat(list).extracting(Thing::getId, Thing::getFoo, Thing::getBar, Thing::getBaz).containsExactly(tuple(1, "foo1", null, null), tuple(3, "abc", null, null));
});
}
Aggregations