@Test public void testFieldsPrefixBinding() { Handle h = dbRule.openHandle(); assertThat(h .createUpdate("insert into something (id, name) values (:my.id, :my.name)") .bindFields("my", 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")); }
@Test public void testFieldsBinding() { 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")); }
@Test public void testFieldsNestedBinding() { Handle h = dbRule.openHandle(); assertThat(h .createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)") .bindFields("my", new Object() { @SuppressWarnings("unused") public PublicFields nested = 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")); }
@Test public void bindFieldsQualified() { dbRule.getJdbi() .registerArgument(new ReversedStringArgumentFactory()) .useHandle(handle -> { handle.createUpdate("INSERT INTO something (id, name) VALUES (:id, :name)") .bindFields(new QualifiedFieldThing(1, "abc")) .execute(); assertThat(handle.select("SELECT name FROM something") .mapTo(String.class) .findOnly()) .isEqualTo("cba"); }); }