コード例 #1
0
 @Override
 public SimpleTurn mapRow(ResultSet rs, int number) throws SQLException {
   SimpleTurn turn;
   int uid = rs.getInt("uid");
   int prayer_id = rs.getInt("prayer_id");
   String day = rs.getString("day");
   String hour = rs.getString("hour");
   String status = rs.getString("status");
   String notes = rs.getString("notes");
   int pax = rs.getInt("pax");
   try {
     turn =
         new SimpleTurn(
             uid,
             prayer_id,
             DayOfWeek.valueOf(day),
             SimpleTurn.getTurnByHour(hour),
             TurnStatus.valueOf(status),
             notes,
             pax);
   } catch (TurnException e) {
     throw new RuntimeException(e.toString());
   }
   return turn;
 }
コード例 #2
0
  @RequestMapping(method = RequestMethod.POST)
  public ModelAndView processForm(
      @ModelAttribute("turn2Change") JSPSimpleTurn turn2Change, Errors errors) {

    resetForm();
    model.put("turn2Change", turn2Change);

    /* If this is the first hit to the page from another page, then it doesn't need to be validated.
     * Just, present the form to the user
     */
    if (!turn2Change.isFirstCall()) {

      turn2Change.setFirstCall(false);

      validator.validate(turn2Change, errors);

      // Prepare a simpleTurn
      if (errors.hasErrors()) {
        return new ModelAndView("/web/ChangeTurn.jsp", model);
      }

      int turnUid = Integer.parseInt(turn2Change.getUid());
      int prayerID = Integer.parseInt(turn2Change.getPrayer_id());
      DayOfWeek dow = DayOfWeek.valueOf(turn2Change.getDow());
      int turn2Add = turn2Change.getTurnInt();
      TurnStatus status = TurnStatus.valueOf(turn2Change.getStatus());
      SimpleTurn turn2BeAdded =
          new SimpleTurn(turnUid, prayerID, dow, turn2Add, status, turn2Change.getNotes(), 1);
      try {
        main.changeTurn(turn2BeAdded);
        return new ModelAndView("/web/TurnModified.jsp");
      } catch (TurnException e) {
        throw new RuntimeException(
            "There were a fatal error while trying to update a turn into the ddbb. "
                + e.toString());
      }

    } else {
      return new ModelAndView("/web/ChangeTurn.jsp", model);
    }

    // If errors, there's no need to process the form. The user should correct any error first
  }