public class RowMapperResultSetExtractor extends Object
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));
Modifier and Type | Field and Description |
---|---|
protected RowMapper |
rowMapper |
protected int |
rowsExpected |
Constructor and Description |
---|
RowMapperResultSetExtractor(RowMapper rowMapper)
Create a new RowMapperResultSetExtractor.
|
RowMapperResultSetExtractor(RowMapper rowMapper,
int rowsExpected)
Create a new RowMapperResultSetExtractor.
|
Modifier and Type | Method and Description |
---|---|
Object |
extractData(ResultSet rs)
Implementations must implement this method to process the entire ResultSet.
|
protected final RowMapper rowMapper
protected final int rowsExpected
public RowMapperResultSetExtractor(RowMapper rowMapper)
rowMapper
- the RowMapper which creates an object for each rowpublic RowMapperResultSetExtractor(RowMapper rowMapper, int rowsExpected)
rowMapper
- the RowMapper which creates an object for each rowrowsExpected
- the number of expected rows
(just used for optimized collection handling)public Object extractData(ResultSet rs) throws SQLException
rs
- ResultSet to extract data from. Implementations should
not close this: it will be closed by the calling JdbcTemplate.null
if none
(the extractor will typically be stateful in the latter case).SQLException
- if a SQLException is encountered getting column
values or navigating (that is, there's no need to catch SQLException)Copyright © 2023 Liquibase.org. All rights reserved.