Interface JdbcMapper<T>

Type Parameters:
T - the type that the jdbcMapper is mapping to
All Superinterfaces:
org.simpleflatmapper.map.ContextualSourceMapper<ResultSet,T>, org.simpleflatmapper.map.EnumerableMapper<ResultSet,T,SQLException>, org.simpleflatmapper.map.context.MappingContextFactoryFromRows<ResultSet,ResultSet,SQLException>, org.simpleflatmapper.map.SetRowMapper<ResultSet,ResultSet,T,SQLException>, org.simpleflatmapper.map.SourceMapper<ResultSet,T>
All Known Subinterfaces:
DynamicJdbcMapper<T>
All Known Implementing Classes:
JdbcMapperFactory.DynamicJdbcSetRowMapper

public interface JdbcMapper<T> extends org.simpleflatmapper.map.SetRowMapper<ResultSet,ResultSet,T,SQLException>, org.simpleflatmapper.map.context.MappingContextFactoryFromRows<ResultSet,ResultSet,SQLException>
JdbcMapper will map from a ResultSet to an object of the specified type T

JdbcMapper are instantiable via JdbcMapperFactory.

JdbcMapper<MyClass> jdbcMapper = JdbcMapperFactory.newInstance().newMapper(MyClass.class);

...

try (ResultSet rs : ps.executeQuery()){
    jdbcMapper.stream(rs).forEach(System.out::println);
}

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>>
    H
    forEach(ResultSet rs, H handler)
    Loop over the resultSet, map each row to a new newInstance of T and call back the handler.
     
    map the current row of the ResultSet to a new newInstance of T.
     

    Methods inherited from interface org.simpleflatmapper.map.EnumerableMapper

    enumerate

    Methods inherited from interface org.simpleflatmapper.map.context.MappingContextFactoryFromRows

    newMappingContext

    Methods inherited from interface org.simpleflatmapper.map.SourceMapper

    map
  • Method Details

    • map

      T map(ResultSet rs) throws org.simpleflatmapper.map.MappingException
      map the current row of the ResultSet to a new newInstance of T. This method does not manage the iteration of the ResultSet and will only map the current row. No join aggregation will be performed.
      Specified by:
      map in interface org.simpleflatmapper.map.ContextualSourceMapper<ResultSet,T>
      Parameters:
      rs - the resultSet
      Returns:
      a new mapped newInstance of T
      Throws:
      org.simpleflatmapper.map.MappingException - if an exception occurs
    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(ResultSet rs, H handler) throws SQLException, org.simpleflatmapper.map.MappingException
      Loop over the resultSet, map each row to a new newInstance of T and call back the handler.

      The method will return the handler passed as an argument so you can easily chain the calls like
      List<T> list = jdbcMapper.forEach(rs, new ListHandler<T>()).getList();

      Specified by:
      forEach in interface org.simpleflatmapper.map.EnumerableMapper<ResultSet,T,SQLException>
      Type Parameters:
      H - the row handler type
      Parameters:
      rs - the resultSet
      handler - the handler that will get the callback
      Returns:
      the handler passed in
      Throws:
      SQLException - if sql error occurs
      org.simpleflatmapper.map.MappingException - if an error occurs during the mapping
    • iterator

      Iterator<T> iterator(ResultSet rs) throws SQLException, org.simpleflatmapper.map.MappingException
      Specified by:
      iterator in interface org.simpleflatmapper.map.EnumerableMapper<ResultSet,T,SQLException>
      Parameters:
      rs - the result set
      Returns:
      an iterator that will return a map object for each row of the result set.
      Throws:
      SQLException - if sql error occurs
      org.simpleflatmapper.map.MappingException - if an error occurs during the mapping
    • stream

      Stream<T> stream(ResultSet rs) throws SQLException, org.simpleflatmapper.map.MappingException
      Specified by:
      stream in interface org.simpleflatmapper.map.EnumerableMapper<ResultSet,T,SQLException>
      Parameters:
      rs - the result set
      Returns:
      a stream that will contain a map object for each row of the result set.
      Throws:
      SQLException - if sql error occurs
      org.simpleflatmapper.map.MappingException - if an error occurs during the mapping