use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestClasspathSqlLocator method testUsefulExceptionForBackTracing.
@Test
public void testUsefulExceptionForBackTracing() throws Exception {
Handle h = dbRule.openHandle();
exception.expect(StatementException.class);
exception.expectMessage("insert into something(id, name) values (:id, :name)");
exception.expectMessage("insert into something(id, name) values (?, ?)");
h.createUpdate(findSqlOnClasspath("insert-id-name")).bind("id", 1).execute();
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestClasspathSqlLocator method testNamedParamsInExternal.
@Test
public void testNamedParamsInExternal() throws Exception {
Handle h = dbRule.openHandle();
h.createUpdate(findSqlOnClasspath("insert-id-name")).bind("id", 1).bind("name", "Tip").execute();
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 TestClasspathSqlLocator method testLocateNamed.
@Test
public void testLocateNamed() throws Exception {
Handle h = dbRule.openHandle();
h.execute(findSqlOnClasspath("insert-keith"));
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 MapOptionalTest method testMapOptional.
@Test
public void testMapOptional() throws Exception {
final Handle h = db.getSharedHandle();
h.execute("insert into something(intValue, name) values(1, 'Duke')");
h.execute("insert into something(intValue, name) values(null, null)");
assertThat(h.createQuery("select * from something order by id").map(ConstructorMapper.of(OptionalBean.class)).list()).extracting("intValue", "name").containsExactly(tuple(OptionalInt.of(1), Optional.of("Duke")), tuple(OptionalInt.empty(), Optional.empty()));
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestEnums method testMapInvalidEnumValue.
@Test(expected = IllegalArgumentException.class)
public void testMapInvalidEnumValue() throws SQLException {
Handle h = dbRule.openHandle();
h.createUpdate("insert into something (id, name) values (1, 'joe')").execute();
h.createQuery("select * from something order by id").mapToBean(SomethingElse.class).findFirst();
}
Aggregations