Example #1
0
  /**
   * Returns true if this set contains the specified element. This method conforms to the {@link
   * Set#contains} interface.
   *
   * @param mapEntry is a {@link java.util.Map.Entry} instance to be checked.
   * @return true if the key-value pair is present in the set, or false if the mapEntry is not a
   *     {@link java.util.Map.Entry} instance or is not present in the set.
   * @throws RuntimeExceptionWrapper if a {@link DatabaseException} is thrown.
   */
  public boolean contains(Object mapEntry) {

    if (!(mapEntry instanceof Map.Entry)) {
      return false;
    }
    Map.Entry entry = (Map.Entry) mapEntry;
    DataCursor cursor = null;
    try {
      cursor = new DataCursor(view, false);
      OperationStatus status = cursor.findBoth(entry.getKey(), entry.getValue(), false);
      return (status == OperationStatus.SUCCESS);
    } catch (Exception e) {
      throw StoredContainer.convertException(e);
    } finally {
      closeCursor(cursor);
    }
  }
Example #2
0
  /**
   * Removes the specified element from this set if it is present (optional operation). This method
   * conforms to the {@link Set#remove} interface.
   *
   * @param mapEntry is a {@link java.util.Map.Entry} instance to be removed.
   * @return true if the key-value pair was removed from the set, or false if the mapEntry is not a
   *     {@link java.util.Map.Entry} instance or is not present in the set.
   * @throws UnsupportedOperationException if the collection is read-only.
   * @throws RuntimeExceptionWrapper if a {@link DatabaseException} is thrown.
   */
  public boolean remove(Object mapEntry) {

    if (!(mapEntry instanceof Map.Entry)) {
      return false;
    }
    Map.Entry entry = (Map.Entry) mapEntry;
    DataCursor cursor = null;
    boolean doAutoCommit = beginAutoCommit();
    try {
      cursor = new DataCursor(view, true);
      OperationStatus status = cursor.findBoth(entry.getKey(), entry.getValue(), true);
      if (status == OperationStatus.SUCCESS) {
        cursor.delete();
      }
      closeCursor(cursor);
      commitAutoCommit(doAutoCommit);
      return (status == OperationStatus.SUCCESS);
    } catch (Exception e) {
      closeCursor(cursor);
      throw handleException(e, doAutoCommit);
    }
  }