public
classRowMapperResultReader
implements
ResultReader
Overview
Inheritance
Members
Usage
Source
Books
Since1.0.2
VersionNot specified.
Author(s)Juergen Hoeller
Adapter implementation of the ResultReader interface that delegates to
a RowMapper which is supposed to create an object for each row.
Each object is added to the results list of this ResultReader.
Useful for the typical case of one object per row in the database table.
The number of entries in the results list will match the number of rows.
Note that a RowMapper object is typically stateless and thus reusable;
just the RowMapperResultReader adapter is stateful.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
RowMapper rowMapper = new UserRowMapper(); // reusable object
List allUsers = jdbcTemplate.query("select * from user", new RowMapperResultReader(rowMapper, 10));
List userResults = jdbcTemplate.query("select * from user where id=?", new Object[] {id},
new RowMapperResultReader(rowMapper, 1));
User user = (User) DataAccessUtils.uniqueResult(userResults);
Alternatively, consider subclassing MappingSqlQuery from the jdbc.object
package: Instead of working with separate JdbcTemplate and RowMapper objects,
you can have executable query objects (containing row-mapping logic) there.
Useful for the typical case of one object per row in the database table. The number of entries in the results list will match the number of rows.
Note that a RowMapper object is typically stateless and thus reusable; just the RowMapperResultReader adapter is stateful.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object RowMapper rowMapper = new UserRowMapper(); // reusable object List allUsers = jdbcTemplate.query("select * from user", new RowMapperResultReader(rowMapper, 10)); List userResults = jdbcTemplate.query("select * from user where id=?", new Object[] {id}, new RowMapperResultReader(rowMapper, 1)); User user = (User) DataAccessUtils.uniqueResult(userResults);Alternatively, consider subclassing MappingSqlQuery from the jdbc.object package: Instead of working with separate JdbcTemplate and RowMapper objects, you can have executable query objects (containing row-mapping logic) there.