use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestClasspathSqlLocator method testCommentsInExternalSql.
@Test
public void testCommentsInExternalSql() throws Exception {
Handle h = dbRule.openHandle();
h.execute(findSqlOnClasspath("insert-eric-with-comments"));
assertThat(h.select("select name from something").mapTo(String.class).list()).hasSize(1);
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestEnums method testMapToEnum.
@Test
public void testMapToEnum() throws Exception {
Handle h = dbRule.openHandle();
h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
List<SomethingElse.Name> results = h.createQuery("select name from something order by id").mapTo(SomethingElse.Name.class).list();
assertThat(results).containsExactly(SomethingElse.Name.eric, SomethingElse.Name.brian);
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class BeanMapperTest method testNestedPrefix.
@Test
public void testNestedPrefix() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.createQuery("select id nested_id, name nested_name from something").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class BeanMapperTest method testNested.
@Test
public void testNested() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(NestedBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.createQuery("select id, name from something").mapTo(NestedBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class BeanMapperTest method testColumnNameAnnotation.
@Test
public void testColumnNameAnnotation() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(ColumnNameBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
ColumnNameBean bean = handle.createQuery("select * from something").mapTo(ColumnNameBean.class).findOnly();
assertThat(bean.getI()).isEqualTo(1);
assertThat(bean.getS()).isEqualTo("foo");
}
Aggregations