use of io.vertx.ext.sql.ResultSet in project vertx-openshift-it by cescoffier.
the class QueryWithParamsTest method handle.
@Override
public void handle(RoutingContext rc) {
jdbcClient.getConnection(ar -> {
if (ar.failed()) {
fail(rc, ar.cause());
return;
}
SQLConnection connection = ar.result();
rc.response().bodyEndHandler(v -> {
connection.close();
});
connection.queryWithParams("select name from person where id=?", new JsonArray().add(2), res -> {
if (res.failed()) {
fail(rc, res.cause());
return;
}
ResultSet resultSet = res.result();
if (!resultSet.getResults().get(0).getString(0).equals("titi")) {
fail(rc, resultSet.getResults().get(0).getString(0));
} else {
rc.response().setStatusCode(200).end();
}
});
});
}
use of io.vertx.ext.sql.ResultSet in project vertx-openshift-it by cescoffier.
the class StoredProcedureTest method handle.
@Override
public void handle(RoutingContext rc) {
jdbcClient.getConnection(ar -> {
if (ar.failed()) {
fail(rc, ar.cause());
return;
}
SQLConnection connection = ar.result();
rc.response().bodyEndHandler(v -> {
connection.close();
});
String statsFunc = "{ call animal_stats(?, ?, ?) }";
connection.callWithParams(statsFunc, new JsonArray().add(false), new JsonArray().addNull().add("BIGINT").add("REAL"), sres -> {
if (sres.failed()) {
fail(rc, sres.cause());
return;
}
ResultSet statsResult = sres.result();
JsonArray output = statsResult.getOutput();
if (output == null) {
fail(rc, "output is null");
return;
}
if (output.size() != 3) {
fail(rc, output.toString());
return;
}
if (output.getValue(0) != null) {
fail(rc, output.toString());
return;
}
if (output.getLong(1) != 3) {
fail(rc, output.toString());
return;
}
BigDecimal bigDecimal = new BigDecimal(output.getDouble(2)).setScale(2, RoundingMode.HALF_UP);
if (!bigDecimal.equals(new BigDecimal("33.33"))) {
fail(rc, output.toString());
return;
}
String loadFunc = "{ call load_animals(?) }";
connection.callWithParams(loadFunc, new JsonArray().add(true), new JsonArray(), lres -> {
if (lres.failed()) {
fail(rc, lres.cause());
return;
}
ResultSet loadResult = lres.result();
List<JsonArray> results = loadResult.getResults();
if (results.size() != 2) {
fail(rc, results.toString());
return;
}
if (!loadResult.getColumnNames().equals(Arrays.asList("id", "name"))) {
fail(rc, results.toString());
return;
}
List<String> names = results.stream().map(array -> array.getString(1)).collect(toList());
if (!names.equals(Arrays.asList("dog", "cat"))) {
fail(rc, results.toString());
return;
}
rc.response().setStatusCode(200).end();
});
});
});
}
use of io.vertx.ext.sql.ResultSet in project mod-inventory-storage by folio-org.
the class StorageTestSuite method getRecordsWithUnmatchedIds.
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_inventory_storage", tableName);
dbClient.select(sql, result -> {
if (result.succeeded()) {
selectCompleted.complete(result.result());
} else {
selectCompleted.completeExceptionally(result.cause());
}
});
return selectCompleted.get(5, TimeUnit.SECONDS);
}
use of io.vertx.ext.sql.ResultSet in project okapi by folio-org.
the class PostgresTable method getAll.
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));
}
});
}
use of io.vertx.ext.sql.ResultSet in project okapi by folio-org.
the class TenantStorePostgres method updateModules.
@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);
}
}
});
}
Aggregations