Issue Details (XML | Word | Printable)

Key: SPR-4320
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Eric Miles
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Parameterized SingleColumnRowMapper

Created: 10/Jan/08 07:13 PM   Updated: 14/Jan/08 07:49 AM
Component/s: SpringCORE
Affects Version/s: 2.5 final
Fix Version/s: 2.5.2

Time Tracking:
Not Specified

File Attachments: 1. Java Source File ParameterizedSingleColumnRowMapper.java (1 kB)



 Description  « Hide
I looked all over but couldn't find one, but it would be nice if there was a parameterized single column row mapper in Spring. There is one available for the non-java 5 code base, but there isn't one with use for generics. I've written one that simply wraps the SingleColumnRowMapper but I thought framework should contain such a class.

I can provide my class if you like but it was very easy to implement (~35 lines of code).



 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 13/Jan/08 01:30 PM
What benefit would a generified version of SingleColumnRowMapper have? The mapRow method itself doesn't matter since it's pre-implemented and invoked by JdbcTemplate... The "requiredType" has to be specified in any case... I'm afraid I'm not getting it

Juergen


Eric Miles added a comment - 13/Jan/08 06:56 PM
As is, I do not think there is a way to call SimpleJdbcTemplate.query() with a SingleColumnRowMapper. These are the following methods:

SimpleJdbcTemplate.java:

public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map args) throws DataAccessException {

I can not call any of these methods with the SingleColumnRowMapper used for the row mapper. Is there another way to do what I want to do?


Juergen Hoeller added a comment - 14/Jan/08 05:38 AM
Fair enough! I haven't thought of the SimpleJdbcTemplate signature issue there...

I guess we'll indeed have to provide a ParameterizedSingleColumnRowMapper subclass there... Even if the result might not be entirely satisfying either, since you'll have to specify the expected type twice - once for the parameterized type, once as constructor argument for the RowMapper impl...

Juergen


Eric Miles added a comment - 14/Jan/08 06:31 AM
Juergen,

I actually followed the ParameterizedBeanPropertyRowMapper and that you only have to specify the type once. I'm attaching my implementation. Thanks for looking into this.


Juergen Hoeller added a comment - 14/Jan/08 07:49 AM
I've added such a ParameterizedSingleColumnRowMapper for Spring 2.5.2, although in a slightly different fashion: It is implemented as a subclass of SingleColumnRowMapper now, in order to preserve the same public/protected methods.

I've made sure to make this analogous to BeanPropertyRowMapper, which I've revised to follow to exact same pattern now.

Juergen