use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class BeanMapperTest method testNestedPrefixStrict.
@Test
public void testNestedPrefixStrict() {
Handle handle = dbRule.getSharedHandle();
handle.getConfig(ReflectionMappers.class).setStrictMatching(true);
handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class));
// three, sir!
handle.execute("insert into something (id, name, integerValue) values (1, 'foo', 5)");
assertThat(handle.createQuery("select id nested_id, name nested_name, integerValue from something").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.id", "nested.name", "integerValue").containsExactly(1, "foo", 5);
assertThatThrownBy(() -> handle.createQuery("select id nested_id, name nested_name, 1 as other from something").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match properties for columns: [other]");
assertThatThrownBy(() -> handle.createQuery("select id nested_id, name nested_name, 1 as nested_other from something").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match properties for columns: [nested_other]");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class BeanMapperTest method testNestedStrict.
@Test
public void testNestedStrict() {
Handle handle = dbRule.getSharedHandle();
handle.getConfig(ReflectionMappers.class).setStrictMatching(true);
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");
assertThatThrownBy(() -> handle.createQuery("select id, name, 1 as other from something").mapTo(NestedBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match properties for columns: [other]");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class ConstructorMapperTest method nestedPrefixParametersStrict.
@Test
public void nestedPrefixParametersStrict() {
Handle handle = dbRule.getSharedHandle();
handle.getConfig(ReflectionMappers.class).setStrictMatching(true);
handle.registerRowMapper(ConstructorMapper.factory(NestedPrefixBean.class));
assertThat(handle.createQuery("select i nested_i, s nested_s from bean").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.s", "nested.i").containsExactly("3", 2);
assertThatThrownBy(() -> handle.createQuery("select i nested_i, s nested_s, 1 as other from bean").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match parameters for columns: [other]");
assertThatThrownBy(() -> handle.createQuery("select i nested_i, s nested_s, 1 as nested_other from bean").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match parameters for columns: [nested_other]");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestUpdateGeneratedKeys method testUpdate.
@Test
public void testUpdate() throws Exception {
Handle h = dbRule.openHandle();
Update insert = h.createUpdate("insert into something_else (name) values (:name)");
insert.bind("name", "Brian");
Long id1 = insert.executeAndReturnGeneratedKeys().mapTo(long.class).findOnly();
assertThat(id1).isNotNull();
Update update = h.createUpdate("update something_else set name = :name where id = :id");
update.bind("id", id1);
update.bind("name", "Tom");
Optional<Long> id2 = update.executeAndReturnGeneratedKeys().mapTo(long.class).findFirst();
assertThat(id2.isPresent()).isFalse();
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestUpdateGeneratedKeys method testDelete.
@Test
public void testDelete() throws Exception {
Handle h = dbRule.openHandle();
Update insert = h.createUpdate("insert into something_else (name) values (:name)");
insert.bind("name", "Brian");
Long id1 = insert.executeAndReturnGeneratedKeys().mapTo(long.class).findOnly();
assertThat(id1).isNotNull();
Update delete = h.createUpdate("delete from something_else where id = :id");
delete.bind("id", id1);
Optional<Long> id2 = delete.executeAndReturnGeneratedKeys().mapTo(long.class).findFirst();
assertThat(id2.isPresent()).isFalse();
}
Aggregations