本文整理了Java中org.jdbi.v3.core.statement.Query.setMapKeyColumn
方法的一些代码示例,展示了Query.setMapKeyColumn
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setMapKeyColumn
方法的具体详情如下:
包路径:org.jdbi.v3.core.statement.Query
类名称:Query
方法名:setMapKeyColumn
暂无
代码示例来源:origin: jdbi/jdbi
@Test
public void keyValueColumns() {
h.execute("create table config (key varchar, value varchar)");
h.prepareBatch("insert into config (key, value) values (?, ?)")
.add("foo", "123")
.add("bar", "xyz")
.execute();
// tag::keyValue[]
Map<String, String> map = h.createQuery("select key, value from config")
.setMapKeyColumn("key")
.setMapValueColumn("value")
.collectInto(new GenericType<Map<String, String>>() {});
// end::keyValue[]
assertThat(map).containsOnly(
entry("foo", "123"),
entry("bar", "xyz"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testNonUniqueIndexWithMultimap() {
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")
);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void uniqueIndex() {
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();
// tag::uniqueIndex[]
Map<Integer, User> map = h.createQuery("select * from user")
.setMapKeyColumn("id")
.registerRowMapper(ConstructorMapper.factory(User.class))
.collectInto(new GenericType<Map<Integer, User>>() {});
// end::uniqueIndex[]
assertThat(map).containsOnly(
entry(1, new User(1, "alice")),
entry(2, new User(2, "bob")),
entry(3, new User(3, "cathy")),
entry(4, new User(4, "dilbert")));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void keyValueColumns() {
h.execute("create table config (key varchar, value varchar)");
h.prepareBatch("insert into config (key, value) values (?, ?)")
.add("foo", "123")
.add("foo", "456")
.add("bar", "xyz")
.execute();
// tag::keyValue[]
Multimap<String, String> map = h.createQuery("select key, value from config")
.setMapKeyColumn("key")
.setMapValueColumn("value")
.collectInto(new GenericType<Multimap<String, String>>() {});
// end::keyValue[]
Multimap<String, String> expected = ImmutableListMultimap.<String, String>builder()
.putAll("foo", "123", "456")
.put("bar", "xyz")
.build();
assertThat(map).isEqualTo(expected);
}
代码示例来源:origin: jdbi/jdbi
/**
* 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")));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void index() {
h.execute("create table user (id int, manager_id int, name varchar)");
h.prepareBatch("insert into user (id, manager_id, name) values (?, ?, ?)")
.add(1, 0, "alice")
.add(2, 1, "bob")
.add(3, 1, "cathy")
.add(4, 3, "dilbert")
.execute();
// tag::index[]
Multimap<Integer, User> map = h.createQuery("select id, manager_id, name from user")
.setMapKeyColumn("manager_id")
.registerRowMapper(ConstructorMapper.factory(User.class))
.collectInto(new GenericType<Multimap<Integer, User>>() {});
// end::index[]
Multimap<Integer, User> expected = ImmutableListMultimap.<Integer, User>builder()
.put(0, new User(1, "alice"))
.putAll(1, new User(2, "bob"), new User(3, "cathy"))
.put(3, new User(4, "dilbert"))
.build();
assertThat(map).isEqualTo(expected);
}
代码示例来源:origin: jdbi/jdbi
.useHandle(handle -> {
Map<User, Phone> map = handle.createQuery(sql)
.setMapKeyColumn(null)
.setMapValueColumn(null)
.registerRowMapper(ConstructorMapper.factory(User.class, "u"))
代码示例来源:origin: org.jdbi/jdbi3-guava
@Test
public void keyValueColumns() {
h.execute("create table config (key varchar, value varchar)");
h.prepareBatch("insert into config (key, value) values (?, ?)")
.add("foo", "123")
.add("foo", "456")
.add("bar", "xyz")
.execute();
// tag::keyValue[]
Multimap<String, String> map = h.createQuery("select key, value from config")
.setMapKeyColumn("key")
.setMapValueColumn("value")
.collectInto(new GenericType<Multimap<String, String>>() {});
// end::keyValue[]
Multimap<String, String> expected = ImmutableListMultimap.<String, String>builder()
.putAll("foo", "123", "456")
.put("bar", "xyz")
.build();
assertThat(map).isEqualTo(expected);
}
代码示例来源:origin: org.jdbi/jdbi3-guava
@Test
public void index() {
h.execute("create table user (id int, manager_id int, name varchar)");
h.prepareBatch("insert into user (id, manager_id, name) values (?, ?, ?)")
.add(1, 0, "alice")
.add(2, 1, "bob")
.add(3, 1, "cathy")
.add(4, 3, "dilbert")
.execute();
// tag::index[]
Multimap<Integer, User> map = h.createQuery("select id, manager_id, name from user")
.setMapKeyColumn("manager_id")
.registerRowMapper(ConstructorMapper.factory(User.class))
.collectInto(new GenericType<Multimap<Integer, User>>() {});
// end::index[]
Multimap<Integer, User> expected = ImmutableListMultimap.<Integer, User>builder()
.put(0, new User(1, "alice"))
.putAll(1, new User(2, "bob"), new User(3, "cathy"))
.put(3, new User(4, "dilbert"))
.build();
assertThat(map).isEqualTo(expected);
}
内容来源于网络,如有侵权,请联系作者删除!