use of io.vertx.sqlclient.RowSet in project raml-module-builder by folio-org.
the class PostgresClientIT method updateWithWhereClauseSqlConnection.
@Test
public void updateWithWhereClauseSqlConnection(TestContext context) {
String where = "WHERE jsonb->>'key'='x'";
createFoo(context).save(FOO, xPojo, context.asyncAssertSuccess(save -> {
postgresClient.getSQLConnection(conn -> {
postgresClient.update(conn, FOO, singleQuotePojo, "jsonb", where, true, context.asyncAssertSuccess(rowSet -> {
assertThat(rowSet.rowCount(), is(1));
postgresClient.update(conn, FOO, xPojo, "jsonb", where, true, context.asyncAssertSuccess(rowSet2 -> {
assertThat(rowSet2.rowCount(), is(0));
}));
}));
});
}));
}
use of io.vertx.sqlclient.RowSet in project raml-module-builder by folio-org.
the class PostgresClientIT method saveBatchJsonConnection.
@Test
public void saveBatchJsonConnection(TestContext context) {
String id = randomUuid();
JsonArray update = new JsonArray().add(new JsonObject().put("id", id).put("key", "y").encode());
createFoo(context).save(FOO, id, new StringPojo("x"), context.asyncAssertSuccess(x -> {
postgresClient.getSQLConnection(sqlConnection -> {
postgresClient.saveBatch(sqlConnection, FOO, update, context.asyncAssertFailure(e -> {
postgresClient.upsertBatch(sqlConnection, FOO, update, context.asyncAssertSuccess(rowSet -> {
postgresClient.getById(FOO, id, context.asyncAssertSuccess(json -> {
assertThat(rowSet.iterator().next().getUUID(0).toString(), is(id));
assertThat(json.getString("key"), is("y"));
}));
}));
}));
});
}));
}
use of io.vertx.sqlclient.RowSet in project raml-module-builder by folio-org.
the class PostgresClientIT method postgresClientConnectionThrowsException.
/**
* @return a PostgresClient where invoking SQLConnection::update(...) or SQLConnection::updateWithParams
* throws an RuntimeException.
*/
private PostgresClient postgresClientConnectionThrowsException() {
PgConnection pgConnection = new PgConnection() {
@Override
public PgConnection notificationHandler(Handler<PgNotification> handler) {
throw new RuntimeException();
}
@Override
public PgConnection cancelRequest(Handler<AsyncResult<Void>> handler) {
throw new RuntimeException();
}
@Override
public int processId() {
throw new RuntimeException();
}
@Override
public int secretKey() {
throw new RuntimeException();
}
@Override
public PgConnection prepare(String s, Handler<AsyncResult<PreparedStatement>> handler) {
throw new RuntimeException();
}
@Override
public Future<PreparedStatement> prepare(String s) {
return null;
}
@Override
public SqlConnection prepare(String sql, PrepareOptions options, Handler<AsyncResult<PreparedStatement>> handler) {
return null;
}
@Override
public Future<PreparedStatement> prepare(String s, PrepareOptions prepareOptions) {
return null;
}
@Override
public PgConnection exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public PgConnection closeHandler(Handler<Void> handler) {
return null;
}
@Override
public void begin(Handler<AsyncResult<Transaction>> handler) {
}
@Override
public Future<Transaction> begin() {
return null;
}
@Override
public boolean isSSL() {
return false;
}
@Override
public void close(Handler<AsyncResult<Void>> handler) {
close().onComplete(handler);
}
@Override
public Future<Void> close() {
return Future.succeededFuture();
}
@Override
public Query<RowSet<Row>> query(String s) {
throw new RuntimeException();
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s, PrepareOptions options) {
throw new RuntimeException();
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s) {
throw new RuntimeException();
}
@Override
public DatabaseMetadata databaseMetadata() {
throw new RuntimeException();
}
};
PgPool client = new PgPoolBase() {
@Override
public Future<SqlConnection> getConnection() {
return Future.succeededFuture(pgConnection);
}
};
try {
PostgresClient postgresClient = new PostgresClient(vertx, TENANT);
postgresClient.setClient(client);
return postgresClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.vertx.sqlclient.RowSet in project raml-module-builder by folio-org.
the class PostgresClientIT method executeList.
@Test
public void executeList(TestContext context) {
Async async = context.async();
JsonArray ids = new JsonArray().add(randomUuid()).add(randomUuid());
List<Tuple> list = new ArrayList<>(2);
list.add(Tuple.of(UUID.fromString(ids.getString(0))));
list.add(Tuple.of(UUID.fromString(ids.getString(1))));
insertXAndSingleQuotePojo(context, ids).execute("DELETE FROM tenant_raml_module_builder.foo WHERE id=$1", list, res -> {
assertSuccess(context, res);
List<RowSet<Row>> result = res.result();
context.assertEquals(2, result.size());
context.assertEquals(1, result.get(0).rowCount());
context.assertEquals(1, result.get(1).rowCount());
async.complete();
});
}
use of io.vertx.sqlclient.RowSet in project raml-module-builder by folio-org.
the class PostgresClientIT method selectReturnOneRow.
@Test
public void selectReturnOneRow(TestContext context) {
List<String> columns = new LinkedList<>();
columns.add("field");
RowDesc rowDesc = new RowDesc(columns);
List<Row> rows = new LinkedList<>();
Row row = new RowImpl(rowDesc);
row.addString("value");
rows.add(row);
RowSet rowSet = new LocalRowSet(1).withColumns(columns).withRows(rows);
Promise<RowSet<Row>> promise = Promise.promise();
promise.complete(rowSet);
PostgresClient.selectReturn(promise.future(), context.asyncAssertSuccess(res -> context.assertEquals("value", res.getString(0))));
}
Aggregations