Interface ColumnMapper<R>

  • Type Parameters:
    R - The type of object this ColumnMapper yields from a ResultSet
    All Known Subinterfaces:
    BasicColumnMapper<R>, NullableColumnMapper<R>
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ColumnMapper<R>
    A ColumnMapper differ from a RowMapper in that it is also given a column label/name together with the ResultSet, which can be used to process specific column(s). Typically, a ColumnMapper defines how a extract the value from a certain type of columns, say INT, VARCHAR, or TIMESTAMP columns. Mappers for these value types and other common basic mappers can be found in the Mappers class. A ColumnMapper can be specialized to handle one specific column with forColumn(Attribute), which turns it into a RowMapper.
    See Also:
    BasicColumnMapper, NullableColumnMapper
    • Method Detail

      • map

        R map​(String name,
              ResultSet resultSet)
        throws SQLException
        Extract a value from a ResultSet based on the given name. Usually the name is the column name, or column label if an SQL AS clause was used in the query. The given ResultSet is expected to be positioned at the "current" row, i.e. the ColumnMapper is not expected to be required to do any cursor placement before doing any value extraction.
        Parameters:
        name - the name of the value to extract, usually the column name, or column label if an SQL AS clause was used in the query.
        resultSet - the ResultSet to extract from.
        Returns:
        The reulting extracted value.
        Throws:
        SQLException - if any error happens when processing the ResultSet. May be if the name/label is not valid, if a database access error occurs, or this method is called on a closed result set.
      • forColumn

        default AttributeMapper<R> forColumn​(Attribute<R> attribute)
        Associate the column mapper with an Attribute. This will create a row mapper for the column named by the given attribute.
        Returns:
        a new AttributeMapper, which is a row mapper.