Search in sources :

Example 1 with Notification

use of io.reactivex.Notification in project rxjava2-jdbc by davidmoten.

the class Call method createWithNResultSets.

private static Flowable<Notification<CallableResultSetN>> createWithNResultSets(Connection con, String sql, Flowable<List<Object>> parameterGroups, List<ParameterPlaceholder> parameterPlaceholders, List<Function<? super ResultSet, ?>> functions, int fetchSize) {
    Callable<NamedCallableStatement> resourceFactory = () -> Util.prepareCall(con, sql, parameterPlaceholders);
    final // 
    Function<NamedCallableStatement, Flowable<Notification<CallableResultSetN>>> flowableFactory = stmt -> // 
    parameterGroups.flatMap(parameters -> {
        List<Object> outputValues = executeAndReturnOutputValues(parameterPlaceholders, stmt, parameters);
        List<Flowable<?>> flowables = Lists.newArrayList();
        int i = 0;
        do {
            Function<? super ResultSet, ?> f = functions.get(i);
            flowables.add(createFlowable(stmt, f));
            i++;
        } while (stmt.stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
        return Single.just(new CallableResultSetN(outputValues, flowables)).toFlowable();
    }).materialize().doOnComplete(// 
    () -> Util.commit(stmt.stmt)).doOnError(e -> Util.rollback(stmt.stmt));
    Consumer<NamedCallableStatement> disposer = Util::closeCallableStatementAndConnection;
    return Flowable.using(resourceFactory, flowableFactory, disposer, true);
}
Also used : BiFunction(io.reactivex.functions.BiFunction) Connection(java.sql.Connection) Tuple2(org.davidmoten.rx.jdbc.tuple.Tuple2) Tuple3(org.davidmoten.rx.jdbc.tuple.Tuple3) BiConsumer(io.reactivex.functions.BiConsumer) Tuple4(org.davidmoten.rx.jdbc.tuple.Tuple4) LoggerFactory(org.slf4j.LoggerFactory) Lists(com.github.davidmoten.guavamini.Lists) Callable(java.util.concurrent.Callable) Single(io.reactivex.Single) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Flowable(io.reactivex.Flowable) ResultSet(java.sql.ResultSet) CallableResultSet3(org.davidmoten.rx.jdbc.callable.CallableResultSet3) CallableResultSet4(org.davidmoten.rx.jdbc.callable.CallableResultSet4) CallableResultSet1(org.davidmoten.rx.jdbc.callable.CallableResultSet1) CallableResultSet2(org.davidmoten.rx.jdbc.callable.CallableResultSet2) Notification(io.reactivex.Notification) CallableResultSetN(org.davidmoten.rx.jdbc.callable.CallableResultSetN) Logger(org.slf4j.Logger) TupleN(org.davidmoten.rx.jdbc.tuple.TupleN) PreparedStatement(java.sql.PreparedStatement) Consumer(io.reactivex.functions.Consumer) Emitter(io.reactivex.Emitter) OutParameterPlaceholder(org.davidmoten.rx.jdbc.callable.internal.OutParameterPlaceholder) List(java.util.List) ParameterPlaceholder(org.davidmoten.rx.jdbc.callable.internal.ParameterPlaceholder) Function(io.reactivex.functions.Function) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) InParameterPlaceholder(org.davidmoten.rx.jdbc.callable.internal.InParameterPlaceholder) BiFunction(io.reactivex.functions.BiFunction) Function(io.reactivex.functions.Function) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) CallableResultSetN(org.davidmoten.rx.jdbc.callable.CallableResultSetN) Flowable(io.reactivex.Flowable)

Aggregations

Lists (com.github.davidmoten.guavamini.Lists)1 Emitter (io.reactivex.Emitter)1 Flowable (io.reactivex.Flowable)1 Notification (io.reactivex.Notification)1 Single (io.reactivex.Single)1 BiConsumer (io.reactivex.functions.BiConsumer)1 BiFunction (io.reactivex.functions.BiFunction)1 Consumer (io.reactivex.functions.Consumer)1 Function (io.reactivex.functions.Function)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 CallableResultSet1 (org.davidmoten.rx.jdbc.callable.CallableResultSet1)1 CallableResultSet2 (org.davidmoten.rx.jdbc.callable.CallableResultSet2)1