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

📄 classcoursedaoimpl.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * ClassCourseDaoImpl.java * * Created on 2006年5月20日, 下午9:34 * * 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 ClassCourseDaoImpl implements ClassCourseDao{        public ClassCourse get(Integer classId,Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from ClassCourse where CLASS_ID=:classId and COURSE_ID=:courseId")            .setParameter("classId",classId)            .setParameter("courseId",courseId)            .list();            return list.isEmpty()?null:(ClassCourse)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void create(ClassCourse cc) throws RecordExistException, DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from ClassCourse where CLASS_ID=:classId and COURSE_ID=:courseId")            .setParameter("classId",cc.getC().getId())            .setParameter("courseId",cc.getCourse().getId())            .list();            if( !list.isEmpty() )                throw new RecordExistException("the ClassCourse's classId and courseId ware existed.");            Transaction tran = session.beginTransaction();            session.save(cc);            //自动更新Score            list = session.createQuery("from Student where CLASS_ID=:classId")            .setParameter("classId",cc.getC().getId())            .list();            for(int i=0;i<list.size();i++){                Student student = (Student)list.get(i);                Score score = new Score(student.getId(),cc.getCourse().getId(),DateUtil.getLocalDate());                session.save(score);            }            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void delete(Integer classId,Integer courseId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("delete from ClassCourse where CLASS_ID=:classId and COURSE_ID=:courseId")            .setParameter("classId",classId)            .setParameter("courseId",courseId)            .executeUpdate();            tran.commit();        }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 ClassCourse 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)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getBySpecialIdAndYearAndTermSortClassId(Integer specialId,Integer year,String term) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from ClassCourse where CLASS_ID in (select id from Class where SPECIAL_ID=:specialId) and COURSE_ID in (select id from Course where year=:year and term=:term)")            .setParameter("specialId",specialId)            .setParameter("year",year)            .setParameter("term",term)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        }

⌨️ 快捷键说明

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