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

org.babyfish.jimmer.sql.runtime.Reader Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.runtime;

import org.babyfish.jimmer.runtime.DraftContext;
import org.babyfish.jimmer.runtime.DraftSpi;
import org.babyfish.jimmer.sql.ast.tuple.*;
import org.babyfish.jimmer.sql.dialect.Dialect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.ZoneId;

public interface Reader {

    T read(ResultSet rs, Context ctx) throws SQLException;

    final class Context {

        private DraftContext draftContext;

        private final Dialect dialect;

        private final ZoneId zoneId;

        private int col;

        public Context(@Nullable DraftContext draftContext, JSqlClientImplementor sqlClient) {
            this.draftContext = draftContext;
            this.dialect = sqlClient.getDialect();
            this.zoneId = sqlClient.getZoneId();
        }

        @NotNull
        public DraftContext draftContext() {
            DraftContext dc = draftContext;
            if (dc == null) {
                draftContext = dc = new DraftContext(null);
            }
            return dc;
        }

        public Dialect getDialect() {
            return dialect;
        }

        public ZoneId getZoneId() {
            return zoneId;
        }

        public int col() {
            return ++col;
        }
        
        public void addCol(int delta) {
            col += delta;
        }
        
        public void resetCol() {
            col = 0;
        }
        
        public Object resolve(DraftSpi spi) {
            return draftContext().resolveObject(spi);
        }
    }

    static  Reader> tuple(Reader reader1, Reader reader2) {
        return new Reader>() {
            @Override
            public Tuple2 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple2<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3
    ) {
        return new Reader>() {
            @Override
            public Tuple3 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple3<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4
    ) {
        return new Reader>() {
            @Override
            public Tuple4 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple4<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4,
            Reader reader5
    ) {
        return new Reader>() {
            @Override
            public Tuple5 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple5<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx),
                        reader5.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4,
            Reader reader5,
            Reader reader6
    ) {
        return new Reader>() {
            @Override
            public Tuple6 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple6<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx),
                        reader5.read(rs, ctx),
                        reader6.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4,
            Reader reader5,
            Reader reader6,
            Reader reader7
    ) {
        return new Reader>() {
            @Override
            public Tuple7 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple7<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx),
                        reader5.read(rs, ctx),
                        reader6.read(rs, ctx),
                        reader7.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4,
            Reader reader5,
            Reader reader6,
            Reader reader7,
            Reader reader8
    ) {
        return new Reader>() {
            @Override
            public Tuple8 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple8<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx),
                        reader5.read(rs, ctx),
                        reader6.read(rs, ctx),
                        reader7.read(rs, ctx),
                        reader8.read(rs, ctx)
                );
            }
        };
    }

    static  Reader> tuple(
            Reader reader1,
            Reader reader2,
            Reader reader3,
            Reader reader4,
            Reader reader5,
            Reader reader6,
            Reader reader7,
            Reader reader8,
            Reader reader9
    ) {
        return new Reader>() {
            @Override
            public Tuple9 read(ResultSet rs, Context ctx) throws SQLException {
                return new Tuple9<>(
                        reader1.read(rs, ctx),
                        reader2.read(rs, ctx),
                        reader3.read(rs, ctx),
                        reader4.read(rs, ctx),
                        reader5.read(rs, ctx),
                        reader6.read(rs, ctx),
                        reader7.read(rs, ctx),
                        reader8.read(rs, ctx),
                        reader9.read(rs, ctx)
                );
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy