📄 classdaoimpl.java
字号:
/* * ClassDaoImpl.java * * Created on 2006年5月20日, 下午10:42 * * 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 ClassDaoImpl implements ClassDao{ public enova.pojo.Class get(Integer id) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); List list = session.createQuery("from Class where id=:id") .setParameter("id",id) .list(); return list.isEmpty()?null:(enova.pojo.Class)list.get(0); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public void updateOrInsert(enova.pojo.Class c) throws RecordExistException, DataAccessException{ try{ Session session = HibernateUtil.currentSession(); if( c.getId()==null ){ List list = session.createQuery("from Class where name=:name and enrollYear=:enrollYear and SPECIAL_ID=:specialId") .setParameter("name",c.getName()) .setParameter("enrollYear",c.getEnrollYear()) .setParameter("specialId",c.getSpecial().getId()) .list(); if( !list.isEmpty() ) throw new RecordExistException(); } Transaction tran = session.beginTransaction(); session.saveOrUpdate(c); 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 Class where id=:id") .setParameter("id",id).executeUpdate(); tran.commit(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getBySpecialIdAndEnrollYear(Integer specialId,Integer year) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Class where enrollYear=:enrollYear and SPECIAL_ID=:specialId") .setParameter("enrollYear",year) .setParameter("specialId",specialId) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } public List getBySpecialIdSortEnrollYear(Integer specialId) throws DataAccessException{ try{ Session session = HibernateUtil.currentSession(); return session.createQuery("from Class where SPECIAL_ID=:specialId order by enrollYear") .setParameter("specialId",specialId) .list(); }catch(HibernateException he){ throw new DataAccessException(he.toString()); }finally{ HibernateUtil.closeSession(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -