Exemplo 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;
  }