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 RowMapperResultSetExtractor adapter is stateful.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
RowMapper rowMapper = new UserRowMapper(); // reusable object
List allUsers = (List) jdbcTemplate.query(
"select * from user",
new RowMapperResultSetExtractor(rowMapper, 10));
User user = (User) jdbcTemplate.queryForObject(
"select * from user where id=?", new Object[] {id},
new RowMapperResultSetExtractor(rowMapper, 1));
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.
RowMapper, JdbcTemplate, org.springframework.jdbc.object.MappingSqlQuery
| Modifier and Type | Field and Description |
|---|---|
| private final RowMapper | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | RowMapperResultSetExtractor(RowMapper<T>
the RowMapper which creates an object for each row rowMapper)Create a new RowMapperResultSetExtractor. |
| public | RowMapperResultSetExtractor(RowMapper<T>
the RowMapper which creates an object for each row rowMapper, int the number of expected rows
(just used for optimized collection handling) rowsExpected)Create a new RowMapperResultSetExtractor. |
| Modifier and Type | Method and Description |
|---|---|
| public List | extractData(ResultSet
the ResultSet to extract data from. Implementations should
not close this: it will be closed by the calling JdbcTemplate. rs)Implements org. |
| rowMapper | back to summary |
|---|---|
| private final RowMapper<T> rowMapper | |
| rowsExpected | back to summary |
|---|---|
| private final int rowsExpected | |
| RowMapperResultSetExtractor | back to summary |
|---|---|
| public RowMapperResultSetExtractor(RowMapper<T> rowMapper) Create a new RowMapperResultSetExtractor.
| |
| RowMapperResultSetExtractor | back to summary |
|---|---|
| public RowMapperResultSetExtractor(RowMapper<T> rowMapper, int rowsExpected) Create a new RowMapperResultSetExtractor.
| |
| extractData | back to summary |
|---|---|
| public List Implements org. Doc from org. Implementations must implement this method to process the entire ResultSet.
| |