1 package org.davidmoten.rx.jdbc.callable.internal;
2
3 import java.sql.ResultSet;
4
5 import javax.annotation.Nonnull;
6
7 import org.davidmoten.rx.jdbc.CallableBuilder.CallableResultSets2Builder;
8 import org.davidmoten.rx.jdbc.Util;
9 import org.davidmoten.rx.jdbc.tuple.Tuple2;
10 import org.davidmoten.rx.jdbc.tuple.Tuple3;
11 import org.davidmoten.rx.jdbc.tuple.Tuple4;
12 import org.davidmoten.rx.jdbc.tuple.Tuple5;
13 import org.davidmoten.rx.jdbc.tuple.Tuple6;
14 import org.davidmoten.rx.jdbc.tuple.Tuple7;
15 import org.davidmoten.rx.jdbc.tuple.Tuples;
16
17 import com.github.davidmoten.guavamini.Preconditions;
18
19 import io.reactivex.functions.Function;
20
21 public interface Getter2<T1> {
22
23 <T2> CallableResultSets2Builder<T1, T2> get(Function<? super ResultSet, ? extends T2> function);
24
25 default <T2> CallableResultSets2Builder<T1, T2> getAs(@Nonnull Class<T2> cls) {
26 Preconditions.checkNotNull(cls, "cls cannot be null");
27 return get(rs -> Util.mapObject(rs, cls, 1));
28 }
29
30 default <A, B> CallableResultSets2Builder<T1, Tuple2<A, B>> getAs(@Nonnull Class<A> cls1, @Nonnull Class<B> cls2) {
31 return get(Tuples.tuple(cls1, cls2));
32 }
33
34 default <A, B, C> CallableResultSets2Builder<T1, Tuple3<A, B, C>> getAs(@Nonnull Class<A> cls1,
35 @Nonnull Class<B> cls2, @Nonnull Class<C> cls3) {
36 return get(Tuples.tuple(cls1, cls2, cls3));
37 }
38
39 default <A, B, C, D> CallableResultSets2Builder<T1, Tuple4<A, B, C, D>> getAs(@Nonnull Class<A> cls1,
40 @Nonnull Class<B> cls2, @Nonnull Class<C> cls3, @Nonnull Class<D> cls4) {
41 return get(Tuples.tuple(cls1, cls2, cls3, cls4));
42 }
43
44 default <A, B, C, D, E> CallableResultSets2Builder<T1, Tuple5<A, B, C, D, E>> getAs(@Nonnull Class<A> cls1,
45 @Nonnull Class<B> cls2, @Nonnull Class<C> cls3, @Nonnull Class<D> cls4, @Nonnull Class<E> cls5) {
46 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5));
47 }
48
49 default <A, B, C, D, E, F> CallableResultSets2Builder<T1, Tuple6<A, B, C, D, E, F>> getAs(@Nonnull Class<A> cls1,
50 @Nonnull Class<B> cls2, @Nonnull Class<C> cls3, @Nonnull Class<D> cls4, @Nonnull Class<E> cls5,
51 @Nonnull Class<F> cls6) {
52 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5, cls6));
53 }
54
55 default <A, B, C, D, E, F, G> CallableResultSets2Builder<T1, Tuple7<A, B, C, D, E, F, G>> getAs(
56 @Nonnull Class<A> cls1, @Nonnull Class<B> cls2, @Nonnull Class<C> cls3, @Nonnull Class<D> cls4,
57 @Nonnull Class<E> cls5, @Nonnull Class<F> cls6, @Nonnull Class<G> cls7) {
58 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5, cls6, cls7));
59 }
60
61 }