Search in sources :

Example 1 with Emitter

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

the class Call method createFlowable.

private static <T> Flowable<T> createFlowable(NamedCallableStatement stmt, Function<? super ResultSet, ? extends T> f) throws SQLException {
    ResultSet rsActual = stmt.stmt.getResultSet();
    Callable<ResultSet> initialState = () -> rsActual;
    BiConsumer<ResultSet, Emitter<T>> generator = (rs, emitter) -> {
        log.debug("getting row from ps={}, rs={}", stmt.stmt, rs);
        if (rs.next()) {
            T v = f.apply(rs);
            log.debug("emitting {}", v);
            emitter.onNext(v);
        } else {
            log.debug("completed");
            emitter.onComplete();
        }
    };
    Consumer<ResultSet> disposeState = Util::closeSilently;
    return Flowable.generate(initialState, generator, disposeState);
}
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) Emitter(io.reactivex.Emitter) ResultSet(java.sql.ResultSet)

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