FileDaoImpl.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:3k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.folder.dao;
- import java.util.List;
- import org.apache.commons.beanutils.BeanUtils;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import com.oa.module.folder.bean.FileBean;
- import com.oa.module.folder.filemapping.Tfile;
- public class FileDaoImpl implements FileDao{
- private SessionFactory sf ;
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- /**
- * 根据文件夹id,获取文件列表
- * @param id
- * @return
- */
- public List getFileListByForderId(String id) {
- Session session = null;
- Query query = null;
- List list = null;
- String hql ="select a from Tfile a where a.forderid=:forderid";
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- query.setParameter("forderid", id);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return list;
- }
- /**
- * 上传文件
- * @param filebean
- */
- public boolean addFile(FileBean filebean) {
- Tfile file = null;
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx =session.beginTransaction();
- file = new Tfile();
- BeanUtils.copyProperties(file, filebean);
- session.save(file);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 删除文件
- * @param id
- */
- public boolean delFileById(String id) {
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx =session.beginTransaction();
- Tfile file = (Tfile)session.load(Tfile.class, id);
- session.delete(file);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- } finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 获取文件
- * @param id
- */
- public FileBean getFileById(String id) {
- Session session = null;
- FileBean bean = null;
- try {
- session = sf.openSession();
- Tfile file = (Tfile)session.get(Tfile.class, id);
- bean = new FileBean();
- BeanUtils.copyProperties(bean, file);
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return bean;
- }
- }