Search in sources :

Example 1 with SqlObject

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[]
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SqlObjectPlugin(org.jdbi.v3.sqlobject.SqlObjectPlugin) Test(org.junit.Test)

Aggregations

Jdbi (org.jdbi.v3.core.Jdbi)1 SqlObjectPlugin (org.jdbi.v3.sqlobject.SqlObjectPlugin)1 Test (org.junit.Test)1