.flatMap(updateResult -> conn.rxUpdateWithParams("INSERT INTO colors (name) VALUES (?)", new JsonArray().add("PURPLE"))) .compose(SQLClientHelper.txSingleTransformer(conn))
@Test public void st2ToSt1() { SingleTransformer<Integer, Integer> transformer = new SingleTransformer<Integer, Integer>() { @Override public Single<Integer> apply(Single<Integer> o) { return o.map(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) { return v + 1; } }); } }; rx.Single.just(1) .compose(toV1Transformer(transformer)) .test() .assertResult(2); }
/** * Generates a {@link Single} from {@link SQLConnection} operations executed inside a transaction. * * @param client the {@link SQLClient} * @param sourceSupplier a user-provided function returning a {@link Single} generated by interacting with the given {@link SQLConnection} * @param <T> the type of the item emitted by the {@link Single} * @return a {@link Single} generated from {@link SQLConnection} operations executed inside a transaction */ public static <T> Single<T> inTransactionSingle(SQLClient client, Function<SQLConnection, Single<T>> sourceSupplier) { return usingConnectionSingle(client, conn -> sourceSupplier.apply(conn).compose(txSingleTransformer(conn))); }
/** * Generates a {@link Single} from {@link SQLConnection} operations executed inside a transaction. * * @param client the {@link SQLClient} * @param sourceSupplier a user-provided function returning a {@link Single} generated by interacting with the given {@link SQLConnection} * @param <T> the type of the item emitted by the {@link Single} * @return a {@link Single} generated from {@link SQLConnection} operations executed inside a transaction */ public static <T> Single<T> inTransactionSingle(SQLClient client, Function<SQLConnection, Single<T>> sourceSupplier) { return usingConnectionSingle(client, conn -> sourceSupplier.apply(conn).compose(txSingleTransformer(conn))); }
private Single<List<String>> inTransaction(Exception e) throws Exception { return client.rxGetConnection().flatMap(conn -> { return rxInsertExtraFolks(conn) .andThen(uniqueNames(conn)) .<List<String>>collect(ArrayList::new, List::add).toSingle() .compose(upstream -> e == null ? upstream : upstream.flatMap(names -> Single.error(e))) .compose(SQLClientHelper.txSingleTransformer(conn)) .flatMap(names -> rxAssertAutoCommit(conn).andThen(Single.just(names))) .doAfterTerminate(conn::close); }); } }