use of io.vertx.ext.sql.ResultSet in project raml-module-builder by folio-org.
the class PostgresClientIT method parallel.
@Test
public void parallel(TestContext context) {
/**
* number of parallel queries
*/
int n = 20;
/**
* sleep time in milliseconds
*/
double sleep = 150;
String selectSleep = "select pg_sleep(" + sleep / 1000 + ")";
/**
* maximum duration in milliseconds for the completion of all parallel queries
*/
long maxDuration = (long) (n * sleep / 2);
/* create n queries in parallel, each sleeping for some time.
* If vert.x properly processes them in parallel it finishes
* in less than half of the time needed for sequential processing.
*/
Async async = context.async();
PostgresClient client = PostgresClient.getInstance(vertx);
List<Future> futures = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
Future<ResultSet> future = Future.future();
client.select(selectSleep, future.completer());
futures.add(future);
}
long start = System.currentTimeMillis();
CompositeFuture.all(futures).setHandler(handler -> {
long duration = System.currentTimeMillis() - start;
client.closeClient(whenDone -> {
});
context.assertTrue(handler.succeeded());
context.assertTrue(duration < maxDuration, "duration must be less than " + maxDuration + " ms, it is " + duration + " ms");
async.complete();
});
}
use of io.vertx.ext.sql.ResultSet in project vertx-openshift-it by cescoffier.
the class CRUDTest 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 calypso = "Calypso";
connection.updateWithParams("insert into ship (name) values (?)", new JsonArray().add(calypso), ires -> {
if (ires.failed()) {
fail(rc, ires.cause());
return;
}
UpdateResult insertResult = ires.result();
if (insertResult.getUpdated() != 1) {
fail(rc, String.valueOf(insertResult.getUpdated()));
return;
}
Long calypsoId = insertResult.getKeys().getLong(0);
connection.queryWithParams("select name from ship where id = ?", new JsonArray().add(calypsoId), sres -> {
if (sres.failed()) {
fail(rc, sres.cause());
return;
}
ResultSet resultSet = sres.result();
if (!resultSet.getResults().get(0).getString(0).equals(calypso)) {
fail(rc, resultSet.getResults().get(0).getString(0));
return;
}
connection.updateWithParams("update ship set name = ? where id = ?", new JsonArray().add("Alcyone").add(calypsoId), ures -> {
if (ures.failed()) {
fail(rc, ures.cause());
return;
}
UpdateResult updateResult = ures.result();
if (updateResult.getUpdated() != 1) {
fail(rc, String.valueOf(updateResult.getUpdated()));
return;
}
connection.updateWithParams("delete from ship where id = ?", new JsonArray().add(calypsoId), dres -> {
if (dres.failed()) {
fail(rc, dres.cause());
return;
}
UpdateResult deleteResult = dres.result();
if (deleteResult.getUpdated() != 1) {
fail(rc, String.valueOf(deleteResult.getUpdated()));
} else {
rc.response().setStatusCode(200).end();
}
});
});
});
});
});
}
use of io.vertx.ext.sql.ResultSet in project mod-inventory-storage by folio-org.
the class StorageTestSuite method checkForMismatchedIDs.
static void checkForMismatchedIDs(String table) {
try {
ResultSet results = getRecordsWithUnmatchedIds(TENANT_ID, table);
Integer mismatchedRowCount = results.getNumRows();
assertThat(mismatchedRowCount, is(0));
} catch (Exception e) {
System.out.println("WARNING!!!!! Unable to determine mismatched ID rows");
}
}
use of io.vertx.ext.sql.ResultSet in project vertx-auth by vert-x3.
the class JDBCAuthImpl method executeQuery.
<T> void executeQuery(String query, JsonArray params, Handler<AsyncResult<T>> resultHandler, Consumer<ResultSet> resultSetConsumer) {
client.getConnection(res -> {
if (res.succeeded()) {
SQLConnection conn = res.result();
conn.queryWithParams(query, params, queryRes -> {
if (queryRes.succeeded()) {
ResultSet rs = queryRes.result();
resultSetConsumer.accept(rs);
} else {
resultHandler.handle(Future.failedFuture(queryRes.cause()));
}
conn.close(closeRes -> {
});
});
} else {
resultHandler.handle(Future.failedFuture(res.cause()));
}
});
}
use of io.vertx.ext.sql.ResultSet in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
JsonObject config = new JsonObject().put("url", "jdbc:hsqldb:mem:test?shutdown=true").put("driver_class", "org.hsqldb.jdbcDriver");
JDBCClient jdbc = JDBCClient.createShared(vertx, config);
// Connect to the database
jdbc.rxGetConnection().flatMap(conn -> {
// Now chain some statements using flatmap composition
Single<ResultSet> resa = conn.rxUpdate("CREATE TABLE test(col VARCHAR(20))").flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val1')")).flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val2')")).flatMap(result -> conn.rxQuery("SELECT * FROM test"));
return resa.doAfterTerminate(conn::close);
}).subscribe(resultSet -> {
// Subscribe to the final result
System.out.println("Results : " + resultSet.getRows());
}, err -> {
System.out.println("Database problem");
err.printStackTrace();
});
}
Aggregations