Top Description Constructors Methods
org.springframework.jdbc.core.support

public abstract Class AbstractLobStreamingResultSetExtractor<T>

extends Object
implements ResultSetExtractor<T>
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.ResultSetExtractor
Type Parameters
<T>
the result type
Imports
java.io.IOException, java.sql.ResultSet, .SQLException, org.springframework.dao.DataAccessException, .EmptyResultDataAccessException, .IncorrectResultSizeDataAccessException, org.springframework.jdbc.LobRetrievalFailureException, org.springframework.jdbc.core.ResultSetExtractor, org.springframework.lang.Nullable

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);
       }
     });
 
Author
Juergen Hoeller
Since
1.0.2
See Also
org.springframework.jdbc.support.lob.LobHandler, org.springframework.jdbc.LobRetrievalFailureException

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final T
extractData(ResultSet
the ResultSet to extract data from. Implementations should not close this: it will be closed by the calling JdbcTemplate.
rs
)

Implements org.springframework.jdbc.core.ResultSetExtractor.extractData.

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
the ResultSet to take the LOB content from
rs
)

Stream LOB content from the given ResultSet to some OutputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractLobStreamingResultSetExtractorback to summary
public AbstractLobStreamingResultSetExtractor()

Method Detail

extractDataback to summary
public final T extractData(ResultSet rs) throws SQLException, DataAccessException

Implements org.springframework.jdbc.core.ResultSetExtractor.extractData.

Delegates to handleNoRowFound, handleMultipleRowsFound and streamData, according to the ResultSet state. Converts an IOException thrown by streamData to a LobRetrievalFailureException.

Parameters
rs:ResultSet

Doc from org.springframework.jdbc.core.ResultSetExtractor.extractData.

the ResultSet to extract data from. Implementations should not close this: it will be closed by the calling JdbcTemplate.

Returns:T

Doc from org.springframework.jdbc.core.ResultSetExtractor.extractData.

an arbitrary result object, or null if none (the extractor will typically be stateful in the latter case).

Annotations
@Override
@Nullable
Exceptions
SQLException:

Doc from org.springframework.jdbc.core.ResultSetExtractor.extractData.

if an SQLException is encountered getting column values or navigating (that is, there's no need to catch SQLException)

DataAccessException:

Doc from org.springframework.jdbc.core.ResultSetExtractor.extractData.

in case of custom exceptions

See Also
handleNoRowFound, handleMultipleRowsFound, streamData, org.springframework.jdbc.LobRetrievalFailureException
handleMultipleRowsFoundback to summary
protected void handleMultipleRowsFound() throws DataAccessException

Handle the case where the ResultSet contains multiple rows.

Exceptions
DataAccessException:
a corresponding exception, by default an IncorrectResultSizeDataAccessException
See Also
org.springframework.dao.IncorrectResultSizeDataAccessException
handleNoRowFoundback to summary
protected void handleNoRowFound() throws DataAccessException

Handle the case where the ResultSet does not contain a row.

Exceptions
DataAccessException:
a corresponding exception, by default an EmptyResultDataAccessException
See Also
org.springframework.dao.EmptyResultDataAccessException
streamDataback to summary
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.

Parameters
rs:ResultSet

the ResultSet to take the LOB content from

Exceptions
SQLException:
if thrown by JDBC methods
IOException:
if thrown by stream access methods
DataAccessException:
in case of custom exceptions
See Also
org.springframework.jdbc.support.lob.LobHandler#getBlobAsBinaryStream, org.springframework.util.FileCopyUtils