-
大小: 35.58MB文件類型: .zip金幣: 1下載: 0 次發(fā)布日期: 2023-06-16
- 語言: 其他
- 標簽: spring2.5.6??
資源簡介
代碼片段和文件信息
package?org.springframework.samples.imagedb;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.OutputStream;
import?java.sql.PreparedStatement;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.util.List;
import?org.springframework.dao.DataAccessException;
import?org.springframework.dao.EmptyResultDataAccessException;
import?org.springframework.jdbc.LobRetrievalFailureException;
import?org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import?org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import?org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
import?org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor;
import?org.springframework.jdbc.support.lob.LobCreator;
import?org.springframework.jdbc.support.lob.LobHandler;
import?org.springframework.transaction.annotation.Transactional;
import?org.springframework.util.FileCopyUtils;
/**
?*?Default?implementation?of?the?central?image?database?business?interface.
?*
?*?Uses?JDBC?with?a?LobHandler?to?retrieve?and?store?image?data.
?*?Illustrates?direct?use?of?the?jdbc.core
?package
?*?i.e.?JdbcTemplate?rather?than?operation?objects?from?the
?*?jdbc.object
?package.
?*
?*?@author?Juergen?Hoeller
?*?@since?07.01.2004
?*?@see?org.springframework.jdbc.core.JdbcTemplate
?*?@see?org.springframework.jdbc.support.lob.LobHandler
?*/
public?class?DefaultImageDatabase?extends?SimpleJdbcDaoSupport?implements?ImageDatabase?{
private?LobHandler?lobHandler;
/**
?*?Set?the?LobHandler?to?use?for?BLOB/CLOB?access.
?*?Could?use?a?DefaultLobHandler?instance?as?default
?*?but?relies?on?a?specified?LobHandler?here.
?*?@see?org.springframework.jdbc.support.lob.DefaultLobHandler
?*/
public?void?setLobHandler(LobHandler?lobHandler)?{
this.lobHandler?=?lobHandler;
}
@Transactional(readOnly=true)
public?Listriptor>?getImages()?throws?DataAccessException?{
return?getSimpleJdbcTemplate().query(
????“SELECT?image_name?description?FROM?imagedb“
????new?ParameterizedRowMapperriptor>()?{
????public?ImageDescriptor?mapRow(ResultSet?rs?int?rowNum)?throws?SQLException?{
????String?name?=?rs.getString(1);
????String?description?=?lobHandler.getClobAsString(rs?2);
????return?new?ImageDescriptor(name?description);
????}
????});
}
@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)?thro
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2008-10-31?18:30??spring-fr
?????文件??????312387??2008-10-29?16:45??spring-fr
?????目錄???????????0??2008-10-31?18:25??spring-fr
?????目錄???????????0??2008-10-31?18:25??spring-fr
?????文件??????325942??2008-10-31?18:25??spring-fr
?????文件??????488282??2008-10-31?18:25??spring-fr
?????文件???????96880??2008-10-31?18:25??spring-fr
?????文件??????476940??2008-10-31?18:25??spring-fr
?????文件??????285491??2008-10-31?18:25??spring-fr
?????文件??????335484??2008-10-31?18:25??spring-fr
?????文件??????195350??2008-10-31?18:25??spring-fr
?????文件??????377805??2008-10-31?18:25??spring-fr
?????文件??????180924??2008-10-31?18:25??spring-fr
?????文件??????231173??2008-10-31?18:25??spring-fr
?????文件??????194577??2008-10-31?18:25??spring-fr
?????文件??????149683??2008-10-31?18:25??spring-fr
?????文件???????36748??2008-10-31?18:25??spring-fr
?????文件??????402396??2008-10-31?18:25??spring-fr
?????目錄???????????0??2008-10-31?18:25??spring-fr
?????文件???????14164??2007-09-20?22:59??spring-fr
?????文件???????13480??2007-09-20?22:57??spring-fr
?????文件???????24108??2008-03-09?01:08??spring-fr
?????文件???????39928??2008-06-06?17:42??spring-fr
?????文件???????43281??2008-08-06?12:37??spring-fr
?????文件???????21774??2008-01-28?16:48??spring-fr
?????文件???????17925??2008-10-21?17:26??spring-fr
?????文件???????72994??2008-05-13?14:40??spring-fr
?????文件????????7744??2008-03-18?21:42??spring-fr
?????文件????????9467??2008-05-21?12:06??spring-fr
?????文件???????18072??2008-05-19?21:29??spring-fr
?????文件????????5549??2007-06-14?10:24??spring-fr
............此處省略6092個文件信息
評論
共有 條評論