本文整理了Java中org.skife.jdbi.v2.Query.first
方法的一些代码示例,展示了Query.first
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.first
方法的具体详情如下:
包路径:org.skife.jdbi.v2.Query
类名称:Query
方法名:first
[英]Executes the select.
Specifies a maximum of one result on the JDBC statement, and map that one result as the return value, or return null if there is nothing in the results
[中]执行选择。
在JDBC语句中指定最多一个结果,并将该结果映射为返回值,如果结果中没有任何内容,则返回null
代码示例来源:origin: apache/incubator-druid
@Override
public Timestamp withHandle(Handle handle)
{
final String query = StringUtils.format(
"SELECT MAX(%s) FROM %s",
tsColumn, table
);
return handle
.createQuery(query)
.map(TimestampMapper.FIRST)
.first();
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Optional<EntryType> withHandle(Handle handle) throws Exception
{
byte[] res = handle.createQuery(
StringUtils.format("SELECT payload FROM %s WHERE id = :id", entryTable)
)
.bind("id", entryId)
.map(ByteArrayMapper.FIRST)
.first();
return Optional.fromNullable(
res == null ? null : jsonMapper.readValue(res, entryType)
);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Optional<StatusType> withHandle(Handle handle) throws Exception
{
byte[] res = handle.createQuery(
StringUtils.format("SELECT status_payload FROM %s WHERE id = :id", entryTable)
)
.bind("id", entryId)
.map(ByteArrayMapper.FIRST)
.first();
return Optional.fromNullable(
res == null ? null : jsonMapper.readValue(res, statusType)
);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
@Nullable
public TaskInfo<EntryType, StatusType> getTaskInfo(String entryId)
{
return connector.retryWithHandle(handle -> {
final String query = StringUtils.format(
"SELECT id, status_payload, payload, datasource, created_date FROM %s WHERE id = :id",
entryTable
);
return handle.createQuery(query)
.bind("id", entryId)
.map(taskInfoMapper)
.first();
});
}
代码示例来源:origin: apache/incubator-druid
@Override
public boolean tableExists(Handle handle, String tableName)
{
String databaseCharset = handle
.createQuery("SELECT @@character_set_database")
.map(StringMapper.FIRST)
.first();
if (!databaseCharset.startsWith("utf8")) {
throw new ISE(
"Druid requires its MySQL database to be created with an UTF8 charset, found `%1$s`. "
+ "The recommended charset is `utf8mb4`.",
databaseCharset
);
} else if (!"utf8mb4".equals(databaseCharset)) {
log.warn("The current database charset `%1$s` does not match the recommended charset `utf8mb4`", databaseCharset);
}
return !handle.createQuery("SHOW tables LIKE :tableName")
.bind("tableName", tableName)
.list()
.isEmpty();
}
代码示例来源:origin: apache/incubator-druid
.createQuery(
StringUtils.format(
"SELECT %1$s FROM %2$s WHERE %3$s = :key",
.first();
代码示例来源:origin: apache/incubator-druid
.createQuery(
StringUtils.format("SELECT COUNT(*) FROM %1$s WHERE %2$s = :key", tableName, keyColumn)
.first();
if (count == 0) {
handle.createStatement(
代码示例来源:origin: HubSpot/Singularity
@Override
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();
}
代码示例来源:origin: rakam-io/rakam
private boolean hasMasterAccess(Handle handle, int project, int user) {
return TRUE.equals(handle.createQuery("select user_id = :user or (select bool_or(master_permission) from web_user_api_key_permission p " +
"join web_user_api_key a on (p.api_key_id = a.id) where p.user_id = :user and a.project_id = :project) from web_user_project where id = :project")
.bind("user", user)
.bind("project", project).map(BooleanMapper.FIRST)
.first());
}
代码示例来源:origin: rakam-io/rakam
@Override
public InputStream getFile(int project, String slug, String file) {
try (Handle handle = dbi.open()) {
return handle.createQuery("SELECT data FROM custom_page WHERE project_id = :project AND slug = :slug")
.bind("project", project)
.bind("slug", slug)
.map((i, resultSet, statementContext) -> {
return new ByteArrayInputStream(((String) JsonHelper.read(resultSet.getString(1), Map.class)
.get(file)).getBytes(UTF_8));
}).first();
}
}
代码示例来源:origin: rakam-io/rakam
public ProjectOwner getProjectOwner(int project) {
try (Handle handle = dbi.open()) {
return handle.createQuery("select web_user.id, web_user.email from web_user join web_user_project project on (project.user_id = web_user.id) where project.id = :id")
.bind("id", project)
.map((index, r, ctx) -> {
return new ProjectOwner(r.getInt(1), r.getString(2));
}).first();
}
}
代码示例来源:origin: rakam-io/rakam
public String getUserStripeId(int id) {
try (Handle handle = dbi.open()) {
return handle
.createQuery("SELECT stripe_id FROM web_user WHERE id = :id")
.bind("id", id).map(StringMapper.FIRST).first();
}
}
代码示例来源:origin: rakam-io/rakam
@Override
public <T> T getConfig(String project, String configName, Class<T> clazz) {
try (Handle handle = dbi.open()) {
return handle.createQuery("SELECT value FROM config WHERE project = :project AND name = :name")
.bind("project", project)
.bind("name", configName.toUpperCase(Locale.ENGLISH)).map((i, resultSet, statementContext) -> {
return JsonHelper.read(resultSet.getString(1), clazz);
}).first();
}
}
代码示例来源:origin: rakam-io/rakam
@Override
public <T> T getConfig(String project, String configName, Class<T> clazz) {
try (Handle handle = dbi.open()) {
return handle.createQuery("SELECT value FROM config WHERE project = :project AND name = :name")
.bind("project", project)
.bind("name", configName.toUpperCase(Locale.ENGLISH)).map((i, resultSet, statementContext) -> {
return JsonHelper.read(resultSet.getString(1), clazz);
}).first();
}
}
代码示例来源:origin: rakam-io/rakam
public Optional<WebUser> getUser(int id) {
List<WebUser.Project> projectDefinitions;
try (Handle handle = dbi.open()) {
final Map<String, Object> data = handle
.createQuery("SELECT id, name, email, read_only, created_at FROM web_user WHERE id = :id")
.bind("id", id).first();
if (data == null) {
return Optional.empty();
}
String name = (String) data.get("name");
String email = (String) data.get("email");
Timestamp createdAt = (Timestamp) data.get("created_at");
id = (int) data.get("id");
projectDefinitions = getUserApiKeys(handle, id);
return Optional.of(new WebUser(id, email, name,
(Boolean) data.get("read_only"), createdAt.toInstant(), generateIntercomHash(email), projectDefinitions));
}
}
代码示例来源:origin: rakam-io/rakam
public Optional<WebUser> getUserByEmail(String email) {
List<WebUser.Project> projectDefinitions;
try (Handle handle = dbi.open()) {
final Map<String, Object> data = handle
.createQuery("SELECT id, name, read_only, created_at FROM web_user WHERE lower(email) = lower(:email)")
.bind("email", email).first();
if (data == null) {
return Optional.empty();
}
String name = (String) data.get("name");
int id = (int) data.get("id");
boolean readOnly = (boolean) data.get("read_only");
Timestamp createdAt = (Timestamp) data.get("created_at");
projectDefinitions = getUserApiKeys(handle, id);
return Optional.of(new WebUser(id, email, name, readOnly, createdAt.toInstant(), generateIntercomHash(email), projectDefinitions));
}
}
代码示例来源:origin: rakam-io/rakam
public <T> T get(Handle handle, @Named("user_id") UIPermissionParameterProvider.Project project, @ApiParam("name") String name) {
return (T) handle.createQuery("SELECT value FROM ui_user_defaults WHERE user_id = :user AND project_id = :project AND name = :name")
.bind("project", project.project)
.bind("user", project.userId)
.bind("name", name.toUpperCase(Locale.ENGLISH))
.map((index, r, ctx) -> {
return JsonHelper.read(r.getString(1), Object.class);
}).first();
}
代码示例来源:origin: rakam-io/rakam
public Map<String, String> get(int project, String slug) {
try (Handle handle = dbi.open()) {
return handle.createQuery("SELECT data FROM custom_page WHERE project_id = :project AND slug = :slug")
.bind("project", project)
.bind("slug", slug)
.map((i, resultSet, statementContext) -> {
return JsonHelper.read(resultSet.getString(1), Map.class);
}).first();
}
}
代码示例来源:origin: rakam-io/rakam
public ABTestingReport get(String project, int id) {
try (Handle handle = dbi.open()) {
return handle.createQuery("SELECT id, name, variants, collection_name, connector_field, goals, options " +
"FROM ab_testing WHERE project = :project AND id = :id")
.bind("project", project)
.bind("id", id).map(mapper).first();
}
}
代码示例来源:origin: rakam-io/rakam
public Lock tryLock(String name, int tryCount) {
Boolean first;
try {
first = currentHandle.createQuery("select get_lock(:name, 1)")
.bind("name", name)
.map(BooleanMapper.FIRST)
.first();
} catch (Exception e) {
synchronized (this) {
currentHandle.createQuery("select release_lock(:name)")
.bind("name", name)
.map(BooleanMapper.FIRST)
.first();
};
内容来源于网络,如有侵权,请联系作者删除!