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

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.bo.service;
  2. import java.util.List;
  3. import com.xdf.exams.bean.Options;
  4. import com.xdf.exams.bean.Question;
  5. import com.xdf.exams.bean.Subject;
  6. import com.xdf.exams.bo.IQuestionService;
  7. import com.xdf.exams.dao.IExamrecordDAO;
  8. import com.xdf.exams.dao.IOptionsDAO;
  9. import com.xdf.exams.dao.IQuestionDAO;
  10. import com.xdf.exams.dao.IResultDAO;
  11. import com.xdf.exams.dao.ISubjectDAO;
  12. public class QuestionServiceImp extends BaseService implements IQuestionService{
  13. private IExamrecordDAO examrecorddao = null;
  14. private IOptionsDAO  optionsdao= null;
  15. private IQuestionDAO questiondao = null;
  16. private IResultDAO resultdao = null;
  17. private ISubjectDAO subjectdao = null;
  18. public IExamrecordDAO getExamrecorddao() {
  19. return examrecorddao;
  20. }
  21. public void setExamrecorddao(IExamrecordDAO examrecorddao) {
  22. this.examrecorddao = examrecorddao;
  23. }
  24. public IOptionsDAO getOptionsdao() {
  25. return optionsdao;
  26. }
  27. public void setOptionsdao(IOptionsDAO optionsdao) {
  28. this.optionsdao = optionsdao;
  29. }
  30. public IQuestionDAO getQuestiondao() {
  31. return questiondao;
  32. }
  33. public void setQuestiondao(IQuestionDAO questiondao) {
  34. this.questiondao = questiondao;
  35. }
  36. public IResultDAO getResultdao() {
  37. return resultdao;
  38. }
  39. public void setResultdao(IResultDAO resultdao) {
  40. this.resultdao = resultdao;
  41. }
  42. public ISubjectDAO getSubjectdao() {
  43. return subjectdao;
  44. }
  45. public void setSubjectdao(ISubjectDAO subjectdao) {
  46. this.subjectdao = subjectdao;
  47. }
  48. public void addQuestion(Question que,List options) {
  49. try {
  50. beginTransaction();
  51. questiondao.add(que);
  52. for (int i=0;i<options.size();i++) {
  53. Options op = (Options)options.get(i);
  54. op.setQuestion(que);
  55. optionsdao.add(op);
  56. }
  57. commitTransaction();
  58. } catch (RuntimeException e) {
  59. e.printStackTrace();
  60. rollbackTransaction();
  61. throw e;
  62. }
  63. }
  64. public void addSubject(Subject sub) {
  65. beginTransaction();
  66. subjectdao.add(sub);
  67. commitTransaction();
  68. }
  69. public void deleteQuestion(Question que) {
  70. try {
  71. beginTransaction();
  72. optionsdao.deletebyquestion(que.getQuestionid());
  73. examrecorddao.deleteExamrecordbyQuestion(que.getQuestionid());
  74. questiondao.delete(que);
  75. commitTransaction();
  76. } catch (RuntimeException e) {
  77. rollbackTransaction();
  78. e.printStackTrace();
  79. throw e;
  80. }
  81. }
  82. public void deleteSubject(Subject sub) {
  83. try {
  84. beginTransaction();
  85. List list = questiondao.findQuestionBySubject(sub.getSubjectid());
  86. for (int i=0;i<list.size();i++) {
  87. Question q = (Question)list.get(i);
  88. optionsdao.deletebyquestion(q.getQuestionid());
  89. examrecorddao.deleteExamrecordbyQuestion(q.getQuestionid());
  90. }
  91. questiondao.deletebySubject(sub.getSubjectid());
  92. resultdao.deleteResultbySubject(sub.getSubjectid());
  93. subjectdao.delete(sub);
  94. commitTransaction();
  95. } catch (RuntimeException e) {
  96. rollbackTransaction();
  97. e.printStackTrace();
  98. throw e;
  99. }
  100. }
  101. public List findAllSubjects() {
  102. return subjectdao.findAllSubjects();
  103. }
  104. public List findAllSubjects(int pageno, int pagesize) {
  105. return subjectdao.findAllSubjects(pageno,pagesize);
  106. }
  107. public int findAllSubjectsnum() {
  108. return subjectdao.findAllSubjectsnum();
  109. }
  110. public Question findQuestion(Long id) {
  111. return (Question)questiondao.load(Question.class,id);
  112. }
  113. public List findQuestionBySubjects(Long subjectid, int pageno, int pagesize) {
  114. return questiondao.findQuestionBySubject(subjectid,pageno,pagesize);
  115. }
  116. public List findQuestionBySubjects(Long subjectid) {
  117. return questiondao.findQuestionBySubject(subjectid);
  118. }
  119. public int findQuestionnumBySubjects(Long subjectid) {
  120. return questiondao.findQuestionnumBySubject(subjectid);
  121. }
  122. public Subject findSubject(Long id) {
  123. return (Subject)subjectdao.load(Subject.class,id);
  124. }
  125. public void updateQuestion(Question que,List options) {
  126. try {
  127. beginTransaction();
  128. questiondao.update(que);
  129. optionsdao.deletebyquestion(que.getQuestionid());
  130. for (int i=0;i<options.size();i++) {
  131. Options op = (Options)options.get(i);
  132. op.setQuestion(que);
  133. optionsdao.add(op);
  134. }
  135. commitTransaction();
  136. } catch (RuntimeException e) {
  137. e.printStackTrace();
  138. rollbackTransaction();
  139. throw e;
  140. }
  141. }
  142. public void updateSubject(Subject sub) {
  143. beginTransaction();
  144. subjectdao.update(sub);
  145. commitTransaction();
  146. }
  147. }