Esempio n. 1
0
  public VacationSettings getVacationSettings(AccessToken token) {
    VacationSettings ret = new VacationSettings();

    Connection con = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    try {
      con = obmHelper.getConnection();

      String query =
          "SELECT userobm_vacation_enable, userobm_vacation_datebegin, "
              + "userobm_vacation_dateend, userobm_vacation_message FROM UserObm "
              + "WHERE userobm_id=?";

      ps = con.prepareStatement(query);

      ps.setInt(1, token.getObmId());
      rs = ps.executeQuery();

      if (rs.next()) {
        ret.setEnabled(rs.getBoolean(1));
        Timestamp ts = rs.getTimestamp(2);
        if (ts != null) {
          ret.setStart(new Date(ts.getTime()));
        }
        ts = rs.getTimestamp(3);
        if (ts != null) {
          ret.setEnd(new Date(ts.getTime()));
        }
        ret.setText(rs.getString(4));
      }

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

    return ret;
  }
Esempio n. 2
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);
    }
  }