Example #1
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;
  }
Example #2
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;
  }