Search in sources :

Example 1 with Multimap

use of io.vavr.collection.Multimap in project jdbi by jdbi.

the class TestVavrMapCollectorWithDB method testNonUniqueIndex_withMultimap.

@Test
public void testNonUniqueIndex_withMultimap() {
    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, "alice").execute();
    Multimap<String, User> usersByName = h.createQuery("select * from user").setMapKeyColumn("name").registerRowMapper(ConstructorMapper.factory(User.class)).collectInto(new GenericType<Multimap<String, User>>() {
    });
    assertThat(usersByName.apply("alice")).hasSize(2).containsExactly(new User(1, "alice"), new User(3, "alice"));
    assertThat(usersByName.apply("bob")).hasSize(1).containsExactly(new User(2, "bob"));
}
Also used : Multimap(io.vavr.collection.Multimap) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Multimap (io.vavr.collection.Multimap)1 Handle (org.jdbi.v3.core.Handle)1 Test (org.junit.Test)1