/** * Method declaration * * @param con * @param questionContainerHeader * @throws SQLException * @see */ public static void updateQuestionContainerHeader( Connection con, QuestionContainerHeader questionContainerHeader) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.updateQuestionContainerHeader()", "root.MSG_GEN_ENTER_METHOD", "questionContainerHeader = " + questionContainerHeader); String insertStatement = "update " + questionContainerHeader.getPK().getTableName() + " set qcTitle = ?," + " qcDescription = ?," + " qcComment = ?," + " qcBeginDate = ?," + " qcEndDate = ?," + " qcNbVoters = ?," + " qcNbQuestionsPage = ?," + " qcNbMaxParticipations = ?," + " qcNbTriesBeforeSolution = ?," + " qcMaxTime = ?, " + " instanceId = ?, " + " anonymous = ?" + " where qcId = ?"; PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(insertStatement); prepStmt.setString(1, questionContainerHeader.getTitle()); prepStmt.setString(2, questionContainerHeader.getDescription()); prepStmt.setString(3, questionContainerHeader.getComment()); if (questionContainerHeader.getBeginDate() == null) { prepStmt.setString(4, nullBeginDate); } else { prepStmt.setString(4, questionContainerHeader.getBeginDate()); } if (questionContainerHeader.getEndDate() == null) { prepStmt.setString(5, nullEndDate); } else { prepStmt.setString(5, questionContainerHeader.getEndDate()); } prepStmt.setInt(6, questionContainerHeader.getNbVoters()); prepStmt.setInt(7, questionContainerHeader.getNbQuestionsPerPage()); prepStmt.setInt(8, questionContainerHeader.getNbMaxParticipations()); prepStmt.setInt(9, questionContainerHeader.getNbParticipationsBeforeSolution()); prepStmt.setInt(10, questionContainerHeader.getMaxTime()); prepStmt.setString(11, questionContainerHeader.getPK().getComponentName()); if (questionContainerHeader.isAnonymous()) { prepStmt.setInt(12, 1); } else { prepStmt.setInt(12, 0); } prepStmt.setInt(13, Integer.parseInt(questionContainerHeader.getPK().getId())); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
public void index(MainSessionController mainSessionCtrl, ComponentContext context) throws QuizzException { try { scc = new QuizzSessionController(mainSessionCtrl, context); Collection<QuestionContainerHeader> quizzes = scc.getAdminQuizzList(); for (QuestionContainerHeader questionContainerHeader : quizzes) { scc.updateQuizzHeader(questionContainerHeader, questionContainerHeader.getPK().getId()); } } catch (Exception e) { throw new QuizzException( "QuizzIndexer.index", QuizzException.WARNING, "Quizz.EX_CANNOT_UPDATE_QUIZZ_HEADER", e); } }
/** * Method declaration * * @param con * @param questionContainerHeader * @return * @throws SQLException * @see */ public static QuestionContainerPK createQuestionContainerHeader( Connection con, QuestionContainerHeader questionContainerHeader) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.createQuestionContainerHeader()", "root.MSG_GEN_ENTER_METHOD", "questionContainerHeader = " + questionContainerHeader); int newId = 0; String insertStatement = "insert into " + questionContainerHeader.getPK().getTableName() + " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; try { /* Retrieve next sequence identifier */ newId = DBUtil.getNextId(questionContainerHeader.getPK().getTableName(), "qcId"); } catch (Exception e) { throw new QuestionContainerRuntimeException( "QuestionContainerDAO.createQuestionContainerHeader()", SilverpeasRuntimeException.ERROR, "root.EX_GET_NEXTID_FAILED", e); } QuestionContainerPK questionContainerPK = questionContainerHeader.getPK(); questionContainerPK.setId(Integer.toString(newId)); PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(insertStatement); prepStmt.setInt(1, newId); prepStmt.setString(2, questionContainerHeader.getTitle()); prepStmt.setString(3, questionContainerHeader.getDescription()); prepStmt.setString(4, questionContainerHeader.getComment()); prepStmt.setString(5, questionContainerHeader.getCreatorId()); prepStmt.setString(6, formatter.format(new java.util.Date())); if (questionContainerHeader.getBeginDate() == null) { prepStmt.setString(7, nullBeginDate); } else { prepStmt.setString(7, questionContainerHeader.getBeginDate()); } if ((questionContainerHeader.getEndDate() == null) || (questionContainerHeader.getEndDate().length() < 10)) { prepStmt.setString(8, nullEndDate); } else { prepStmt.setString(8, questionContainerHeader.getEndDate()); } prepStmt.setInt(9, 0); prepStmt.setInt(10, 0); prepStmt.setInt(11, questionContainerHeader.getNbQuestionsPerPage()); prepStmt.setInt(12, questionContainerHeader.getNbMaxParticipations()); prepStmt.setInt(13, questionContainerHeader.getNbParticipationsBeforeSolution()); prepStmt.setInt(14, questionContainerHeader.getMaxTime()); prepStmt.setString(15, questionContainerHeader.getPK().getComponentName()); if (questionContainerHeader.isAnonymous()) { prepStmt.setInt(16, 1); } else { prepStmt.setInt(16, 0); } prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } return questionContainerPK; }