Skip to content

Instantly share code, notes, and snippets.

@vietj
Last active July 31, 2020 09:16
Show Gist options
  • Save vietj/b8b609bf5227e7ae0ff21f05be56c993 to your computer and use it in GitHub Desktop.
Save vietj/b8b609bf5227e7ae0ff21f05be56c993 to your computer and use it in GitHub Desktop.
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)
.compose(upstream -> e == null ? upstream : upstream.flatMap(names -> Single.error(e)))
.compose(SQLClientHelper.txSingleTransformer(conn))
.flatMap(names -> rxAssertAutoCommit(conn).andThen(Single.just(names)))
.doFinally(conn::close);
});
}
private Single<List<String>> withTransaction(Exception e) {
return client.rxWithTransaction((Function<SqlClient, Single<List<String>>>) sqlClient ->
rxInsertExtraFolks(sqlClient)
.flatMapPublisher(res -> uniqueNames(sqlClient))
.<List<String>>collect(ArrayList::new, List::add)
.compose(upstream -> e == null ? upstream : upstream.flatMap(names -> Single.error(e))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment