FolderDaoImpl.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.folder.dao;
- import java.util.Iterator;
- 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.FolderBean;
- import com.oa.module.folder.filemapping.Tfile;
- import com.oa.module.folder.fordermapping.Tforder;
- public class FolderDaoImpl implements FolderDao{
- private SessionFactory sf;
- /**
- *根据用户id获取用户文件夹列表
- */
- public List getUserFolder(String id) {
- Session session = null;
- Query query = null;
- List list = null;
- String hql = "select a from Tforder a where a.userid=:userid and a.fatherid<>"+"0";
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- query.setParameter("userid", id);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return list;
- }
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- /**
- * 添加文件夹
- */
- public boolean addnewForder(FolderBean bean) {
- Session session = null;
- Transaction tx = null;
- Tforder forder = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- forder = new Tforder();
- BeanUtils.copyProperties(forder, bean);
- session.save(forder);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 获取父文件夹
- * @param userid
- * @param username
- */
- public FolderBean getFatherForderByUserName(String userid, String username) {
- Session session = null;
- Query query = null;
- FolderBean bean = null;
- String hql = "select a from Tforder a where a.fordername=:fordername";
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- query.setParameter("fordername", username+","+userid);
- List list = query.list();
- Tforder forder = (Tforder)list.get(0);
- bean = new FolderBean();
- BeanUtils.copyProperties(bean, forder);
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return bean;
- }
- /**
- * 修改文件夹名称
- * @param forderid
- * @param fordername
- */
- public boolean uploadForder(String forderid, String fordername) {
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- Tforder forder = (Tforder)session.get(Tforder.class, forderid);
- forder.setVirtualfordername(fordername);
- session.update(forder);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 判断文件夹是否存在
- * @param forderid
- * @param fordername
- */
- public boolean isExist(String forderid, String fordername) {
- Session session = null;
- try {
- session = sf.openSession();
- Tforder forder = (Tforder)session.get(Tforder.class, forderid);
- if(forder.getFordername().equals(fordername))
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 删除文件夹
- * @param forderid
- */
- public boolean delForder(String forderid) {
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- Tforder forder = (Tforder)session.load(Tforder.class, forderid);
- session.delete(forder);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 获取文件夹
- * @param forderid
- */
- public FolderBean getForderByForderId(String forderid) {
- Session session = null;
- FolderBean bean = null;
- try {
- session = sf.openSession();
- Tforder forder = (Tforder)session.get(Tforder.class, forderid);
- bean = new FolderBean();
- BeanUtils.copyProperties(bean , forder);
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return bean;
- }
- /**
- * 根据文件夹id删除文件表
- */
- public boolean delFileByForderId(String forderid) {
- String hql = "select a from Tfile a where a.forderid=:forderid";
- Session session = null;
- Transaction tx = null;
- Query query = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- query = session.createQuery(hql);
- query.setParameter("forderid", forderid);
- List list = query.list();
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- Tfile element = (Tfile) iter.next();
- Tfile file = (Tfile)session.load(Tfile.class, element.getFileid());
- session.delete(file);
- }
- tx.commit();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- }