本文整理了Java中org.jdbi.v3.core.statement.Query.bind
方法的一些代码示例,展示了Query.bind
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.bind
方法的具体详情如下:
包路径:org.jdbi.v3.core.statement.Query
类名称:Query
方法名:bind
暂无
代码示例来源:origin: jdbi/jdbi
@Test
// TODO it would be nice if this failed in the future
public void testUsedAndUnusedNamed() {
assertThatCode(() -> h.createQuery("select * from something where id = :id")
.bind("id", 1)
.bind("name", "jack")
.collectRows(Collectors.counting())
).doesNotThrowAnyException();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindOptionalPresent() {
Something result = handle.createQuery(SELECT_BY_NAME)
.bind("name", Optional.of("brian"))
.mapToBean(Something.class)
.findOnly();
assertThat(result).isEqualTo(new Something(2, "brian"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindOptionalLong() {
assertThat(handle.createQuery("SELECT :value")
.bind("value", OptionalLong.empty())
.collectInto(OptionalLong.class))
.isEmpty();
assertThat(handle.createQuery("SELECT :value")
.bind("value", OptionalLong.of(123))
.collectInto(OptionalLong.class))
.hasValue(123);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindOptionalEmpty() {
List<Something> result = handle.createQuery(SELECT_BY_NAME)
.bind("name", Optional.absent())
.mapToBean(Something.class)
.list();
assertThat(result).containsExactly(new Something(1, "eric"), new Something(2, "brian"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSetPositionalString() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where name = ?")
.bind(0, "eric")
.mapToBean(Something.class)
.list()
.get(0);
assertThat(eric.getId()).isEqualTo(1);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSetPositionalInteger() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where id = ?")
.bind(0, 1)
.mapToBean(Something.class)
.list().get(0);
assertThat(eric.getId()).isEqualTo(1);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testGetTrySuccessShouldReturnCorrectRow() {
Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME)
.bind("name", Try.success("brian"))
.mapToBean(Something.class)
.findOnly();
assertThat(result).isEqualTo(BRIANSOMETHING);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testGetLazyShouldReturnCorrectRow() {
Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME)
.bind("name", Lazy.of(() -> "brian"))
.mapToBean(Something.class)
.findOnly();
assertThat(result).isEqualTo(BRIANSOMETHING);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testGetValidationInvalidShouldReturnAllRows() {
List<Something> result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME)
.bind("name", Validation.invalid("eric"))
.mapToBean(Something.class)
.list();
assertThat(result).hasSize(2);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFiveMinuteFluentApi() {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (?, ?)", 1, "Brian");
String name = h.createQuery("select name from something where id = :id")
.bind("id", 1)
.mapTo(String.class)
.findOnly();
assertThat(name).isEqualTo("Brian");
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindOptionalOfCustomType() {
handle.registerArgument(new NameArgumentFactory());
List<Something> result = handle.createQuery(SELECT_BY_NAME)
.bind("name", Optional.of(new Name("eric")))
.mapToBean(Something.class)
.list();
assertThat(result).containsExactly(new Something(1, "eric"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void namesAreMappedCorrectly() {
db.getJdbi().useHandle(h -> {
Foobar name = h.createQuery("select :name")
.bind("name", Foobar.FOO.name())
.mapTo(Foobar.class)
.findOnly();
assertThat(name)
.isEqualTo(Foobar.FOO);
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void columnMapper() {
handle.registerColumnMapper(userNameFactory);
handle.registerRowMapper(ConstructorMapper.factory(NamedUser.class));
NamedUser bob = handle.createQuery("SELECT id, name FROM user WHERE name = :name")
.bind("name", "Bob")
.mapTo(NamedUser.class)
.findOnly();
assertThat(bob.name.name).isEqualTo("Bob");
}
// end::columnMapper[]
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindOptionalOfUnregisteredCustomType() {
exception.expect(UnsupportedOperationException.class);
handle.createQuery(SELECT_BY_NAME)
.bind("name", Optional.of(new Name("eric")))
.mapToBean(Something.class)
.list();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testHandlesNulls() {
handle.execute("insert into intervals(id, foo) values(?, ?)", 5, null);
final Period p = handle.createQuery("select foo from intervals where id=?")
.bind(0, 5)
.mapTo(Period.class)
.findOnly();
assertThat(p).isNull();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testHandlesEmptyMap() {
handle.execute("insert into campaigns(id, caps) values (?,?)", 4, ImmutableMap.of());
Map<String, String> newCaps = handle.createQuery("select caps from campaigns where id=?")
.bind(0, 4)
.mapTo(QualifiedType.of(STRING_MAP).with(HStore.class))
.findOnly();
assertThat(newCaps).isEmpty();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallCanBeAnnotatedAsByName() {
h.getConfig(Enums.class).setEnumStrategy(EnumStrategy.BY_ORDINAL);
Object byName = h.createQuery("select :name")
.bind("name", Foobar.FOO.name())
.mapTo(QualifiedType.of(Foobar.class).with(EnumByName.class))
.findOnly();
assertThat(byName)
.isEqualTo(Foobar.FOO);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallOverridesClassForName() {
h.getConfig(Enums.class).setEnumStrategy(EnumStrategy.BY_ORDINAL);
Object byName = h.createQuery("select :name")
.bind("name", ByOrdinal.NUMERIC.name())
.mapTo(QualifiedType.of(ByOrdinal.class).with(EnumByName.class))
.findOnly();
assertThat(byName)
.isEqualTo(ByOrdinal.NUMERIC);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testRegisterInferredOnJdbi() {
db.registerRowMapper(new SomethingMapper());
Something sam = db.withHandle(handle1 -> {
handle1.execute("insert into something (id, name) values (18, 'Sam')");
return handle1.createQuery("select id, name from something where id = :id")
.bind("id", 18)
.mapTo(Something.class)
.findOnly();
});
assertThat(sam.getName()).isEqualTo("Sam");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testDoesNotExist() {
Handle h = dbRule.getSharedHandle();
h.execute("insert into something (id, name) values (1, 'Coda')");
Optional<String> rs = h.createQuery("select name from something where id = :id")
.bind("id", 2)
.mapTo(String.class)
.collect(GuavaCollectors.toOptional());
assertThat(rs).isAbsent();
}
内容来源于网络,如有侵权,请联系作者删除!