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

org.panteleyev.mysqlapi.DataReaders Maven / Gradle / Ivy

The newest version!
/*
 Copyright (c) Petr Panteleyev. All rights reserved.
 Licensed under the BSD license. See LICENSE file in the project root for full license information.
 */
package org.panteleyev.mysqlapi;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Date;
import java.util.UUID;
import java.util.function.BiFunction;

interface DataReaders {
    BiFunction OBJECT_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getObject(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction BOOL_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getBoolean(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction BIG_DECIMAL_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getBigDecimal(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction INT_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getInt(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction LONG_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getLong(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction DATE_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getObject(name) == null ? null : new Date(rs.getLong(name));
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction LOCAL_DATE_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getObject(name) == null ? null : LocalDate.ofEpochDay(rs.getLong(name));
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction BYTE_ARRAY_READER = (ResultSet rs, String name) -> {
        try {
            return rs.getBytes(name);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };

    BiFunction UUID_STRING_READER = (ResultSet rs, String name) -> {
        try {
            var uuid = rs.getString(name);
            return uuid == null ? null : UUID.fromString(uuid);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    };
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy