use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testCascadedLazyArgs.
@Test
public void testCascadedLazyArgs() throws Exception {
Handle h = dbRule.openHandle();
Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
Map<String, Object> args = new HashMap<>();
args.put("id", 0);
s.bindMap(args);
s.bindBean(new Object() {
@SuppressWarnings("unused")
public String getName() {
return "Keith";
}
});
int insert_count = s.execute();
assertThat(insert_count).isEqualTo(1);
Something something = h.createQuery("select id, name from something").mapToBean(Something.class).findOnly();
assertThat(something).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestArgumentFactory method testRegisterOnJdbi.
@Test
public void testRegisterOnJdbi() throws Exception {
final Jdbi db = dbRule.getJdbi();
db.registerArgument(new NameAF());
try (Handle h = db.open()) {
h.createUpdate("insert into something (id, name) values (:id, :name)").bind("id", 7).bind("name", new Name("Brian", "McCallister")).execute();
String full_name = h.createQuery("select name from something where id = 7").mapTo(String.class).findOnly();
assertThat(full_name).isEqualTo("Brian McCallister");
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestArgumentFactory method testRegisterOnHandle.
@Test
public void testRegisterOnHandle() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.registerArgument(new NameAF());
h.createUpdate("insert into something (id, name) values (:id, :name)").bind("id", 7).bind("name", new Name("Brian", "McCallister")).execute();
String full_name = h.createQuery("select name from something where id = 7").mapTo(String.class).findOnly();
assertThat(full_name).isEqualTo("Brian McCallister");
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testBeanPropertyNestedBinding.
@Test
public void testBeanPropertyNestedBinding() throws Exception {
Handle h = dbRule.openHandle();
Something thing = new Something(0, "Keith");
assertThat(h.createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)").bindBean("my", new Object() {
@SuppressWarnings("unused")
public Something getNested() {
return thing;
}
}).execute()).isEqualTo(1);
assertThat(h.select("select * from something where id = ?", thing.getId()).mapToBean(Something.class).findOnly()).isEqualTo(thing);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testInsert.
@Test
public void testInsert() throws Exception {
Handle h = dbRule.openHandle();
Update insert = h.createUpdate("insert into something (id, name) values (:id, :name)");
insert.bind("id", 1);
insert.bind("name", "Brian");
int count = insert.execute();
assertThat(count).isEqualTo(1);
}
Aggregations