本文整理汇总了Java中org.skife.jdbi.v2.util.StringColumnMapper类的典型用法代码示例。如果您正苦于以下问题:Java StringColumnMapper类的具体用法?Java StringColumnMapper怎么用?Java StringColumnMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringColumnMapper类属于org.skife.jdbi.v2.util包,在下文中一共展示了StringColumnMapper类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchIdsByPropertyValueFullTableScan
import org.skife.jdbi.v2.util.StringColumnMapper; //导入依赖的package包/类
protected Set<String> fetchIdsByPropertyValueFullTableScan(final String collectionPath, final String property, final String value) {
final String pathRegex = collectionPath + "/:[^/]+/" + property;
final AtomicReference<Set<String>> ret = new AtomicReference<>();
withTransaction(dbi -> {
final String query;
if (databaseKind == DatabaseKind.PostgreSQL) {
query = "SELECT regexp_replace(path, '(/.+/:[^/]+).*', '\\1') from jsondb where path ~ ? and value = ?";
} else if (databaseKind == DatabaseKind.H2) {
query = "SELECT regexp_replace(path, '(/.+/:[^/]+).*', '$1') from jsondb where path regexp ? and value = ?";
} else {
throw new UnsupportedOperationException(
"Don't know how to use regex in a query with database: " + databaseKind);
}
final List<String> paths = dbi.createQuery(query).bind(0, pathRegex).bind(1, value)
.map(StringColumnMapper.INSTANCE).list();
ret.set(new HashSet<>(paths));
});
return ret.get();
}
示例2: fetchIdsByPropertyValue
import org.skife.jdbi.v2.util.StringColumnMapper; //导入依赖的package包/类
@Override
public Set<String> fetchIdsByPropertyValue(final String collectionPath, final String property, final String value) {
final String pathRegex = collectionPath + "/:[^/]+/" + property;
final AtomicReference<Set<String>> ret = new AtomicReference<>();
withTransaction(dbi -> {
final String query;
if (databaseKind == DatabaseKind.PostgreSQL) {
query = "SELECT regexp_replace(path, '(/.+/:[^/]+).*', '\\1') from jsondb where path ~ ? and value = ?";
} else if (databaseKind == DatabaseKind.H2) {
query = "SELECT regexp_replace(path, '(/.+/:[^/]+).*', '$1') from jsondb where path regexp ? and value = ?";
} else {
throw new UnsupportedOperationException(
"Don't know how to use regex in a query with database: " + databaseKind);
}
final List<String> paths = dbi.createQuery(query).bind(0, pathRegex).bind(1, value)
.map(StringColumnMapper.INSTANCE).list();
ret.set(new HashSet<>(paths));
});
return ret.get();
}
示例3: fetchIdsByPropertyValue
import org.skife.jdbi.v2.util.StringColumnMapper; //导入依赖的package包/类
@Override
public Set<String> fetchIdsByPropertyValue(final String collectionPath, final String property, final String value) {
String path = prefix(trimSuffix(collectionPath, "/"), "/");
String idx = path+"/"+property;
if( !indexes.contains(idx) ) {
String message = "Index not defined for: collectionPath: " + path + ", property: " + property;
LOG.warn("fetchIdsByPropertyValue not optimzed !!!: {}", message);
return fetchIdsByPropertyValueFullTableScan(collectionPath, property, value);
} else {
final AtomicReference<Set<String>> ret = new AtomicReference<>();
withTransaction(dbi -> {
final String query = "SELECT path FROM jsondb WHERE idx = ? AND value = ?";
final List<String> paths = dbi.createQuery(query)
.bind(0, idx)
.bind(1, value)
.map(StringColumnMapper.INSTANCE).list();
String suffix = "/" + property + "/";
ret.set(paths.stream()
.map(x -> trimSuffix(x, suffix))
.collect(Collectors.toCollection(HashSet::new)));
});
return ret.get();
}
}