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

ru.tinkoff.kora.database.r2dbc.R2dbcModule Maven / Gradle / Ivy

The newest version!
package ru.tinkoff.kora.database.r2dbc;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import ru.tinkoff.kora.common.DefaultComponent;
import ru.tinkoff.kora.database.common.DataBaseModule;
import ru.tinkoff.kora.database.r2dbc.mapper.parameter.R2dbcParameterColumnMapper;
import ru.tinkoff.kora.database.r2dbc.mapper.result.R2dbcResultColumnMapper;
import ru.tinkoff.kora.database.r2dbc.mapper.result.R2dbcResultFluxMapper;
import ru.tinkoff.kora.database.r2dbc.mapper.result.R2dbcRowMapper;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.*;
import java.util.List;
import java.util.UUID;

public interface R2dbcModule extends DataBaseModule {

    default  R2dbcResultFluxMapper> monoR2dbcResultFluxMapper(R2dbcRowMapper rowMapper) {
        return R2dbcResultFluxMapper.mono(rowMapper);
    }

    default  R2dbcResultFluxMapper, Mono>> monoListR2dbcResultFluxMapper(R2dbcRowMapper rowMapper) {
        return R2dbcResultFluxMapper.monoList(rowMapper);
    }

    default  R2dbcResultFluxMapper> fluxR2dbcResultFluxMapper(R2dbcRowMapper rowMapper) {
        return R2dbcResultFluxMapper.flux(rowMapper);
    }

    default R2dbcRowMapper stringR2dbcRowMapper() {
        return row -> row.get(0, String.class);
    }

    default R2dbcRowMapper shortR2dbcRowMapper() {
        return row -> row.get(0, Short.class);
    }

    default R2dbcRowMapper integerR2dbcRowMapper() {
        return row -> row.get(0, Integer.class);
    }

    default R2dbcRowMapper longR2dbcRowMapper() {
        return row -> row.get(0, Long.class);
    }

    default R2dbcRowMapper doubleR2dbcRowMapper() {
        return row -> row.get(0, Double.class);
    }

    default R2dbcRowMapper bigDecimalR2dbcRowMapper() {
        return row -> row.get(0, BigDecimal.class);
    }

    @DefaultComponent
    default R2dbcRowMapper bigIntegerR2dbcRowMapper() {
        return row -> row.get(0, BigInteger.class);
    }

    default R2dbcRowMapper byteArrayR2dbcRowMapper() {
        return row -> row.get(0, byte[].class);
    }

    @DefaultComponent
    default R2dbcRowMapper uuidR2dbcRowMapper() {
        return row -> row.get(0, UUID.class);
    }

    @DefaultComponent
    default R2dbcRowMapper localDateR2dbcRowMapper() {
        return row -> row.get(0, LocalDate.class);
    }

    @DefaultComponent
    default R2dbcRowMapper localTimeR2dbcRowMapper() {
        return row -> row.get(0, LocalTime.class);
    }

    @DefaultComponent
    default R2dbcRowMapper localDateTimeR2dbcRowMapper() {
        return row -> row.get(0, LocalDateTime.class);
    }

    @DefaultComponent
    default R2dbcRowMapper offsetTimeR2dbcRowMapper() {
        return row -> row.get(0, OffsetTime.class);
    }

    @DefaultComponent
    default R2dbcRowMapper offsetDateTimeR2dbcRowMapper() {
        return row -> row.get(0, OffsetDateTime.class);
    }

    // Parameter Mapper
    @DefaultComponent
    default R2dbcParameterColumnMapper bigDecimalR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, BigDecimal.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper uuidR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, UUID.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper localDateR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, LocalDate.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper LocalTimeR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, LocalTime.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper LocalDateTimeR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, LocalDateTime.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper offsetTimeR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, OffsetTime.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    @DefaultComponent
    default R2dbcParameterColumnMapper OffsetDateTimeR2dbcParameterColumnMapper() {
        return (stmt, index, o) -> {
            if (o == null) {
                stmt.bindNull(index, OffsetDateTime.class);
            } else {
                stmt.bind(index, o);
            }
        };
    }

    // Result Column Mappers
    @DefaultComponent
    default R2dbcResultColumnMapper bigDecimalR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, BigDecimal.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper uuidR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, UUID.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper localDateR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, LocalDate.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper localTimeR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, LocalTime.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper localDateTimeR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, LocalDateTime.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper offsetTimeR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, OffsetTime.class);
    }

    @DefaultComponent
    default R2dbcResultColumnMapper offsetDateTimeR2dbcResultColumnMapper() {
        return (row, label) -> row.get(label, OffsetDateTime.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy