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.TransactedCallableBuilder.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 TxGetter2<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,
31 @Nonnull Class<B> cls2) {
32 return get(Tuples.tuple(cls1, cls2));
33 }
34
35 default <A, B, C> CallableResultSets2Builder<T1, Tuple3<A, B, C>> getAs(@Nonnull Class<A> cls1,
36 @Nonnull Class<B> cls2, @Nonnull Class<C> cls3) {
37 return get(Tuples.tuple(cls1, cls2, cls3));
38 }
39
40 default <A, B, C, D> CallableResultSets2Builder<T1, Tuple4<A, B, C, D>> getAs(
41 @Nonnull Class<A> cls1, @Nonnull Class<B> cls2, @Nonnull Class<C> cls3,
42 @Nonnull Class<D> cls4) {
43 return get(Tuples.tuple(cls1, cls2, cls3, cls4));
44 }
45
46 default <A, B, C, D, E> CallableResultSets2Builder<T1, Tuple5<A, B, C, D, E>> getAs(
47 @Nonnull Class<A> cls1, @Nonnull Class<B> cls2, @Nonnull Class<C> cls3,
48 @Nonnull Class<D> cls4, @Nonnull Class<E> cls5) {
49 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5));
50 }
51
52 default <A, B, C, D, E, F> CallableResultSets2Builder<T1, Tuple6<A, B, C, D, E, F>> getAs(
53 @Nonnull Class<A> cls1, @Nonnull Class<B> cls2, @Nonnull Class<C> cls3,
54 @Nonnull Class<D> cls4, @Nonnull Class<E> cls5, @Nonnull Class<F> cls6) {
55 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5, cls6));
56 }
57
58 default <A, B, C, D, E, F, G> CallableResultSets2Builder<T1, Tuple7<A, B, C, D, E, F, G>> getAs(
59 @Nonnull Class<A> cls1, @Nonnull Class<B> cls2, @Nonnull Class<C> cls3,
60 @Nonnull Class<D> cls4, @Nonnull Class<E> cls5, @Nonnull Class<F> cls6,
61 @Nonnull Class<G> cls7) {
62 return get(Tuples.tuple(cls1, cls2, cls3, cls4, cls5, cls6, cls7));
63 }
64
65 }