/** * Generates a {@link Completable} from {@link SQLConnection} operations. * * @param client the {@link SQLClient} * @param sourceSupplier a user-provided function returning a {@link Completable} generated by interacting with the given {@link SQLConnection} * @return a {@link Completable} generated from {@link SQLConnection} operations */ public static Completable usingConnectionCompletable(SQLClient client, Function<SQLConnection, Completable> sourceSupplier) { return client.rxGetConnection().flatMapCompletable(conn -> { return sourceSupplier.apply(conn).doAfterTerminate(conn::close); }); }
/** * Generates a {@link Completable} from {@link SQLConnection} operations. * * @param client the {@link SQLClient} * @param sourceSupplier a user-provided function returning a {@link Completable} generated by interacting with the given {@link SQLConnection} * @return a {@link Completable} generated from {@link SQLConnection} operations */ public static Completable usingConnectionCompletable(SQLClient client, Function<SQLConnection, Completable> sourceSupplier) { return client.rxGetConnection().flatMapCompletable(conn -> { return sourceSupplier.apply(conn).doAfterTerminate(conn::close); }); }
.flatMap(file -> { return doDownload(downloadUrl, file) .doAfterTerminate(() -> { file.flush(); file.close();
protected Completable rxAssertAutoCommit(SQLConnection conn) { String testName = UUID.randomUUID().toString(); return conn.rxExecute(String.format(INSERT_FOLK_SQL, testName)).toCompletable() .andThen(client.rxGetConnection().flatMapCompletable(other -> { return uniqueNames(other).contains(testName).toSingle() .flatMapCompletable(contains -> { if (contains) { return Completable.complete(); } return Completable.error(new AssertionError("Connection should be back in autocommit mode")); }) .doAfterTerminate(other::close); })); }
@Override public void setUp() throws Exception { super.setUp(); client = new JDBCClient(io.vertx.ext.jdbc.JDBCClient.createNonShared(vertx, config)); client.rxGetConnection().flatMapCompletable(conn -> { Completable setup = conn.rxExecute("drop table folks if exists").toCompletable() .andThen(conn.rxExecute("create table folks (firstname varchar(255) not null)").toCompletable()); for (String name : NAMES) { setup = setup.andThen(conn.rxExecute(String.format(INSERT_FOLK_SQL, name)).toCompletable()); } return setup.doAfterTerminate(conn::close); }).await(); }
private Completable inTransaction(Exception e) throws Exception { return client.rxGetConnection().flatMapCompletable(conn -> { return rxInsertExtraFolks(conn) .andThen(uniqueNames(conn)) .<List<String>>collect(ArrayList::new, List::add).toSingle() .flatMapCompletable(names -> rxAssertEquals(Arrays.asList(namesWithExtraFolks()), names)) .compose(upstream -> e == null ? upstream : upstream.andThen(Completable.error(e))) .compose(SQLClientHelper.txCompletableTransformer(conn)) .andThen(rxAssertAutoCommit(conn)) .doAfterTerminate(conn::close); }); } }