Search in sources :

Example 1 with ResultSetEnumarable

use of org.simpleflatmapper.jdbc.impl.ResultSetEnumarable in project SimpleFlatMapper by arnaudroger.

the class DiscriminatorJdbcBuilder method mapper.

/**
 * @return a new jdbcMapper based on the current state
 */
public JdbcMapper<T> mapper() {
    List<DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>> mappers = new ArrayList<DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>>();
    for (DiscriminatorJdbcSubBuilder subBuilder : builders) {
        JdbcMapper<T> mapper = subBuilder.createMapper();
        Predicate<ResultSet> predicate = new ResultSetDiscriminatorPredicate(column, subBuilder.predicate);
        mappers.add(new DiscriminatorMapper.PredicatedMapper<ResultSet, ResultSet, T, SQLException>(predicate, mapper, mapper));
    }
    DiscriminatorJdbcMapper<T> discriminatorMapper = new DiscriminatorJdbcMapper<T>(mappers, new UnaryFactory<ResultSet, Enumarable<ResultSet>>() {

        @Override
        public Enumarable<ResultSet> newInstance(ResultSet resultSet) {
            return new ResultSetEnumarable(resultSet);
        }
    }, UncheckedConverterHelper.<ResultSet, String>toUnchecked(new Converter<ResultSet, String>() {

        @Override
        public String convert(ResultSet in) throws SQLException {
            return column + ":" + in.getObject(column);
        }
    }), jdbcMapperFactory.consumerErrorHandler());
    return discriminatorMapper;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DiscriminatorMapper(org.simpleflatmapper.map.mapper.DiscriminatorMapper) ResultSetEnumarable(org.simpleflatmapper.jdbc.impl.ResultSetEnumarable) Enumarable(org.simpleflatmapper.util.Enumarable) ResultSetEnumarable(org.simpleflatmapper.jdbc.impl.ResultSetEnumarable) ResultSet(java.sql.ResultSet) UncheckedConverter(org.simpleflatmapper.converter.UncheckedConverter) Converter(org.simpleflatmapper.converter.Converter)

Aggregations

ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Converter (org.simpleflatmapper.converter.Converter)1 UncheckedConverter (org.simpleflatmapper.converter.UncheckedConverter)1 ResultSetEnumarable (org.simpleflatmapper.jdbc.impl.ResultSetEnumarable)1 DiscriminatorMapper (org.simpleflatmapper.map.mapper.DiscriminatorMapper)1 Enumarable (org.simpleflatmapper.util.Enumarable)1