Пример #1
0
 @Override
 public List<Choice> getQuestionChoices(int id) {
   List<Choice> list = new ArrayList<Choice>();
   try {
     Question question = this.loadQuestion(id);
     if (null != question) {
       list = question.getChoices();
     }
   } catch (Throwable t) {
     _logger.error("Error while loading the choices belonging to the question of ID {}", id, t);
     throw new RuntimeException("Error while loading the choices belonging a question", t);
   }
   return list;
 }
Пример #2
0
 @Override
 public Question loadQuestion(int id) {
   Question question = null;
   Connection conn = null;
   PreparedStatement stat = null;
   ResultSet res = null;
   try {
     conn = this.getConnection();
     stat = conn.prepareStatement(GET_COMPLETE_QUESTION_BY_ID);
     stat.setInt(1, id);
     res = stat.executeQuery();
     while (res.next()) {
       if (null == question) {
         question = this.buildQuestionRecordFromResultSet(res, 1);
       }
       // get extra info: questions need the survey type
       int questionnaireValue = res.getInt(13);
       boolean questionnaire = questionnaireValue == 1 ? true : false;
       ApsProperties titles = new ApsProperties();
       titles.loadFromXml(res.getString(14));
       question.setExtraInfo(questionnaire, titles);
       Choice choice = this.buildChoiceRecordFromResultSet(res, 8);
       if (null == choice) continue;
       choice.setExtraInfo(
           question.getSurveyId(),
           question.isQuestionnaire(),
           question.getSurveyTitles(),
           question.getQuestions());
       if (null == question.getChoice(choice.getId())) {
         question.getChoices().add(choice);
       }
     }
   } catch (Throwable t) {
     _logger.error("Error while loading the question of ID {}", t);
     throw new RuntimeException("Error while loading a question", t);
   } finally {
     closeDaoResources(res, stat, conn);
   }
   return question;
 }