本文整理汇总了Java中org.skife.jdbi.v2.Query.bind方法的典型用法代码示例。如果您正苦于以下问题:Java Query.bind方法的具体用法?Java Query.bind怎么用?Java Query.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.skife.jdbi.v2.Query
的用法示例。
在下文中一共展示了Query.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindDimensionsToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
static void bindDimensionsToQuery(Query<?> query, Map<String, String> dimensions) {
if (dimensions != null) {
int i = 0;
for (Iterator<Map.Entry<String, String>> it = dimensions.entrySet().iterator(); it.hasNext(); i++) {
Map.Entry<String, String> entry = it.next();
query.bind("dname" + i, entry.getKey());
if (!Strings.isNullOrEmpty(entry.getValue())) {
List<String> values = BAR_SPLITTER.splitToList(entry.getValue());
if (values.size() > 1) {
for (int j = 0; j < values.size(); j++) {
query.bind("dvalue" + i + '_' + j, values.get(j));
}
}
else {
query.bind("dvalue" + i, entry.getValue());
}
}
}
}
}
示例2: bindDimensionsToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
public static void bindDimensionsToQuery(
Query<?> query,
Map<String, String> dimensions) {
if (dimensions != null) {
int i = 0;
for (Iterator<Map.Entry<String, String>> it = dimensions.entrySet().iterator(); it.hasNext(); i++) {
Map.Entry<String, String> entry = it.next();
query.bind("dname" + i, entry.getKey());
if (!Strings.isNullOrEmpty(entry.getValue())) {
List<String> values = Splitter.on('|').splitToList(entry.getValue());
int j = 0;
for (String value : values) {
query.bind("dvalue" + i + '_' + j, value);
j++;
}
}
}
}
}
示例3: findById
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
@Override
public AlarmDefinition findById(String tenantId, String alarmDefId) {
try (Handle h = db.open()) {
String query = "SELECT alarm_definition.id, alarm_definition.tenant_id, alarm_definition.name, alarm_definition.description, "
+ "alarm_definition.expression, alarm_definition.severity, alarm_definition.match_by, alarm_definition.actions_enabled, "
+" alarm_definition.created_at, alarm_definition.updated_at, alarm_definition.deleted_at, "
+ "GROUP_CONCAT(alarm_action.action_id) AS notificationIds,group_concat(alarm_action.alarm_state) AS states "
+ "FROM alarm_definition LEFT OUTER JOIN alarm_action ON alarm_definition.id=alarm_action.alarm_definition_id "
+ " WHERE alarm_definition.tenant_id=:tenantId AND alarm_definition.id=:alarmDefId AND alarm_definition.deleted_at "
+ " IS NULL GROUP BY alarm_definition.id";
Query<?> q = h.createQuery(query);
q.bind("tenantId", tenantId);
q.bind("alarmDefId", alarmDefId);
q.registerMapper(new AlarmDefinitionMapper());
q = q.mapTo(AlarmDefinition.class);
AlarmDefinition alarmDefinition = (AlarmDefinition) q.first();
if(alarmDefinition == null)
{
throw new EntityNotFoundException("No alarm definition exists for %s", alarmDefId);
}
return alarmDefinition;
}
}
示例4: getTaskIdHistoryCount
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
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();
}
示例5: getLogs
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
@JsonRequest
@ApiOperation(value = "Get logs", authorizations = @Authorization(value = "master_key"))
@Path("/get_logs")
public List<LogEntry> getLogs(@Named("project") RequestContext context, @ApiParam(value = "start", required = false) Instant start, @ApiParam(value = "end", required = false) Instant end, @ApiParam(value = "prefix") String prefix) {
String sql = "SELECT id, type, error, created FROM javascript_logs WHERE project = :project AND prefix = :prefix";
if (start != null) {
sql += " AND created > :start";
}
if (end != null) {
sql += " AND created < :end";
}
sql += " ORDER BY created DESC";
try (Handle handle = dbi.open()) {
Query<Map<String, Object>> query = handle.createQuery(sql + " LIMIT 100");
query.bind("project", context.project);
query.bind("prefix", prefix);
if (start != null) {
query.bind("start", start.toEpochMilli());
}
if (end != null) {
query.bind("end", end.toEpochMilli());
}
return query.map((index, r, ctx) -> {
return new LogEntry(r.getString(1), Level.valueOf(r.getString(2)), r.getString(3), Instant.ofEpochMilli(r.getLong(4)));
}).list();
}
}
示例6: bindOffsetToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
static void bindOffsetToQuery(Query<Map<String, Object>> query, String offset) {
List<String> offsets = UNDERSCORE_SPLITTER.splitToList(offset);
if (offsets.size() > 1) {
query.bind("offset_id", offsets.get(0));
query.bind("offset_timestamp",
new Timestamp(DateTime.parse(offsets.get(1)).getMillis()));
} else {
query.bind("offset_timestamp",
new Timestamp(DateTime.parse(offsets.get(0)).getMillis()));
}
}
示例7: checkForMultipleDefinitions
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
static void checkForMultipleDefinitions(Handle h, String tenantId, String name, Map<String, String> dimensions)
throws MultipleMetricsException {
String namePart = "";
if (name != null && !name.isEmpty()) {
namePart = "AND name = :name ";
}
String sql = String.format(METRIC_DEF_SUB_SQL,
"",
namePart,
buildDimensionAndClause(dimensions,
TABLE_TO_JOIN_ON),
"") + " limit 2";
Query<Map<String, Object>> query = h.createQuery(sql);
query.bind("tenantId", tenantId);
if (name != null) {
query.bind("name", name);
}
bindDimensionsToQuery(query, dimensions);
List<Map<String, Object>> rows = query.list();
if (rows.size() > 1) {
throw new MultipleMetricsException(name, dimensions);
}
}
示例8: bindGroupBy
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
static void bindGroupBy(Query<Map<String, Object>> query, List<String> groupBy) {
int i = 0;
for (String value: groupBy) {
query.bind("groupBy" + i, value);
i++;
}
}
示例9: bindDimensionsToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
public static void bindDimensionsToQuery(Query query, Map<String, String> dimensions) {
if (dimensions != null) {
int i = 0;
for (Map.Entry<String, String> entry: dimensions.entrySet()) {
query.bind("dname" + i, entry.getKey());
query.bind("dvalue" + i, entry.getValue());
i++;
}
}
}
示例10: bindDimensionsToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
private void bindDimensionsToQuery(Query query, Map<String, String> dimensions) {
if (dimensions != null) {
int i = 0;
for (Map.Entry<String, String> entry : dimensions.entrySet()) {
query.bind("dname" + i, entry.getKey());
query.bind("dvalue" + i, entry.getValue());
i++;
}
}
}
示例11: bindSeverityToQuery
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
public static void bindSeverityToQuery(Query query, List<AlarmSeverity> severities) {
if (severities != null && !severities.isEmpty()) {
for (int i = 0; i < severities.size(); i++) {
query.bind("severity" + String.valueOf(i), severities.get(i).name());
}
}
}
示例12: keyValuesFor
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
/**
* Returns a map of key/value pairs for the given {@code keyValueSelectingSql} with the
* {@code orderedParameters}.
*
* @param handle to execute statement against
* @param keyValueSelectingSql statement that selects a key and value
* @param orderedParameters ordered parameters to set against the {@code keyValueSelectingSql}
* @return a map of key value pairs
*/
public static Map<String, String> keyValuesFor(Handle handle, String keyValueSelectingSql,
Object... orderedParameters) {
Query<Map<String, Object>> q = handle.createQuery(keyValueSelectingSql);
for (int i = 0; i < orderedParameters.length; i++)
q.bind(i, orderedParameters[i]);
KeyValueMapper mapper = new KeyValueMapper();
Iterator<Object> it = q.map(mapper).iterator();
while (it.hasNext())
it.next();
return mapper.map;
}
示例13: getTaskIdHistory
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
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());
}
if (limitStart.isPresent()) {
sqlBuilder.append(" LIMIT :limitStart, ");
binds.put("limitStart", limitStart.get());
} else {
sqlBuilder.append(" LIMIT ");
}
sqlBuilder.append(":limitCount");
binds.put("limitCount", limitCount);
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();
}
示例14: query
import org.skife.jdbi.v2.Query; //导入方法依赖的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);
}
示例15: addSummary
import org.skife.jdbi.v2.Query; //导入方法依赖的package包/类
private void addSummary(Query query, Long id, List<WorkSummary> summaries, int currentDepth, int maxDepth) {
query.bind("id", id);
Map<String, Object> work = (Map<String, Object>) query.first();
if (work != null) {
WorkSummary summary = new WorkSummary();
summary.setId(id);
summary.setParentId((Long) work.get("parentId"));
summary.setTitle((String) work.get("title"));
summary.setCollectionCode((String) work.get("collection"));
summary.setForm((String) work.get("form"));
summary.setCreator((String) work.get("creator"));
summary.setAccessConditions((String) work.get("accessConditions"));
summary.setInternalAccessConditions((String) work.get("internalAccessConditions"));
summary.setDigitalStatus((String) work.get("digitalStatus"));
summary.setDigitalStatusDate((Date) work.get("digitalStatusDate"));
summary.setDateCreated((Date) work.get("dateCreated"));
summary.setRecordSource((String) work.get("recordSource"));
summary.setLocalSystemNumber((String) work.get("localSystemNumber"));
summary.setBibLevel((String) work.get("bibLevel"));
summary.setBibId((String) work.get("bibId"));
summary.setSubUnitType((String) work.get("subUnitType"));
summary.setSubUnitNumber((String) work.get("subUnitNo"));
summary.setSensitiveMaterial((String) work.get("sensitiveMaterial"));
summary.setObjectId(PIUtil.format((Long) work.get("childId")));
summaries.add(summary);
if (summary.getParentId() != null && currentDepth < maxDepth) {
addSummary(query, summary.getParentId(), summaries, currentDepth + 1, maxDepth);
}
}
}