本文整理了Java中org.skife.jdbi.v2.Query.mapTo
方法的一些代码示例,展示了Query.mapTo
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.mapTo
方法的具体详情如下:
包路径:org.skife.jdbi.v2.Query
类名称:Query
方法名:mapTo
[英]Makes use of registered mappers to map the result set to the desired type.
[中]使用已注册的映射器将结果集映射到所需的类型。
代码示例来源:origin: HubSpot/Singularity
@Override
public int getTaskIdHistoryCount(Optional<String> requestId, Optional<String> deployId, Optional<String> runId, Optional<String> host,
Optional<ExtendedTaskState> lastTaskStatus, Optional<Long> startedBefore, Optional<Long> startedAfter, Optional<Long> updatedBefore,
Optional<Long> updatedAfter) {
final Map<String, Object> binds = new HashMap<>();
final StringBuilder sqlBuilder = new StringBuilder(GET_TASK_ID_HISTORY_COUNT_QUERY);
applyTaskIdHistoryBaseQuery(sqlBuilder, binds, requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter);
final String sql = sqlBuilder.toString();
LOG.trace("Generated sql for task search count: {}, binds: {}", sql, binds);
final Query<Integer> query = getHandle().createQuery(sql).mapTo(Integer.class);
for (Map.Entry<String, Object> entry : binds.entrySet()) {
query.bind(entry.getKey(), entry.getValue());
}
return query.first();
}
代码示例来源:origin: HubSpot/Singularity
@Override
public List<SingularityTaskIdHistory> getTaskIdHistory(Optional<String> requestId, Optional<String> deployId, Optional<String> runId, Optional<String> host,
Optional<ExtendedTaskState> lastTaskStatus, Optional<Long> startedBefore, Optional<Long> startedAfter, Optional<Long> updatedBefore,
Optional<Long> updatedAfter, Optional<OrderDirection> orderDirection, Optional<Integer> limitStart, Integer limitCount) {
final Map<String, Object> binds = new HashMap<>();
final StringBuilder sqlBuilder = new StringBuilder(GET_TASK_ID_HISTORY_QUERY);
applyTaskIdHistoryBaseQuery(sqlBuilder, binds, requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter);
sqlBuilder.append(" ORDER BY startedAt ");
sqlBuilder.append(orderDirection.or(OrderDirection.DESC).name());
if (!requestId.isPresent()) {
sqlBuilder.append(", requestId ");
sqlBuilder.append(orderDirection.or(OrderDirection.DESC).name());
}
// NOTE: PG, MySQL are both compatible with OFFSET LIMIT syntax, while only MySQL understands LIMIT offset, limit.
if (limitCount != null ){
sqlBuilder.append(" LIMIT :limitCount");
binds.put("limitCount", limitCount);
}
if (limitStart.isPresent()) {
sqlBuilder.append(" OFFSET :limitStart ");
binds.put("limitStart", limitStart.get());
}
final String sql = sqlBuilder.toString();
LOG.trace("Generated sql for task search: {}, binds: {}", sql, binds);
final Query<SingularityTaskIdHistory> query = getHandle().createQuery(sql).mapTo(SingularityTaskIdHistory.class);
for (Map.Entry<String, Object> entry : binds.entrySet()) {
query.bind(entry.getKey(), entry.getValue());
}
return query.list();
}
代码示例来源:origin: org.jdbi/jdbi
@Override
public Integer withHandle(Handle handle) throws Exception
{
return handle.createQuery("select 2 + 2").mapTo(Integer.class).first();
}
});
代码示例来源:origin: org.jdbi/jdbi
@Override
public void call(IDBI dbi)
{
final Handle h = DBIUtil.getHandle(dbi);
int count = h.createQuery("select count(*) from something").mapTo(Integer.class).first();
assertEquals(0, count);
}
});
代码示例来源:origin: org.kill-bill.commons/killbill-jdbi
@Override
public Object withHandle(final Handle h) throws Exception {
h.execute("create");
h.execute("insert", 1, "Brian");
String brian = h.createQuery("findNameById").bind("0", 1).mapTo(String.class).first();
assertThat(brian).isEqualTo("Brian");
return null;
}
});
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testZipping() throws Exception
{
UsesBatching b = handle.attach(UsesBatching.class);
List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);
List<String> names = Arrays.asList("David", "Tim", "Mike");
b.zipArgumentsTogether(ids, names);
assertThat(b.size(), equalTo(3));
List<String> ins_names = handle.createQuery("select distinct name from something order by name")
.mapTo(String.class)
.list();
assertThat(ins_names, equalTo(Arrays.asList("David", "Mike", "Tim")));
}
代码示例来源:origin: org.jdbi/jdbi
@Override
public String withHandle(Handle handle) throws Exception {
handle.execute("insert into something (id, name) values (8, 'Mike')");
return handle.createQuery("select name from something where id = 8").mapTo(String.class).first();
}
});
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testBindConstantValue() throws Exception
{
UsesBatching b = handle.attach(UsesBatching.class);
List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);
b.withConstantValue(ids, "Johan");
assertThat(b.size(), equalTo(5));
List<String> names = handle.createQuery("select distinct name from something")
.mapTo(String.class)
.list();
assertThat(names, equalTo(Arrays.asList("Johan")));
}
代码示例来源:origin: org.kill-bill.commons/killbill-jdbi
@Override
public Something withHandle(Handle handle) throws Exception
{
handle.insert("insert into something (id, name) values (18, 'Sam')");
return handle.createQuery("select id, name from something where id = :id")
.bind("id", 18)
.mapTo(Something.class)
.first();
}
});
代码示例来源:origin: org.jdbi/jdbi
@Override
public Something withHandle(Handle handle) throws Exception
{
handle.insert("insert into something (id, name) values (18, 'Sam')");
return handle.createQuery("select id, name from something where id = :id")
.bind("id", 18)
.mapTo(Something.class)
.first();
}
});
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testOnList() throws Exception
{
h.registerContainerFactory(new ImmutableListContainerFactory());
h.execute("insert into something (id, name) values (1, 'Coda')");
h.execute("insert into something (id, name) values (2, 'Brian')");
ImmutableList<String> rs = h.createQuery("select name from something order by id")
.mapTo(String.class)
.list(ImmutableList.class);
assertThat(rs, equalTo(ImmutableList.of("Coda", "Brian")));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testDefines() throws Exception
{
handle.attach(Kangaroo.class).weirdInsert("something", "id", "name", 5, "Bouncer");
String name = handle.createQuery("select name from something where id = 5")
.mapTo(String.class)
.first();
assertThat(name, equalTo("Bouncer"));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testBaz() throws Exception
{
Wombat wombat = handle.attach(Wombat.class);
wombat.insert(new Something(7, "Henning"));
String name = handle.createQuery("select name from something where id = 7")
.mapTo(String.class)
.first();
assertThat(name, equalTo("Henning"));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testMapToEnum() throws Exception
{
Handle h = openHandle();
h.createStatement("insert into something (id, name) values (1, 'eric')").execute();
h.createStatement("insert into something (id, name) values (2, 'brian')").execute();
List<SomethingElse.Name> results = h.createQuery("select name from something order by id")
.mapTo(SomethingElse.Name.class)
.list();
assertEquals(SomethingElse.Name.eric, results.get(0));
assertEquals(SomethingElse.Name.brian, results.get(1));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testDefines() throws Exception
{
handle.attach(Wombat.class).weirdInsert("something", "id", "name", 5, "Bouncer");
handle.attach(Wombat.class).weirdInsert("something", "id", "name", 6, "Bean");
String name = handle.createQuery("select name from something where id = 5")
.mapTo(String.class)
.first();
assertThat(name, equalTo("Bouncer"));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testDoesNotExist() throws Exception
{
h.execute("insert into something (id, name) values (1, 'Coda')");
h.registerContainerFactory(new MaybeContainerFactory());
Maybe<String> rs = h.createQuery("select name from something where id = :id")
.bind("id", 2)
.mapTo(String.class)
.first(Maybe.class);
assertThat(rs.isKnown(), equalTo(false));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testExists() throws Exception
{
h.execute("insert into something (id, name) values (1, 'Coda')");
h.registerContainerFactory(new MaybeContainerFactory());
Maybe<String> rs = h.createQuery("select name from something where id = :id")
.bind("id", 1)
.mapTo(String.class)
.first(Maybe.class);
assertThat(rs.isKnown(), equalTo(true));
assertThat(rs.getValue(), equalTo("Coda"));
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testAPIWorks() throws Exception
{
Spiffy s = SqlObjectBuilder.onDemand(dbi, Spiffy.class);
s.insert(7, "Bill");
String bill = handle.createQuery("select name from something where id = 7").mapTo(String.class).first();
assertEquals("Bill", bill);
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testInsertWithVoidReturn() throws Exception
{
Inserter i = SqlObjectBuilder.open(dbi, Inserter.class);
// this is what is under test here
i.insertWithVoidReturn(2, "Diego");
String name = handle.createQuery("select name from something where id = 2").mapTo(String.class).first();
assertEquals("Diego", name);
i.close();
}
代码示例来源:origin: org.jdbi/jdbi
@Test
public void testInsert() throws Exception
{
Spiffy s = handle.attach(Spiffy.class);
s.insert(new Something(2, "Bean"));
String name = handle.createQuery("select name from something where id = 2").mapTo(String.class).first();
assertEquals("Bean", name);
}
内容来源于网络,如有侵权,请联系作者删除!