use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testFunctionsNestedBinding.
@Test
public void testFunctionsNestedBinding() throws Exception {
Handle h = dbRule.openHandle();
assertThat(h.createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)").bindMethods("my", new Object() {
@SuppressWarnings("unused")
public NoArgFunctions nested() {
return new NoArgFunctions(0, "Keith");
}
}).execute()).isEqualTo(1);
assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testFunctionsPrefixBinding.
@Test
public void testFunctionsPrefixBinding() throws Exception {
Handle h = dbRule.openHandle();
assertThat(h.createUpdate("insert into something (id, name) values (:my.id, :my.name)").bindMethods("my", new NoArgFunctions(0, "Keith")).execute()).isEqualTo(1);
assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testDemo.
@Test
public void testDemo() throws Exception {
Handle h = dbRule.getSharedHandle();
h.createUpdate("insert into something (id, name) values (:id, :name)").bind("id", 1).bind("name", "Brian").execute();
h.execute("insert into something (id, name) values (?, ?)", 2, "Eric");
h.execute("insert into something (id, name) values (?, ?)", 3, "Erin");
List<Something> r = h.createQuery("select id, name from something " + "where name like :name " + "order by id").bind("name", "Eri%").mapToBean(Something.class).list();
assertThat(r).extracting(Something::getId).containsExactly(2, 3);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testMapKeyBinding.
@Test
public void testMapKeyBinding() 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);
args.put("name", "Keith");
s.bindMap(args);
int insert_count = s.execute();
Query q = h.createQuery("select * from something where id = :id").bind("id", 0);
final Something fromDb = q.mapToBean(Something.class).findOnly();
assertThat(insert_count).isEqualTo(1);
assertThat(fromDb).extracting(Something::getId, Something::getName).containsExactly(0, "Keith");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestNamedParams method testFieldsBinding.
@Test
public void testFieldsBinding() throws Exception {
Handle h = dbRule.openHandle();
assertThat(h.createUpdate("insert into something (id, name) values (:id, :name)").bindFields(new PublicFields(0, "Keith")).execute()).isEqualTo(1);
assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
Aggregations