001package io.ebean; 002 003import java.sql.ResultSet; 004import java.sql.SQLException; 005 006/** 007 * Used with SqlQuery to map raw JDBC ResultSet to objects. 008 * <p> 009 * This provides a low level mapping option with direct use of JDBC ResultSet 010 * with the option of having logic in the mapping. For example, only map some 011 * columns depending on the values read from other columns. 012 * </p> 013 * <p> 014 * For straight mapping into beans then DtoQuery would be the first choice as 015 * it can automatically map the ResultSet into beans. 016 * </p> 017 * 018 * <pre>{@code 019 * 020 * // 021 * // Map from ResultSet to CustomerDto bean 022 * // 023 * class CustomerMapper implements RowMapper<CustomerDto> { 024 * 025 * @Override 026 * public CustomerDto map(ResultSet rset, int rowNum) throws SQLException { 027 * 028 * long id = rset.getLong(1); 029 * String name = rset.getString(2); 030 * String status = rset.getString(3); 031 * 032 * return new CustomerDto(id, name, status); 033 * } 034 * } 035 * 036 * 037 * // 038 * // Then use the mapper 039 * // 040 * 041 * String sql = "select id, name, status from o_customer where name = ?"; 042 * 043 * CustomerDto rob = DB.sqlQuery(sql) 044 * .setParameter(1, "Rob") 045 * .mapTo(CUSTOMER_MAPPER) 046 * .findOne(); 047 * 048 * 049 * }</pre> 050 * 051 * @param <T> The type the row data is mapped into. 052 */ 053@FunctionalInterface 054public interface RowMapper<T> { 055 056 /** 057 * Read the data from the ResultSet and map to the return type. 058 * 059 * @param resultSet The JDBC ResultSet positioned to the current row 060 * @param rowNum The number of the current row being mapped. 061 */ 062 T map(ResultSet resultSet, int rowNum) throws SQLException; 063}