public abstract class AbstractLobStreamingResultSetExtractor<T> extends Object implements ResultSetExtractor<T>
Delegates to the streamData template method for streaming LOB
content to some OutputStream, typically using a LobHandler. Converts an
IOException thrown during streaming to a LobRetrievalFailureException.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
final LobHandler lobHandler = new DefaultLobHandler(); // reusable object
jdbcTemplate.query(
"SELECT content FROM imagedb WHERE image_name=?", new Object[] {name},
new AbstractLobStreamingResultSetExtractor() {
public void streamData(ResultSet rs) throws SQLException, IOException {
FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream);
}
}
);LobHandler,
LobRetrievalFailureException| Constructor and Description |
|---|
AbstractLobStreamingResultSetExtractor() |
| Modifier and Type | Method and Description |
|---|---|
T |
extractData(ResultSet rs)
Delegates to handleNoRowFound, handleMultipleRowsFound and streamData,
according to the ResultSet state.
|
protected void |
handleMultipleRowsFound()
Handle the case where the ResultSet contains multiple rows.
|
protected void |
handleNoRowFound()
Handle the case where the ResultSet does not contain a row.
|
protected abstract void |
streamData(ResultSet rs)
Stream LOB content from the given ResultSet to some OutputStream.
|
public AbstractLobStreamingResultSetExtractor()
public final T extractData(ResultSet rs) throws SQLException, DataAccessException
extractData in interface ResultSetExtractor<T>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)DataAccessException - in case of custom exceptionshandleNoRowFound(),
handleMultipleRowsFound(),
streamData(java.sql.ResultSet),
LobRetrievalFailureExceptionprotected void handleNoRowFound()
throws DataAccessException
DataAccessException - a corresponding exception,
by default an EmptyResultDataAccessExceptionEmptyResultDataAccessExceptionprotected void handleMultipleRowsFound()
throws DataAccessException
DataAccessException - a corresponding exception,
by default an IncorrectResultSizeDataAccessExceptionIncorrectResultSizeDataAccessExceptionprotected abstract void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException
Typically used as inner class, with access to surrounding method arguments and to a LobHandler instance variable of the surrounding class.
rs - the ResultSet to take the LOB content fromSQLException - if thrown by JDBC methodsIOException - if thrown by stream access methodsDataAccessException - in case of custom exceptionsLobHandler.getBlobAsBinaryStream(java.sql.ResultSet, java.lang.String),
FileCopyUtils