本文整理了Java中org.jdbi.v3.core.statement.Query.mapToMap
方法的一些代码示例,展示了Query.mapToMap
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.mapToMap
方法的具体详情如下:
包路径:org.jdbi.v3.core.statement.Query
类名称:Query
方法名:mapToMap
暂无
代码示例来源:origin: jdbi/jdbi
@Test
public void mapToMapFailsOnUnmappableGenericType() {
jdbi.useHandle(h -> {
Query query = h.createQuery(QUERY);
GenericType<Alien> type = new GenericType<Alien>() {};
assertThatThrownBy(() -> query.mapToMap(type))
.hasMessage("no column mapper found for type " + type);
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testConvenienceMethod() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
List<Map<String, Object>> r = h.select("select * from something order by id").mapToMap().list();
assertThat(r).hasSize(2);
assertThat(r.get(0).get("name")).isEqualTo("eric");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testConvenienceMethodWithParam() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
List<Map<String, Object>> r = h.select("select * from something where id = ?", 1).mapToMap().list();
assertThat(r).hasSize(1);
assertThat(r.get(0).get("name")).isEqualTo("eric");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testHelpfulErrorOnNothingSet() {
assertThatThrownBy(() -> h.createQuery("select * from something where name = :name").mapToMap().list())
.isInstanceOf(UnableToCreateStatementException.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void canFluentMapToMapWithGenericTypeForValue() {
jdbi.useHandle(h -> {
Map<String, BigDecimal> map = h.createQuery(QUERY)
.mapToMap(new GenericType<BigDecimal>() {})
.findOnly();
assertThat(map)
.containsOnlyKeys("one", "two", "three")
.containsValues(new BigDecimal("1.0"), new BigDecimal("2.0"), new BigDecimal("3.0"));
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testEmptyExplosion() {
ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id")
.cleanupHandleRollback()
.mapToMap()
.iterator();
assertThatThrownBy(it::next).isInstanceOf(NoSuchElementException.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInsertWithPositionalParameters() {
somethingDao.insertSomething(4, "Dave", 90);
List<Map<String, Object>> rows = handle.select("select * from something where something_id=?", 4).mapToMap().list();
assertThat(rows).containsExactlyElementsOf(ImmutableList.of(
ImmutableMap.of("something_id", 4, "name", "Dave", "code", 90)));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFuzzyScript() {
Handle h = dbRule.openHandle();
Script script = h.createScript(getResourceOnClasspath("script/fuzzy-script.sql"));
script.executeAsSeparateStatements();
List<Map<String, Object>> rows = h.select("select id, name from something order by id").mapToMap().list();
assertThat(rows).isEqualTo(ImmutableList.of(
ImmutableMap.of("id", 1L, "name", "eric"),
ImmutableMap.of("id", 2L, "name", "sally;ann"),
ImmutableMap.of("id", 3L, "name", "bob"),
ImmutableMap.of("id", 12L, "name", "sally;ann;junior")));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testNotClosing() {
h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
List<Map<String, Object>> results = h.createQuery("select * from something order by id").mapToMap().list();
assertThat(results).hasSize(2);
assertThat(results.get(0)).containsEntry("name", "eric");
assertThat(h.isClosed()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testMapMapperOrdering() {
h.execute("insert into something (id, name) values (?, ?)", 1, "hello");
h.execute("insert into something (id, name) values (?, ?)", 2, "world");
List<Map<String, Object>> rs = h.createQuery("select id, name from something")
.mapToMap()
.list();
assertThat(rs).hasSize(2);
assertThat(rs).hasOnlyElementsOfType(LinkedHashMap.class);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testExecuteSomeStatements() {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (?, ?)", 3, "Patrick");
List<Map<String, Object>> rs = h.select("select id, name from something").mapToMap().list();
assertThat(rs).containsExactlyElementsOf(ImmutableList.of(ImmutableMap.of("id", 3L, "name", "Patrick")));
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testEmptyWorksToo() {
ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id")
.cleanupHandleRollback()
.mapToMap()
.iterator();
assertThat(it.hasNext()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testClosing() {
h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
List<Map<String, Object>> results = h.createQuery("select * from something order by id")
.cleanupHandleRollback()
.mapToMap()
.list();
assertThat(results).hasSize(2);
assertThat(results.get(0)).containsEntry("name", "eric");
assertThat(h.isClosed()).isTrue();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testQueriesWithNullResultSets() {
expectedException.expect(NoResultsException.class);
h.select("insert into something (id, name) values (?, ?)", 1, "hello").mapToMap().list();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testIterateKeepHandle() {
h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id")
.mapToMap()
.iterator();
assertThat(it).hasSize(2);
assertThat(h.isClosed()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testCaseUpper() {
h.getConfig(MapMappers.class).setCaseChange(CaseStrategy.LOCALE_UPPER);
Map<String, Object> noOne = h.createQuery("select * from Foo").mapToMap().findOnly();
assertThat(noOne).containsOnlyKeys("ID", "FIRSTNAME");
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testStatementWithOptionalMapResults() {
h.getConfig(ResultProducers.class).allowNoResults(true);
assertThat(h.createQuery("commit").mapToMap().findFirst()).isEmpty();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testCaseLower() {
h.getConfig(MapMappers.class).setCaseChange(CaseStrategy.LOCALE_LOWER);
Map<String, Object> noOne = h.createQuery("select * from Foo").mapToMap().findOnly();
assertThat(noOne).containsOnlyKeys("id", "firstname");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testScriptWithStringSemicolon() {
Handle h = dbRule.openHandle();
Script script = h.createScript(getResourceOnClasspath("script/insert-with-string-semicolons.sql"));
script.execute();
assertThat(h.select("select * from something").mapToMap()).hasSize(3);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testHandleReentrant() {
final TheBasics dao = db.onDemand(TheBasics.class);
dao.withHandle(handle1 -> {
dao.insert(new Something(7, "Martin"));
handle1.createQuery("SELECT 1").mapToMap().list();
return null;
});
}
内容来源于网络,如有侵权,请联系作者删除!