本文整理汇总了Java中io.vertx.ext.sql.ResultSet类的典型用法代码示例。如果您正苦于以下问题:Java ResultSet类的具体用法?Java ResultSet怎么用?Java ResultSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResultSet类属于io.vertx.ext.sql包,在下文中一共展示了ResultSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@GET
public Single<Template> index(){
return fiber((con) -> {
ResultSet res = await(con.rxQuery(SQL.SQL_ALL_PAGES));
List<String> pages = res.getResults()
.stream()
.map(json -> json.getString(0))
.sorted()
.collect(Collectors.toList());
boolean canCreatePage = await(user.rxIsAuthorised("create"));
return new Template("templates/index.ftl")
.set("title", "Wiki home")
.set("pages", pages)
.set("canCreatePage", canCreatePage)
.set("username", getUserName())
.set("backup_gist_url", flash.get("backup_gist_url"));
});
}
示例2: fetchPageById
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPageById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
// tag::rx-execute-query-with-params[]
Single<ResultSet> resultSet = dbClient.rxQueryWithParams(
sqlQueries.get(SqlQuery.GET_PAGE_BY_ID), new JsonArray().add(id));
// end::rx-execute-query-with-params[]
resultSet
.map(result -> {
if (result.getNumRows() > 0) {
JsonObject row = result.getRows().get(0);
return new JsonObject()
.put("found", true)
.put("id", row.getInteger("ID"))
.put("name", row.getString("NAME"))
.put("content", row.getString("CONTENT"));
} else {
return new JsonObject().put("found", false);
}
})
.subscribe(RxHelper.toSubscriber(resultHandler));
return this;
}
示例3: fetchPageById
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPageById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
Single<ResultSet> resultSet = dbClient.rxQueryWithParams(
sqlQueries.get(SqlQuery.GET_PAGE_BY_ID), new JsonArray().add(id));
resultSet
.map(result -> {
if (result.getNumRows() > 0) {
JsonObject row = result.getRows().get(0);
return new JsonObject()
.put("found", true)
.put("id", row.getInteger("ID"))
.put("name", row.getString("NAME"))
.put("content", row.getString("CONTENT"));
} else {
return new JsonObject().put("found", false);
}
})
.subscribe(RxHelper.toSubscriber(resultHandler));
return this;
}
示例4: fetchPage
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPage(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), new JsonArray().add(name), fetch -> {
if (fetch.succeeded()) {
JsonObject response = new JsonObject();
ResultSet resultSet = fetch.result();
if (resultSet.getNumRows() == 0) {
response.put("found", false);
} else {
response.put("found", true);
JsonArray row = resultSet.getResults().get(0);
response.put("id", row.getInteger(0));
response.put("rawContent", row.getString(1));
}
resultHandler.handle(Future.succeededFuture(response));
} else {
LOGGER.error("Database query error", fetch.cause());
resultHandler.handle(Future.failedFuture(fetch.cause()));
}
});
return this;
}
示例5: fetchPage
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
private void fetchPage(Message<JsonObject> message) {
String requestedPage = message.body().getString("page");
JsonArray params = new JsonArray().add(requestedPage);
dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), params, fetch -> {
if (fetch.succeeded()) {
JsonObject response = new JsonObject();
ResultSet resultSet = fetch.result();
if (resultSet.getNumRows() == 0) {
response.put("found", false);
} else {
response.put("found", true);
JsonArray row = resultSet.getResults().get(0);
response.put("id", row.getInteger(0));
response.put("rawContent", row.getString(1));
}
message.reply(response);
} else {
reportQueryError(message, fetch.cause());
}
});
}
示例6: checkForMismatchedIDs
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
static void checkForMismatchedIDs(String table) {
String tenantId = TENANT_ID;
try {
ResultSet results = getRecordsWithUnmatchedIds(
tenantId, table);
Integer mismatchedRowCount = results.getNumRows();
assertThat(mismatchedRowCount, is(0));
}
catch(Exception e) {
System.out.println(String.format(
"WARNING!!!!! Unable to determine mismatched ID rows"));
}
}
示例7: getRecordsWithUnmatchedIds
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
private static ResultSet getRecordsWithUnmatchedIds(String tenantId,
String tableName)
throws InterruptedException, ExecutionException, TimeoutException {
PostgresClient dbClient = PostgresClient.getInstance(
getVertx(), tenantId);
CompletableFuture<ResultSet> selectCompleted = new CompletableFuture();
String sql = String.format("SELECT null FROM %s_%s.%s" +
" WHERE CAST(_id AS VARCHAR(50)) != jsonb->>'id'",
tenantId, "mod_circulation_storage", tableName);
dbClient.select(sql, result -> {
if(result.succeeded()) {
selectCompleted.complete(result.result());
}
else {
selectCompleted.completeExceptionally(result.cause());
}
});
return selectCompleted.get(5, TimeUnit.SECONDS);
}
示例8: get
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public Single<JsonObject> get(long id) {
return db.rxGetConnection()
.flatMap(conn -> {
JsonArray param = new JsonArray().add(id);
return conn
.rxQueryWithParams(SELECT_ONE, param)
.map(ResultSet::getRows)
.flatMap(list -> {
if (list.isEmpty()) {
return Single.error(new NoSuchElementException("Item '" + id + "' not found"));
} else {
return Single.just(list.get(0));
}
})
.doAfterTerminate(conn::close);
});
}
示例9: testStockTradesPersisted
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Test
public void testStockTradesPersisted(TestContext context) throws ClassNotFoundException {
Async async = context.async();
JsonObject jdbcConfig = new JsonObject(config.getObject("jdbc").render(ConfigRenderOptions.concise()));
JDBCClient jdbc = JDBCClient.createNonShared(vertx, jdbcConfig);
Class.forName(jdbcConfig.getString("driverclass"));
jdbc.getConnection(ar -> {
SQLConnection connection = ar.result();
if (ar.failed()) {
context.fail(ar.cause());
} else {
connection.query(SELECT_STATEMENT, result -> {
ResultSet set = result.result();
List<JsonObject> operations = set.getRows().stream()
.map(json -> new JsonObject(json.getString("OPERATION")))
.collect(Collectors.toList());
context.assertTrue(operations.size() >= 3);
connection.close();
async.complete();
});
}
});
}
示例10: updateModules
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public void updateModules(String id, SortedMap<String, Boolean> enabled,
Handler<ExtendedAsyncResult<Void>> fut) {
logger.debug("updateModules " + Json.encode(enabled.keySet()));
PostgresQuery q = pg.getQuery();
String sql = "SELECT " + JSON_COLUMN + " FROM " + TABLE + " WHERE " + ID_SELECT;
JsonArray jsa = new JsonArray();
jsa.add(id);
q.queryWithParams(sql, jsa, res -> {
if (res.failed()) {
logger.fatal("updateModule failed: " + res.cause().getMessage());
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
ResultSet rs = res.result();
if (rs.getNumRows() == 0) {
fut.handle(new Failure<>(NOT_FOUND, "Tenant " + id + " not found"));
q.close();
} else {
logger.debug("update: replace");
updateModuleR(q, id, enabled, rs.getRows().iterator(), fut);
}
}
});
}
示例11: init
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
public void init(boolean reset, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
if (!reset) {
create(reset, q, fut);
} else {
String dropSql = "DROP TABLE IF EXISTS " + table;
q.query(dropSql, (ExtendedAsyncResult<ResultSet> res) -> {
if (res.failed()) {
logger.fatal(dropSql + ": " + res.cause().getMessage());
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
create(reset, q, fut);
}
});
}
}
示例12: getAll
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
public void getAll(Class<T> clazz, Handler<ExtendedAsyncResult<List<T>>> fut) {
PostgresQuery q = pg.getQuery();
String sql = "SELECT " + jsonColumn + " FROM " + table;
q.query(sql, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
ResultSet rs = res.result();
List<T> ml = new ArrayList<>();
List<JsonObject> tempList = rs.getRows();
for (JsonObject r : tempList) {
String tj = r.getString(jsonColumn);
T md = Json.decodeValue(tj, clazz);
ml.add(md);
}
q.close();
fut.handle(new Success<>(ml));
}
});
}
示例13: queryWithParams
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
public void queryWithParams(String sql, JsonArray jsa,
Handler<ExtendedAsyncResult<ResultSet>> fut) {
getCon(gres -> {
if (gres.failed()) {
fut.handle(new Failure<>(gres.getType(), gres.cause()));
} else {
logger.debug("queryWithParams sql: " + sql);
conn.queryWithParams(sql, jsa, qres -> {
if (qres.failed()) {
logger.fatal("queryWithParams failed: "
+ qres.cause() + " sql: " + sql);
close();
fut.handle(new Failure<>(INTERNAL, qres.cause()));
} else {
fut.handle(new Success<>(qres.result()));
}
});
}
});
}
示例14: query
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
public void query(String sql,
Handler<ExtendedAsyncResult<ResultSet>> fut) {
getCon(gres -> {
if (gres.failed()) {
fut.handle(new Failure<>(gres.getType(), gres.cause()));
} else {
logger.debug("query sql: " + sql);
conn.query(sql, qres -> {
if (qres.failed()) {
logger.fatal("query failed: "
+ qres.cause() + " sql: " + sql);
close();
fut.handle(new Failure<>(INTERNAL, qres.cause()));
} else {
fut.handle(new Success<>(qres.result()));
}
});
}
});
}
示例15: retrieveOne
import io.vertx.ext.sql.ResultSet; //导入依赖的package包/类
@Override
public Single<Optional<CartEvent>> retrieveOne(Long id) {
return client.rxGetConnection()
.flatMap(conn ->
conn.rxQueryWithParams(RETRIEVE_STATEMENT, new JsonArray().add(id))
.map(ResultSet::getRows)
.map(list -> {
if (list.isEmpty()) {
return Optional.<CartEvent>empty();
} else {
return Optional.of(list.get(0))
.map(this::wrapCartEvent);
}
})
.doAfterTerminate(conn::close)
);
}