📄 defaultimagedatabase.java
字号:
package org.springframework.samples.imagedb;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.util.FileCopyUtils;
/**
*
* @author worldheart
*
*/
public class DefaultImageDatabase extends HibernateDaoSupport implements ImageDatabase {
protected static final Log log = LogFactory.getLog(DefaultImageDatabase.class);
public List getImages() throws DataAccessException {
List<ImageDescriptor> returnList = new ArrayList<ImageDescriptor>();
List list = this.getHibernateTemplate().find("from Imagedb");
for(Object imagedb: list){
Imagedb image = (Imagedb)imagedb;
returnList.add(new ImageDescriptor(image.getImageName(), image.getDescription()));
}
return returnList;
}
public void streamImage(final String name, final OutputStream contentStream) throws DataAccessException {
Imagedb imagedb = (Imagedb)this.getHibernateTemplate().get(Imagedb.class, name);
if(imagedb.getContent() != null){
try{
FileCopyUtils.copy(imagedb.getContent(), contentStream);
} catch(IOException io){
log.error(io);
}
}
}
public void storeImage(
final String name, final InputStream contentStream, final int contentLength, final String description)
throws DataAccessException {
Imagedb imagedb = new Imagedb();
imagedb.setImageName(name);
try{
imagedb.setContent(FileCopyUtils.copyToByteArray(contentStream));
} catch(IOException io){
log.error(io);
}
imagedb.setDescription(description);
this.getHibernateTemplate().saveOrUpdate(imagedb);
}
public void checkImages() {
logger.info("Checking images: not implemented but invoked by scheduling");
}
public void clearDatabase() throws DataAccessException {
this.getHibernateTemplate().bulkUpdate("delete from Imagedb");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -