📄 coursedaoimpl.java
字号:
/* * CourseDaoImpl.java * * Created on 2006年5月20日, 下午11:26 * * 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.*;/** * * @author vlinux */public class CourseDaoImpl implements CourseDao{ public Course get(Integer id) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); List list = session.createQuery("from Course where id=:id") .setParameter("id",id) .list(); return list.isEmpty()?null:(Course)list.get(0); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public void updateOrInsert(Course course) throws RecordExistException, DataAccessException{ try{ Session session = HibernateUtil.currentSession(); Transaction tran = session.beginTransaction(); session.saveOrUpdate(course); 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 Course where id=:id") .setParameter("id",id) .executeUpdate(); tran.commit(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getByYearAndTerm(Integer year,String term) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Course where year=:year and term=:term") .setParameter("year",year) .setParameter("term",term) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getByYearSortTerm(Integer year) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Course where year=:year order by term") .setParameter("year",year) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getByYearAndTermAndTeacherId(Integer year,String term,Integer teacherId) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Course where year=:year and term=:term and TEACHER_ID=:teacherId") .setParameter("year",year) .setParameter("term",term) .setParameter("teacherId",teacherId) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getByClassIdAndYearAndTerm(Integer classId,Integer year,String term) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Course where year=:year and term=:term and id in (select COURSE_ID from ClassCourse where CLASS_ID=:classId) order by id") .setParameter("year",year) .setParameter("term",term) .setParameter("classId",classId) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -