T - the mapped typepublic final class JdbcTemplateMapper<T> extends Object implements org.springframework.jdbc.core.RowMapper<T>, org.springframework.jdbc.core.PreparedStatementCallback<List<T>>, org.springframework.jdbc.core.ResultSetExtractor<List<T>>
It implements RowMapper, PreparedStatementCallback and ResultSetExtractor.
Because some JdbcTemplate template signature match against a few of those type you might need to downcast, declare the variable with a specific type or use the type specific method in JdbcTemplateMapperFactory.
class MyDao {
private final JdbcTemplateMapper<DbObject> jdbcMapper =
JdbcTemplateMapperFactory.newInstance().newMapper(DbObject.class);
private final RowMapper<DbObject> rowMapper = jdbcMapper;
public void doSomething() {
List<DbObject> results = template.query(DbHelper.TEST_DB_OBJECT_QUERY, rowMapper);
}
public void doSomethingElse() {
template
.query(TEST_DB_OBJECT_QUERY,
jdbcMapper.newResultSetExtractor((o) -> System.out.println(o.toString())));
}
}
JdbcMapperFactory,
JdbcMapper,
JdbcTemplateMapperFactory.newPreparedStatementCallback(Class),
JdbcTemplateMapperFactory.newResultSetExtractor(Class),
JdbcTemplateMapperFactory.newRowMapper(Class)| Constructor and Description |
|---|
JdbcTemplateMapper(org.sfm.jdbc.JdbcMapper<T> mapper) |
| Modifier and Type | Method and Description |
|---|---|
List<T> |
doInPreparedStatement(PreparedStatement ps) |
List<T> |
extractData(ResultSet rs) |
T |
mapRow(ResultSet rs,
int rowNum) |
<H extends org.sfm.utils.RowHandler<T>> |
newPreparedStatementCallback(H handler) |
<H extends org.sfm.utils.RowHandler<T>> |
newResultSetExtractor(H handler) |
public JdbcTemplateMapper(org.sfm.jdbc.JdbcMapper<T> mapper)
public T mapRow(ResultSet rs, int rowNum) throws SQLException
mapRow in interface org.springframework.jdbc.core.RowMapper<T>SQLExceptionpublic List<T> doInPreparedStatement(PreparedStatement ps) throws SQLException, org.springframework.dao.DataAccessException
doInPreparedStatement in interface org.springframework.jdbc.core.PreparedStatementCallback<List<T>>SQLExceptionorg.springframework.dao.DataAccessExceptionpublic List<T> extractData(ResultSet rs) throws SQLException, org.springframework.dao.DataAccessException
extractData in interface org.springframework.jdbc.core.ResultSetExtractor<List<T>>SQLExceptionorg.springframework.dao.DataAccessExceptionpublic <H extends org.sfm.utils.RowHandler<T>> org.springframework.jdbc.core.PreparedStatementCallback<H> newPreparedStatementCallback(H handler)
public <H extends org.sfm.utils.RowHandler<T>> org.springframework.jdbc.core.ResultSetExtractor<H> newResultSetExtractor(H handler)
Copyright © 2016. All rights reserved.