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

io.github.jinghui70.rainbow.dbaccess.fieldmapper.FieldMapper Maven / Gradle / Ivy

The newest version!
package io.github.jinghui70.rainbow.dbaccess.fieldmapper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Abstract base class for field mappers.
 */
public abstract class FieldMapper {

    /**
     * Retrieve a field value from the JDBC {@code ResultSet}.
     *
     * @param rs    JDBC {@code ResultSet} to retrieve the field from.
     * @param index Column index of the field.
     * @return The processed field value.
     * @throws SQLException If a database access error occurs.
     */
    public abstract T formDB(ResultSet rs, int index) throws SQLException;

    /**
     * Save a field value to the JDBC {@code PreparedStatement}. Derived classes need to convert the value
     * into values that the database can accept.
     *
     * @param ps         JDBC {@code PreparedStatement} to save the field to.
     * @param paramIndex Parameter index of the field.
     * @param value      The field value to save.
     * @throws SQLException If a database access error occurs.
     */
    public void saveToDB(PreparedStatement ps, int paramIndex, Object value) throws SQLException {
        ps.setObject(paramIndex, value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy