Search in sources :

Example 6 with User

use of org.jdbi.v3.core.mapper.JoinRowMapperTest.User in project jdbi by jdbi.

the class TestVavrMapCollectorWithDB method uniqueIndex.

/**
 * from {@link org.jdbi.v3.core.mapper.MapEntryMapperTest}
 */
@Test
public void uniqueIndex() {
    Handle h = dbRule.getSharedHandle();
    h.execute("create table user (id int, name varchar)");
    h.prepareBatch("insert into user (id, name) values (?, ?)").add(1, "alice").add(2, "bob").add(3, "cathy").add(4, "dilbert").execute();
    Map<Integer, User> map = h.createQuery("select * from user").setMapKeyColumn("id").registerRowMapper(ConstructorMapper.factory(User.class)).collectInto(new GenericType<Map<Integer, User>>() {
    });
    assertThat(map).containsOnly(Tuple.of(1, new User(1, "alice")), Tuple.of(2, new User(2, "bob")), Tuple.of(3, new User(3, "cathy")), Tuple.of(4, new User(4, "dilbert")));
}
Also used : HashMap(io.vavr.collection.HashMap) Map(io.vavr.collection.Map) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Handle (org.jdbi.v3.core.Handle)3 Jdbi (org.jdbi.v3.core.Jdbi)2 HashMap (io.vavr.collection.HashMap)1 Map (io.vavr.collection.Map)1 Multimap (io.vavr.collection.Multimap)1 JoinRowMapperTest (org.jdbi.v3.core.mapper.JoinRowMapperTest)1 Article (org.jdbi.v3.core.mapper.JoinRowMapperTest.Article)1 User (org.jdbi.v3.core.mapper.JoinRowMapperTest.User)1 PreparedBatch (org.jdbi.v3.core.statement.PreparedBatch)1 SqlObjectPlugin (org.jdbi.v3.sqlobject.SqlObjectPlugin)1