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

io.github.jinghui70.rainbow.dbaccess.mapper.SingleColumnFieldRowMapper Maven / Gradle / Ivy

There is a newer version: 5.2.11
Show newest version
package io.github.jinghui70.rainbow.dbaccess.mapper;

import io.github.jinghui70.rainbow.dbaccess.fieldmapper.FieldMapper;
import org.springframework.jdbc.IncorrectResultSetColumnCountException;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class SingleColumnFieldRowMapper implements RowMapper {

    private final FieldMapper fieldMapper;

    public SingleColumnFieldRowMapper(FieldMapper fieldMapper) {
        this.fieldMapper = fieldMapper;
    }

    public T mapRow(ResultSet rs, int rowNum) throws SQLException {
        // Validate column count.
        ResultSetMetaData metaData = rs.getMetaData();
        int nrOfColumns = metaData.getColumnCount();
        if (nrOfColumns != 1) {
            throw new IncorrectResultSetColumnCountException(1, nrOfColumns);
        }
        // Extract column value from JDBC ResultSet.
        return fieldMapper.formDB(rs, 1);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy