Esempio n. 1
0
  /**
   * Updates the given entry. If no error occurs, the number of updated rows is returned.
   *
   * @param entry the entry to updated
   * @return the number of updated rows
   * @throws DataAccessException if an error occurs
   */
  public int updateRegistryEntry(RegistryEntry entry) throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;
    int rowsUpdated = 0;

    try {

      con = getConnection();

      ps = con.prepareStatement(queryDesc.getUpdateEntryQuery());

      ps.setLong(1, entry.getPeriod());
      ps.setString(2, entry.getActive() ? "Y" : "N");
      ps.setString(3, entry.getTaskBeanFile());
      ps.setLong(4, entry.getLastUpdate());
      ps.setString(5, RegistryEntryStatus.UPDATED);

      short numberOfExtraProperties = queryDesc.getNumberOfExtraColumns();
      String[] extraProperties = queryDesc.getExtraProperties();
      if (numberOfExtraProperties > 0) {
        short j = 0;
        for (; j < numberOfExtraProperties; j++) {
          Object value = null;
          if (entry.hasProperty(extraProperties[j])) {
            value = entry.getProperty(extraProperties[j]);
          }
          ps.setObject(6 + j, value);
        }
        ps.setLong(6 + j, entry.getId());
      } else {
        ps.setLong(6, entry.getId());
      }
      rowsUpdated = ps.executeUpdate();

    } catch (Exception e) {

      throw new DataAccessException("Error updating registry entry '" + entry.getId() + "'", e);

    } finally {
      DBTools.close(con, ps, null);
    }
    return rowsUpdated;
  }
Esempio n. 2
0
  /**
   * Inserts the given entry. If no error occurs, the entry id is returned and set as id in the
   * given entry object.
   *
   * @param entry the entry to updated
   * @return the entry id
   * @throws DataAccessException if an error occurs
   */
  public long insertRegistryEntry(RegistryEntry entry) throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;

    long id = getNextEntryId();

    try {

      con = getConnection();

      ps = con.prepareStatement(queryDesc.getInsertEntryQuery());

      ps.setLong(1, id);
      ps.setLong(2, entry.getPeriod());
      ps.setString(3, entry.getActive() ? "Y" : "N");
      ps.setString(4, entry.getTaskBeanFile());
      ps.setLong(5, entry.getLastUpdate());
      ps.setString(6, RegistryEntryStatus.NEW);

      short numberOfExtraProperties = queryDesc.getNumberOfExtraColumns();
      String[] extraProperties = queryDesc.getExtraProperties();
      if (numberOfExtraProperties > 0) {
        for (short j = 0; j < numberOfExtraProperties; j++) {
          Object value = null;
          if (entry.hasProperty(extraProperties[j])) {
            value = entry.getProperty(extraProperties[j]);
          }
          ps.setObject(7 + j, value);
        }
      }

      ps.executeUpdate();

      entry.setId(id);

    } catch (Exception e) {

      throw new DataAccessException("Error inserting a registry entry", e);

    } finally {
      DBTools.close(con, ps, null);
    }

    return id;
  }
Esempio n. 3
0
  /**
   * Creates a RegistryEntry reading the given ResultSet
   *
   * @return the RegistryEntry
   * @param rs the resultSet
   * @throws java.sql.SQLException if an error occurs
   */
  private RegistryEntry resultSetToRegistryEntry(ResultSet rs) throws SQLException {

    RegistryEntry entry = new RegistryEntry();

    entry.setId(rs.getLong(1));
    entry.setPeriod(rs.getLong(2));
    entry.setActive("Y".equalsIgnoreCase(rs.getString(3)));
    entry.setTaskBeanFile(rs.getString(4));
    entry.setLastUpdate(rs.getLong(5));

    String s = rs.getString(6);
    if (s == null || s.length() == 0) {
      entry.setStatus(RegistryEntryStatus.UNKNOWN);
    }
    if ("N".equals(s)) {
      entry.setStatus(RegistryEntryStatus.NEW);
    } else if ("U".equals(s)) {
      entry.setStatus(RegistryEntryStatus.UPDATED);
    } else if ("D".equals(s)) {
      entry.setStatus(RegistryEntryStatus.DELETED);
    } else {
      entry.setStatus(RegistryEntryStatus.UNKNOWN);
    }

    short numberOfExtraProperties = queryDesc.getNumberOfExtraColumns();
    String[] extraProperties = queryDesc.getExtraProperties();

    if (numberOfExtraProperties > 0) {
      Map<String, Object> extraPropertiesMap = new LinkedHashMap<String, Object>();
      for (short j = 0; j < numberOfExtraProperties; j++) {
        extraPropertiesMap.put(extraProperties[j], rs.getObject(7 + j));
      }
      entry.setProperties(extraPropertiesMap);
    }

    return entry;
  }