beautypg.com

Defaultimagedatabase.java – HP Integrity NonStop H-Series User Manual

Page 165

background image

void storeImage(String name, InputStream is, int contentLength,
String description)throws DataAccessException;

After the change:

void storeImage(String name, byte[] fl, String description);

DefaultImageDatabase.java

(\samples\imagedb\src\org\springframework\samples\ imagedb\
web\DefaultImageDatabase.java)

:

This Java file includes implementations of the central image database business interface. BLOB
is not directly supported by the SQL/MX database; it is handled by the BLOB/CLOB handler
classes in the SQL/MX driver JAR file. This class is modified to use BLOB.

Changes to the

DefaultImageDatabase.java

file

The following modifications were made in the

DefaultImageDatabase.java

file:

The

streamImage

function (final String name, final OutputStream, contentStream) was

changed to enable the data retrieval from the BLOB table.
Before the change:

@Transactional(readOnly=true)
public void streamImage(final String name, final OutputStream contentStream)
throws DataAccessException
{
getJdbcTemplate().query("SELECT content FROM imagedb WHERE image_name=?",
new Object[] {name},
new AbstractLobStreamingResultSetExtractor()
{
protected void handleNoRowFound() throws LobRetrievalFailureException
{throw new EmptyResultDataAccessException("Image with name '" + name +
"' not found in database", 1);
}
public void streamData(ResultSet rs) throws SQLException, IOException {
InputStream is = lobHandler.getBlobAsBinaryStream(rs, 1);
if (is != null) {
FileCopyUtils.copy(is,contentStream);
}
}
}
);
}

After the change:

@Transactional
public void streamImage(final String name, final OutputStream contentStream)
throws DataAccessException
{
getJdbcTemplate().query(
"SELECT content FROM imagedb WHERE image_name=? ", new Object[] {name},
new AbstractLobStreamingResultSetExtractor() {
protected void handleNoRowFound() throws LobRetrievalFailureException {
throw new EmptyResultDataAccessException("Image with name '" + name +
"' not found in database", 1);
}
public void streamData(ResultSet rs) throws SQLException, IOException {
Blob content = null;
content = rs.getBlob(1);
InputStream is = content.getBinaryStream();
if (is != null) {
FileCopyUtils.copy(is,contentStream);
}
}
}

Customizing ImageDB

165

This manual is related to the following products: