Example #1
0
  /**
   * Repositions to a given raw key/data pair.
   *
   * @throws IllegalStateException when the database has unordered keys or unordered duplicates.
   * @return whether the search succeeded.
   */
  boolean repositionExact(
      byte[] keyBytes, byte[] priKeyBytes, byte[] valueBytes, boolean lockForWrite)
      throws DatabaseException {

    LockMode lockMode = getLockMode(lockForWrite);
    OperationStatus status = null;

    /* Use the given key/data byte arrays. */
    setThangs(keyBytes, priKeyBytes, valueBytes);

    /* Position on the given key/data pair. */
    if (view.recNumRenumber) {
      /* getSearchBoth doesn't work with recno-renumber databases. */
      status =
          cursor.getSearchKey(
              keyThang, primaryKeyThang,
              valueThang, lockMode);
    } else {
      status =
          cursor.getSearchBoth(
              keyThang, primaryKeyThang,
              valueThang, lockMode);
    }

    return (status == OperationStatus.SUCCESS);
  }
Example #2
0
  /**
   * Repositions to a given raw key/data pair, or just past it if that record has been deleted.
   *
   * @return REPOS_EXACT, REPOS_NEXT or REPOS_EOF.
   */
  int repositionRange(byte[] keyBytes, byte[] priKeyBytes, byte[] valueBytes, boolean lockForWrite)
      throws DatabaseException {

    LockMode lockMode = getLockMode(lockForWrite);
    OperationStatus status = null;

    /* Use the given key/data byte arrays. */
    setThangs(keyBytes, priKeyBytes, valueBytes);

    /* Position on or after the given key/data pair. */
    if (view.dupsAllowed) {
      status =
          cursor.getSearchBothRange(
              keyThang, primaryKeyThang,
              valueThang, lockMode);
    }
    if (status != OperationStatus.SUCCESS) {
      status =
          cursor.getSearchKeyRange(
              keyThang, primaryKeyThang,
              valueThang, lockMode);
    }

    /* Return the result of the operation. */
    if (status == OperationStatus.SUCCESS) {
      if (!KeyRange.equalBytes(
          keyBytes,
          0,
          keyBytes.length,
          keyThang.getData(),
          keyThang.getOffset(),
          keyThang.getSize())) {
        return REPOS_NEXT;
      }
      if (view.dupsAllowed) {
        DatabaseEntry thang = view.isSecondary() ? primaryKeyThang : valueThang;
        byte[] bytes = view.isSecondary() ? priKeyBytes : valueBytes;
        if (!KeyRange.equalBytes(
            bytes, 0, bytes.length, thang.getData(), thang.getOffset(), thang.getSize())) {
          return REPOS_NEXT;
        }
      }
      return REPOS_EXACT;
    } else {
      return REPOS_EOF;
    }
  }