本文整理汇总了Java中org.skife.jdbi.v2.util.StringMapper类的典型用法代码示例。如果您正苦于以下问题:Java StringMapper类的具体用法?Java StringMapper怎么用?Java StringMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringMapper类属于org.skife.jdbi.v2.util包,在下文中一共展示了StringMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadAllKeys
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Override
public Set<UUID> loadAllKeys() {
// TODO define how many keys will be pre-loaded
log.debug("loading all keys from table {}", tableName);
Set<UUID> result = dbi.withHandle(new HandleCallback<Set<UUID>>() {
@Override
public Set<UUID> withHandle(Handle h) throws Exception {
List<String> strResult = h.createQuery(String.format("select id from %s", tableName))
.map(new StringMapper()).list();
Set<UUID> uResult = new HashSet<>();
for (String uuid : strResult){
uResult.add(UUID.fromString(uuid));
}
return uResult;
}
});
log.debug("{} keys within table {} were loaded", result.size(), tableName);
return result;
}
示例2: updateUserPassword
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public void updateUserPassword(int id, String oldPassword, String newPassword) {
final String scrypt = SCryptUtil.scrypt(newPassword, 2 << 14, 8, 1);
if (!PASSWORD_PATTERN.matcher(newPassword).matches()) {
throw new RakamException("Password is not valid. Your password must contain at least one lowercase character, uppercase character and digit and be at least 8 characters. ", BAD_REQUEST);
}
if (config.getHashPassword()) {
oldPassword = CryptUtil.encryptWithHMacSHA1(oldPassword, encryptionConfig.getSecretKey());
}
try (Handle handle = dbi.open()) {
String hashedPass = handle.createQuery("SELECT password FROM web_user WHERE id = :id")
.bind("id", id).map(StringMapper.FIRST).first();
if (hashedPass == null) {
throw new RakamException("User does not exist", BAD_REQUEST);
}
if (!SCryptUtil.check(oldPassword, hashedPass)) {
throw new RakamException("Password is wrong", BAD_REQUEST);
}
handle.createStatement("UPDATE web_user SET password = :password WHERE id = :id")
.bind("id", id)
.bind("password", scrypt).execute();
}
}
示例3: shouldCreate
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public void shouldCreate() {
Map<String, AlarmSubExpression> subExpressions =
ImmutableMap
.<String, AlarmSubExpression>builder()
.put(
"4433",
AlarmSubExpression
.of("avg(hpcs.compute{flavor_id=777, image_id=888, metric_name=cpu}) > 10"))
.build();
AlarmDefinition alarmA =
repo.create("555", "2345", "90% CPU", null, "LOW",
"avg(hpcs.compute{flavor_id=777, image_id=888, metric_name=cpu}) > 10", subExpressions,
Arrays.asList("flavor_id", "image_id"), alarmActions, null, null);
AlarmDefinition alarmB = repo.findById("555", alarmA.getId());
assertEquals(alarmA, alarmB);
// Assert that sub-alarm and sub-alarm-dimensions made it to the db
assertEquals(
handle.createQuery("select count(*) from sub_alarm_definition where id = 4433")
.map(StringMapper.FIRST).first(), "1");
assertEquals(
handle.createQuery("select count(*) from sub_alarm_definition_dimension where sub_alarm_definition_id = 4433")
.map(StringMapper.FIRST).first(), "3");
}
示例4: testFixturesArePresent
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Test
public void testFixturesArePresent() throws Exception
{
DataSource ds = mysql.getDataSource();
List<String> rs = new DBI(ds).withHandle(new HandleCallback<List<String>>()
{
@Override
public List<String> withHandle(final Handle handle) throws Exception
{
return handle.createQuery("select name from something order by id")
.map(StringMapper.FIRST)
.list();
}
});
assertThat(rs).containsExactly("Gene", "Brian");
}
示例5: testFixturesEstablished
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Test
public void testFixturesEstablished() throws Exception
{
DataSource ds = mysql.getDataSource();
List<String> rs = new DBI(ds).withHandle(new HandleCallback<List<String>>()
{
@Override
public List<String> withHandle(final Handle handle) throws Exception
{
return handle.createQuery("select name from something order by id")
.map(StringMapper.FIRST)
.list();
}
});
assertThat(rs).containsExactly("Gene", "Brian");
}
示例6: getAllChildCopyRoles
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public List<CopyRole> getAllChildCopyRoles(Long workId) {
List<String> copyRoleCodes = new ArrayList<>();
try (Handle h = graph.dbi().open()) {
copyRoleCodes = h.createQuery(
"SELECT DISTINCT p2.copyRole " +
"FROM node v, flatedge e, flatedge e2, work p, work p2 " +
"WHERE e.v_in = :workId " +
" AND e.v_out = v.id " +
" AND e.label = 'isPartOf' " +
" AND p.id = v.id " +
" AND p.type IN ('Work', 'Page', 'EADWork')" +
" AND e2.v_in = p.id " +
" AND e2.v_out = p2.id " +
" AND e2.label = 'isCopyOf' ")
.bind("workId", workId)
.map(StringMapper.FIRST).list();
}
List<CopyRole> copyRoles = new ArrayList<CopyRole>();
for (String code : copyRoleCodes) {
copyRoles.add(CopyRole.fromString(code));
}
return copyRoles;
}
示例7: getAllCopyRoles
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public List<CopyRole> getAllCopyRoles(List<Long> workIds){
List<CopyRole> copyRoles = new ArrayList<>();
if (CollectionUtils.isNotEmpty(workIds)){
List<String> copyRoleCodes;
try (Handle h = graph.dbi().open()) {
copyRoleCodes = h.createQuery(
"select distinct copyRole " +
"from work p, flatedge e, node v " +
"where p.id = e.v_out and v.id = p.id " +
"and e.label = 'isCopyOf' and e.v_in in (" + Joiner.on(",").join(workIds) + ")")
.map(StringMapper.FIRST).list();
}
for (String code : copyRoleCodes) {
CopyRole copyRole = CopyRole.fromString(code);
if (copyRole != null){
copyRoles.add(copyRole);
}
}
}
return copyRoles;
}
示例8: get
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public String get() {
String name;
Handle handle = dbi.open();
try {
name = handle.createQuery("select description from my_test")
.map(StringMapper.FIRST)
.first();
} finally {
handle.close();
}
return name;
}
示例9: revokeSingleToken
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public Optional<String> revokeSingleToken(String accountId, String tokenLink) {
return Optional.ofNullable(jdbi.withHandle(handle ->
handle.createQuery("UPDATE tokens SET revoked=(now() at time zone 'utc') WHERE account_id=:accountId AND token_link=:tokenLink AND revoked IS NULL RETURNING to_char(revoked,'DD Mon YYYY')")
.bind("accountId", accountId)
.bind("tokenLink", tokenLink)
.map(StringMapper.FIRST)
.first()));
}
示例10: lookupColumnForTokenTable
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
public java.util.Optional<String> lookupColumnForTokenTable(String column, String idKey, String idValue) {
return java.util.Optional.ofNullable(jdbi.withHandle(handle ->
handle.createQuery("SELECT " + column + " FROM tokens WHERE " + idKey + "=:placeholder")
.bind("placeholder", idValue)
.map(StringMapper.FIRST)
.first()));
}
示例11: keySet
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Override
public Set<String> keySet() {
final Handle handle = dbi.open();
final Query<String> query = handle
.createQuery(String.format("select %s from %s order by %s", keyColumnName, tableName, keyColumnName))
.map(StringMapper.FIRST);
return new IteratingSet<String>() {
@Override
public Iterator<String> createIterator() {
return new QueryResultIterator<>(query, handle);
}
};
}
示例12: putStoresExtraColumns
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Test
public void putStoresExtraColumns() {
ExtraColumnsJdbcMap extraMap = new ExtraColumnsJdbcMap("map", "key", "value", serializer);
SerializableThing thing = new SerializableThing(42);
extraMap.put("thing", thing);
int num = handle.createQuery("select num from map where key = ?")
.bind(0, "thing")
.map(IntegerMapper.FIRST).first();
assertThat(num, equalTo(42));
String str = handle.createQuery("select str from map where key = ?")
.bind(0, "thing")
.map(StringMapper.FIRST).first();
assertThat(str, equalTo("value42"));
assertThat(extraMap.get("thing"), equalTo(thing));
}
示例13: getRacesWithFrequencies
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Override
public Set<DetailRace> getRacesWithFrequencies() {
try (Handle handle = dbi.open()) {
return handle.createQuery("select distinct detail_race from race_freq")
.map(StringMapper.FIRST)
.list()
.stream()
.map(r -> DetailRace.valueOf(r))
.collect(Collectors.toSet());
}
}
示例14: getFamilyAlleleMap
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
@Override
public Map<String, Set<String>> getFamilyAlleleMap() {
try (Handle handle = dbi.open()) {
return StreamSupport.stream(handle.createQuery("select distinct allele from ("
+ " select allele from race_freq where locus='HLA-DPB1'"
+ " union select allele from allele_group where locus='HLA-DPB1'"
+ " union select allele from hla_g_group where locus='HLA-DPB1')")
.map(StringMapper.FIRST)
.spliterator(), false)
.collect(Collectors.groupingBy(a -> a.substring(0, a.indexOf(":")), Collectors.toSet()));
}
}
示例15: getGGroupForAllele
import org.skife.jdbi.v2.util.StringMapper; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String getGGroupForAllele(String allele) {
try (Handle handle = dbi.open()) {
Matcher m = ALLELE_PATTERN.matcher(allele);
if (!m.matches()) return null;
String group = handle.createQuery("select g_group from hla_g_group where locus = :locus and allele = :allele")
.bind("locus", m.group("locus"))
.bind("allele", m.group("allele"))
.map(StringMapper.FIRST)
.first();
return (group == null) ? null : m.group("locus") + "*" + group;
}
}