Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading from ParameterizedRowMapper to SingleColumnRowMapper for multiple columns

I'm upgrading a Spring 3 application to Spring 4. My @Repository has ParameterizedRowMapper objects to map the SQL results to objects. But since Spring 4 that interface has been deprecated "in favor of the regular SingleColumnRowMapper". But I use mappers for mapping multiple columns. How am I meant to map multiple columns using SingleColumnRowMapper? Or am I meant to be doing something completely different?

For example, here is the kind of code I have now:

    private static final ParameterizedRowMapper<Thing> THING_ENTRY_MAPPER = new ParameterizedRowMapper<Thing>() {

       @Override
       public Thing mapRow(ResultSet rs, int rowNum) throws SQLException {
          return new Thing(rs.getLong(1), rs.getLong(2), rs.getInt(3));
       }
    };


    @Override
    public List<Thing> getThings(
          ID id, long start, long end) {
       final Map<String, Object> params = new HashMap<String, Object>(4);
       putIDParams(params, id);
       putTimeRangeParams(params, start, end);
       return getNamedParameterJdbcTemplate().query(QUERY_THING, params,
             THING_ENTRY_MAPPER);
    }

How should I be implementing that kind of functionality now?

like image 359
Raedwald Avatar asked Sep 30 '14 13:09

Raedwald


1 Answers

The Javadoc seems to be wrong. The Spring Framework designers probably intend use of the RowMapper<Thing> interface to replace ParameterizedRowMapper<Thing>. That is, use the base interface.

like image 122
Raedwald Avatar answered Nov 15 '22 09:11

Raedwald