QuestionDAOImp.java
上传用户:nbxinmin
上传日期:2021-10-09
资源大小:46k
文件大小:2k
源码类别:

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.dao.hibernate;
  2. import java.util.List;
  3. import org.hibernate.Criteria;
  4. import org.hibernate.Query;
  5. import org.hibernate.criterion.Order;
  6. import org.hibernate.criterion.Projections;
  7. import org.hibernate.criterion.Restrictions;
  8. import com.xdf.exams.bean.Question;
  9. import com.xdf.exams.dao.IQuestionDAO;
  10. public class QuestionDAOImp extends BaseDAO implements IQuestionDAO{
  11. public List findQuestionBySubject(Long subjectid, int pageno, int pagesize) {
  12. Criteria c = getSession()
  13. .createCriteria(Question.class)
  14. .createAlias("subject","s")
  15. .add(Restrictions.eq("s.subjectid",subjectid))
  16. .addOrder(Order.asc("questionid"))
  17. .setFirstResult((pageno-1)*pagesize)
  18. .setMaxResults(pagesize);
  19. return c.list();
  20. }
  21. public List findQuestionBySubject(Long subjectid) {
  22. Criteria c = getSession()
  23. .createCriteria(Question.class)
  24. .createAlias("subject","s")
  25. .addOrder(Order.asc("questionid"))
  26. .add(Restrictions.eq("s.subjectid",subjectid));
  27. return c.list();
  28. }
  29. public int findQuestionnumBySubject(Long subjectid) {
  30. Criteria c = getSession()
  31. .createCriteria(Question.class)
  32. .createAlias("subject","s")
  33. .add(Restrictions.eq("s.subjectid",subjectid))
  34. .setProjection(Projections.rowCount());
  35. Integer a = (Integer)c.list().get(0);
  36. return a.intValue();
  37. }
  38. public void deletebySubject(Long subjectid) {
  39. Query q = getSession().createQuery("delete Question r where r.subject.subjectid=?");
  40. q.setLong(0,subjectid);
  41. q.executeUpdate();
  42. }
  43. }