Exemplo n.º 1
0
  public void setVacationSettings(AccessToken token, VacationSettings vs) {
    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = obmHelper.getConnection();

      String query =
          "UPDATE UserObm SET "
              + "userobm_vacation_enable=?, "
              + "userobm_vacation_datebegin=?, "
              + "userobm_vacation_dateend=?, "
              + "userobm_vacation_message=? "
              + "WHERE userobm_id=?";

      ps = con.prepareStatement(query);

      int i = 1;
      ps.setInt(i++, vs.isEnabled() ? 1 : 0);
      if (vs.getStart() != null) {
        ps.setTimestamp(i++, new Timestamp(vs.getStart().getTime()));
      } else {
        ps.setNull(i++, Types.TIMESTAMP);
      }
      if (vs.getEnd() != null) {
        ps.setTimestamp(i++, new Timestamp(vs.getEnd().getTime()));
      } else {
        ps.setNull(i++, Types.TIMESTAMP);
      }
      ps.setString(i++, vs.getText());
      ps.setInt(i++, token.getObmId());

      ps.executeUpdate();
    } catch (SQLException e) {
      logger.error("Could not store vacation settings for " + token.getUserLogin(), e);
    } finally {
      obmHelper.cleanup(con, ps, null);
    }
  }