Module io.ebean.api
Package io.ebean

Interface RowMapper<T>

Type Parameters:
T - The type the row data is mapped into.
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 RowMapper<T>
Used with SqlQuery to map raw JDBC ResultSet to objects.

This provides a low level mapping option with direct use of JDBC ResultSet with the option of having logic in the mapping. For example, only map some columns depending on the values read from other columns.

For straight mapping into beans then DtoQuery would be the first choice as it can automatically map the ResultSet into beans.



    //
    // Map from ResultSet to CustomerDto bean
    //
    class CustomerMapper implements RowMapper<CustomerDto> {

     @Override
     public CustomerDto map(ResultSet rset, int rowNum) throws SQLException {

       long id = rset.getLong(1);
       String name = rset.getString(2);
       String status = rset.getString(3);

       return new CustomerDto(id, name, status);
     }
   }


   //
   // Then use the mapper
   //

   String sql = "select id, name, status from o_customer where name = ?";

  CustomerDto rob = DB.sqlQuery(sql)
    .setParameter(1, "Rob")
    .mapTo(CUSTOMER_MAPPER)
    .findOne();


 
  • Method Summary

    Modifier and Type
    Method
    Description
    map(ResultSet resultSet, int rowNum)
    Read the data from the ResultSet and map to the return type.
  • Method Details

    • map

      T map(ResultSet resultSet, int rowNum) throws SQLException
      Read the data from the ResultSet and map to the return type.
      Parameters:
      resultSet - The JDBC ResultSet positioned to the current row
      rowNum - The number of the current row being mapped.
      Throws:
      SQLException