All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.davidmoten.rx.jdbc.QuerySelectTransformer Maven / Gradle / Ivy

There is a newer version: 0.7.19
Show newest version
package com.github.davidmoten.rx.jdbc;

import com.github.davidmoten.rx.jdbc.QuerySelect.Builder;

import rx.Observable;
import rx.Observable.Transformer;
import rx.functions.Func1;

/**
 * Transformer corresponding to the QuerySelectOperation.
 * 
 * @param 
 */
final class QuerySelectTransformer implements Transformer {

    private final Builder builder;
    private final ResultSetMapper function;
    private final OperatorType operatorType;

    /**
     * Constructor.
     * 
     * @param builder
     * @param function
     * @param operatorType
     * @param resultSetTransform
     */
    QuerySelectTransformer(final QuerySelect.Builder builder,
            final ResultSetMapper function, final OperatorType operatorType) {
        this.builder = builder;
        this.function = function;
        this.operatorType = operatorType;
    }

    @Override
    public Observable call(Observable source) {
        if (operatorType == OperatorType.PARAMETER)
            return builder.parameters(source).get(function);
        else if (operatorType == OperatorType.DEPENDENCY)
            // dependency
            return builder.dependsOn(source).get(function);
        else // PARAMETER_LIST
        {
            @SuppressWarnings("unchecked")
            Observable> obs = (Observable>) source;
            return obs.concatMap(new Func1, Observable>() {
                @Override
                public Observable call(Observable parameters) {
                    return builder.parameters(parameters).get(function);
                }
            });
        }
    }

}