类 AbstractLobStreamingResultSetExtractor<T>
- java.lang.Object
- org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor<T>
- 类型参数:
T
- the result type
- 所有已实现的接口:
ResultSetExtractor<T>
public abstract class AbstractLobStreamingResultSetExtractor<T> extends Object implements ResultSetExtractor<T>
Abstract ResultSetExtractor implementation that assumes streaming of LOB data. Typically used as inner class, with access to surrounding method arguments.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); } } );
- 从以下版本开始:
- 1.0.2
- 作者:
- Juergen Hoeller
- 另请参阅:
LobHandler
,LobRetrievalFailureException
构造器概要
构造器 构造器 说明 AbstractLobStreamingResultSetExtractor()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 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.
构造器详细资料
AbstractLobStreamingResultSetExtractor
public AbstractLobStreamingResultSetExtractor()
方法详细资料
extractData
@Nullable public final T extractData(ResultSet rs) throws SQLException, DataAccessException
Delegates to handleNoRowFound, handleMultipleRowsFound and streamData, according to the ResultSet state. Converts an IOException thrown by streamData to a LobRetrievalFailureException.- 指定者:
extractData
在接口中ResultSetExtractor<T>
- 参数:
rs
- the ResultSet to extract data from. Implementations should not close this: it will be closed by the calling JdbcTemplate.- 返回:
- an arbitrary result object, or
null
if none (the extractor will typically be stateful in the latter case). - 抛出:
SQLException
- if an SQLException is encountered getting column values or navigating (that is, there's no need to catch SQLException)DataAccessException
- in case of custom exceptions- 另请参阅:
handleNoRowFound()
,handleMultipleRowsFound()
,streamData(java.sql.ResultSet)
,LobRetrievalFailureException
handleNoRowFound
protected void handleNoRowFound() throws DataAccessException
Handle the case where the ResultSet does not contain a row.- 抛出:
DataAccessException
- a corresponding exception, by default an EmptyResultDataAccessException- 另请参阅:
EmptyResultDataAccessException
handleMultipleRowsFound
protected void handleMultipleRowsFound() throws DataAccessException
Handle the case where the ResultSet contains multiple rows.- 抛出:
DataAccessException
- a corresponding exception, by default an IncorrectResultSizeDataAccessException- 另请参阅:
IncorrectResultSizeDataAccessException
streamData
protected abstract void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException
Stream LOB content from the given ResultSet to some OutputStream.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 from- 抛出:
SQLException
- if thrown by JDBC methodsIOException
- if thrown by stream access methodsDataAccessException
- in case of custom exceptions- 另请参阅:
LobHandler.getBlobAsBinaryStream(java.sql.ResultSet, java.lang.String)
,FileCopyUtils