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

📄 scoredaoimpl.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * ScoreDaoImpl.java * * Created on 2006年5月21日, 上午12:32 * * 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 ScoreDaoImpl implements ScoreDao{    public Score get(Integer studentId, Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Score where STUDENT_ID=:studentId and COURSE_ID=:courseId")            .setParameter("studentId",studentId)            .setParameter("courseId",courseId)            .list();            return list.isEmpty()?null:(Score)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void insert(Score score) throws RecordExistException, DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Score where STUDENT_ID=:studentId and COURSE_ID=courseId")            .setParameter("studentId",score.getStudent().getId())            .setParameter("courseId",score.getCourse().getId())            .list();            if( !list.isEmpty() )                throw new RecordExistException("the Score's student and course were existed.");            Transaction tran = session.beginTransaction();            session.saveOrUpdate(score);            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void delete(Integer studentId, Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("delete from Score where STUDENT_ID=:studentId and COURSE_ID=:courseId")            .setParameter("studentId",studentId)            .setParameter("courseId",courseId)            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }            public void update(Integer studentId,Integer courseId,Integer grade) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            session.createQuery("update from Score set value=:grade where STUDENT_ID=:studentId and COURSE_ID=:courseId")            .setParameter("studentId",studentId)            .setParameter("courseId",courseId)            .setParameter("value",grade)            .executeUpdate();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void clean(Integer studentId,Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            session.createQuery("update from Score set value=null where STUDENT_ID=:studentId and COURSE_ID=:courseId")            .setParameter("studentId",studentId)            .setParameter("courseId",courseId)            .executeUpdate();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void cleanByClassId(Integer classId,Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            session.createQuery("update from Score set value=null where STUDENT_ID in (select id from Student where CLASS_ID=:classId) and COURSE_ID=:courseId")            .setParameter("classId",classId)            .setParameter("courseId",courseId)            .executeUpdate();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void cleanByClassIdAndYearAndTerm(Integer classId,Integer year,String term) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            session.createQuery("update from Score set value=null where STUDENT_ID in (select id from Student where CLASS_ID=:classId) and COURSE_ID in (select id from Course where year=:year and term=:term)")            .setParameter("classId",classId)            .setParameter("year",year)            .setParameter("term",term)            .executeUpdate();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByTeacherIdAndCourseIdAndClassIdSortNumber(Integer teacherId,Integer courseId,Integer classId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where COURSE_ID in (select id from Course where TEACHER_ID=:teacherId and id=:id) and STUDENT_ID in (select id from Student where CLASS_ID=:classId) order by STUDENT_ID")            .setParameter("teacherId",teacherId)            .setParameter("id",courseId)            .setParameter("classId",classId)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByStudentIdAndYearAndTerm(Integer studentId,Integer year,String term) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID=:studentId and COURSE_ID in (select id from Course where year=:year and term=:term)")            .setParameter("studentId",studentId)            .setParameter("year",year)            .setParameter("term",term)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByStudentIdSortYearAndTerm(Integer studentId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID=:studentId")            .setParameter("studentId",studentId)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByClassIdSortYearAndTermAndNumber(Integer classId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID in (select id from Student where CLASS_ID=:classId) order by COURSE_ID")            .setParameter("classId",classId)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByClassIdAndYearAndTermSortNumber(Integer classId,Integer year,String term) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID in (select id from Student where CLASS_ID=:classId) and COURSE_ID in (select id from Course where year=:year and term=:term) order by COURSE_ID")            .setParameter("classId",classId)            .setParameter("year",year)            .setParameter("term",term)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByNumberAndYearAndTerm(String number,Integer year,String term) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID in (select id from Student where number=:number) and COURSE_ID in (select id from Course where year=:year and term=:term)")            .setParameter("number",number)            .setParameter("year",year)            .setParameter("term",term)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByNumber(String number) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Score where STUDENT_ID in (select id from Student where number=:number)")            .setParameter("number",number)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void updateByTeacherIdAndStudentIdAndCourseId(Integer teacherId,Integer studentId,Integer courseId,Integer value)         throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("update Score set value=:value where STUDENT_ID=:studentId and COURSE_ID=:courseId")            .setParameter("value",value)            .setParameter("studentId",studentId)            .setParameter("courseId",courseId)            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }    }

⌨️ 快捷键说明

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