本文整理汇总了Java中org.skife.jdbi.v2.util.LongMapper类的典型用法代码示例。如果您正苦于以下问题:Java LongMapper类的具体用法?Java LongMapper怎么用?Java LongMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LongMapper类属于org.skife.jdbi.v2.util包,在下文中一共展示了LongMapper类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDatasetDate
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Long getDatasetDate(String dataset) {
try (Handle handle = dbi.open()) {
return handle.createQuery("select modification_date from dataset_date where dataset = :dataset")
.bind("dataset", dataset)
.map(LongMapper.FIRST)
.first();
}
}
示例2: updateDashboard
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
@JsonRequest
@ApiOperation(value = "Update dashboard items")
@Path("/update_dashboard_items")
@ProtectEndpoint(writeOperation = true)
public SuccessMessage updateDashboard(
@Named("user_id") Project project,
@ApiParam("dashboard") int dashboard,
@ApiParam("items") List<DashboardItem> items) {
dbi.inTransaction((handle, transactionStatus) -> {
Long execute = handle.createQuery("SELECT id FROM dashboard WHERE id = :id AND project_id = :project")
.bind("id", dashboard)
.bind("project", project.project)
.map(LongMapper.FIRST).first();
if (execute == null) {
throw new RakamException(HttpResponseStatus.NOT_FOUND);
}
for (DashboardItem item : items) {
// TODO: verify dashboard is in project
handle.createStatement("UPDATE dashboard_items SET name = :name, directive = :directive, options = :options WHERE id = :id")
.bind("id", item.id)
.bind("name", item.name)
.bind("directive", item.directive)
.bind("options", JsonHelper.encode(item.options))
.execute();
}
return null;
});
return SuccessMessage.success();
}
示例3: getNLastCreatedVertexIds
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
/**
* Find the first N vertex ids order by the txn_start column desc among the specified list of vertex ids
* @param vertexIds input vertex Ids
* @param n the first N rows returned by the query
*/
public static List<Long> getNLastCreatedVertexIds(AmberSession sess, List<Long> vertexIds, long n){
if (CollectionUtils.isNotEmpty(vertexIds)){
String sql = "SELECT id FROM node WHERE id IN (" + Joiner.on(",").join(vertexIds) + ") GROUP BY id ORDER BY MIN(txn_start) DESC LIMIT :n";
try (Handle h = sess.getAmberGraph().dbi().open()) {
return h.createQuery(sql).bind("n", n).map(LongMapper.FIRST).list();
}
}
return new ArrayList<>();
}
示例4: getChildrenIdsByBibLevelSubTypeQuery
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
private Query getChildrenIdsByBibLevelSubTypeQuery(Handle h, List<Long> parentIds, BibLevel bibLevel, List<String> subTypes) {
if (CollectionUtils.isNotEmpty(subTypes)){
Function<String,String> addQuotes = new Function<String,String>() {
@Override public String apply(String s) {
return new StringBuilder(s.length()+2).append("'").append(s).append("'").toString();
}
};
String subTypeStr = Joiner.on(", ").join(Iterables.transform(subTypes, addQuotes));
return h.createQuery(
"select distinct v.id from work p1, work p2, flatedge e, node v " +
"where p1.id = e.v_out and p2.id = e.v_out and v.id = p1.id and v.id = p2.id " +
"and e.label = 'isPartOf' " +
"and p1.bibLevel = :bibLevel " +
"and p2.subType in ("+ subTypeStr + ") " +
"and e.v_in in (" + Joiner.on(",").join(parentIds) + ")")
.bind("bibLevel", bibLevel.code())
.map(LongMapper.FIRST);
}
return h.createQuery(
"select distinct v.id from work p1, flatedge e, node v " +
"where p1.id = e.v_out and v.id = p1.id " +
"and e.label = 'isPartOf' " +
"and p1.bibLevel = :bibLevel " +
"and e.v_in in (" + Joiner.on(",").join(parentIds) + ")")
.bind("bibLevel", bibLevel.code())
.map(LongMapper.FIRST);
}
示例5: getChildPIs
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
public List<String> getChildPIs(String workId) {
try (Handle h = graph.dbi().open()) {
List<Long> objIds = h.createQuery("select v_out from flatedge where v_in = :workId and label = 'isPartOf'")
.bind("workId", PIUtil.parse(workId))
.map(LongMapper.FIRST)
.list();
List<String> strings = new ArrayList<>(objIds.size());
for (Long objId: objIds) {
strings.add(PIUtil.format(objId));
}
return strings;
}
}
示例6: query
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
public Query query(Handle h){
Query q = h.createQuery(sql());
for (int i=0; i< workProperties.size(); i++){
q.bind(i, workProperties.get(i).getValue());
}
return q.map(LongMapper.FIRST);
}
示例7: getAttributes
import org.skife.jdbi.v2.util.LongMapper; //导入依赖的package包/类
@Override
public CompletableFuture<List<String>> getAttributes(String project, String collection, String attribute, Optional<LocalDate> startDate,
Optional<LocalDate> endDate, Optional<String> filter) {
long numRows;
try (Handle handle = dbi.open()) {
numRows = handle.createQuery("select sum(shards.row_count) as row_count from tables join shards on (shards.table_id = tables.table_id) where table_name = :collection and schema_name = :schema")
.bind("collection", checkProject(collection))
.bind("schema", checkProject(project))
.map(LongMapper.FIRST).iterator().next();
}
double samplePercentage;
double adjustedSamplingThreshold = SAMPLING_THRESHOLD * activeNodeCount.get();
if (numRows > adjustedSamplingThreshold) {
samplePercentage = ((adjustedSamplingThreshold / numRows) * 100);
} else {
samplePercentage = 100;
}
String prestoQuery;
prestoQuery = format("SELECT DISTINCT %s FROM %s.%s.%s TABLESAMPLE BERNOULLI (%f) WHERE %s IS NOT NULL",
checkTableColumn(attribute),
prestoConfig.getColdStorageConnector(),
checkProject(project, '"'),
checkCollection(collection, '"'),
samplePercentage, checkTableColumn(attribute));
if (startDate.isPresent()) {
prestoQuery += format(" AND %s >= date '%s'",
checkTableColumn(projectConfig.getTimeColumn()),
startDate.get().toString(),
checkCollection(attribute));
}
if (endDate.isPresent()) {
prestoQuery += format(" AND %s < date '%s'",
checkTableColumn(projectConfig.getTimeColumn()),
endDate.get().toString(),
checkCollection(attribute));
}
if (filter.isPresent() && !filter.get().isEmpty()) {
prestoQuery += String.format(" AND lower(%s) LIKE '%s' ESCAPE '\\'", checkTableColumn(attribute),
filter.get().replaceAll("%", "\\%").replaceAll("_", "\\_").toLowerCase(ENGLISH) + "%");
}
prestoQuery += " LIMIT 10";
CompletableFuture<QueryResult> result = new PrestoQueryExecution(defaultSession, prestoQuery, true).getResult();
return result.thenApply(v -> {
if (v.isFailed()) {
throw new RakamException(v.getError().message, SERVICE_UNAVAILABLE);
}
return v.getResult().stream().map(object -> Objects.toString(object.get(0), null))
.sorted()
.collect(Collectors.toList());
});
}