use of org.jdbi.v3.sqlobject.SqlObject in project jdbi by jdbi.
the class IntroductionTest method sqlObject.
// end::sqlobject-declaration[]
@Test
public void sqlObject() {
// tag::sqlobject-usage[]
Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test");
jdbi.installPlugin(new SqlObjectPlugin());
// Jdbi implements your interface based on annotations
List<User> userNames = jdbi.withExtension(UserDao.class, dao -> {
dao.createTable();
dao.insertPositional(0, "Alice");
dao.insertPositional(1, "Bob");
dao.insertNamed(2, "Clarice");
dao.insertBean(new User(3, "David"));
return dao.listUsers();
});
assertThat(userNames).containsExactly(new User(0, "Alice"), new User(1, "Bob"), new User(2, "Clarice"), new User(3, "David"));
// end::sqlobject-usage[]
}
Aggregations