HP Integrity NonStop H-Series User Manual
Page 166

);
}
•
The
storeImage
function (
final String name
,
final InputStream contentStream
,
final int contentLength
,
final String description
) was modified to enable the
data entry to the BLOB table.
Before the change:
@Transactional
public void storeImage(
final String name, final InputStream contentStream, final int contentLength,
final String description)
throws DataAccessException {
getJdbcTemplate().execute(
"INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)",
new AbstractLobCreatingPreparedStatementCallback(this.lobHandler)
{
protected void setValues(PreparedStatement ps, LobCreator lobCreator)
throws SQLException {
ps.setString(1, name);
lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength);
lobCreator.setClobAsString(ps, 3, description);
}
}
);
}
After the change:
@Transactional
public void storeImage(final String name, final byte[]fl,final String description)
throws DataAccessException {
try{
getJdbcTemplate().execute(
"INSERT INTO imagedb (image_name, content, description) VALUES (?,?,?)",
new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) {
protected void setValues(PreparedStatement ps,LobCreator lobCreator)
throws SQLException {
ByteArrayInputStream blobFs = new ByteArrayInputStream(fl);
ps.setString(1, name);
ps.setBinaryStream(2, blobFs, fl.length);
ps.setString(3, description);
}
}
);
}catch (Exception e) {
}
}
•
The
public void clearDatabase()
function was modified to delete data from the
BLOB table.
Before the change:
@Transactional
public void clearDatabase() throws DataAccessException {
getJdbcTemplate().update("DELETE FROM imagedb");
}
After the change:
@Transactional
public void clearDatabase() throws DataAccessException {
getJdbcTemplate().update("DELETE FROM blobTableName");
getJdbcTemplate().update("DELETE FROM imagedb");
}
•
The modified code requires supporting Java classes, which are imported in
DefaultImageDatabase.java
. Therefore, the following code was added:
import java.sql.Blob;
import java.io.ByteArrayInputStream;
166
Customizing Sample Applications