⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 departmentdaoimpl.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * DepartmentDaoImpl.java * * Created on 2006年5月20日, 下午5:52 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package enova.orm.hibernate.daoImpl;import enova.dao.*;import enova.pojo.*;import java.util.*;import org.hibernate.*;import enova.util.*;/*        try{            //这里放代码        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        } *//** * * @author vlinux */public class DepartmentDaoImpl implements DepartmentDao{        public Department get(Integer id) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Department where id=:id")                    .setParameter("id",id)                    .list();            if( list.isEmpty() )                return null;            else                return (Department)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void updateOrInsert(Department department) throws RecordExistException, DataAccessException{        try{            Session session = HibernateUtil.currentSession();            if( department.getId()==null ){                //insert,判断是否有逻辑重复                List list = session.createQuery("from Department where name=:name")                        .setParameter("name",department.getName())                        .list();                if( !list.isEmpty() )                    //有逻辑重复则抛出记录存在异常                    throw new RecordExistException("the department's name was existed.");            }            Transaction tran = session.beginTransaction();            session.saveOrUpdate(department);            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void delete(Integer id) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("delete from Department where id=:id")                    .setParameter("id",id)                    .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getAll() throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Department").list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -