Beispiel #1
0
  /** Binding version of Cursor.getSearchKeyRange(), no join cursor allowed. */
  OperationStatus getSearchKeyRange(Object key, Object value, boolean lockForWrite)
      throws DatabaseException {

    checkNoJoinCursor();
    LockMode lockMode = getLockMode(lockForWrite);
    if (view.dupsView) {
      if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) {
        KeyRange.copy(view.dupsKey, keyThang);
        return cursor.getSearchBothRange(keyThang, primaryKeyThang, valueThang, lockMode);
      }
    } else {
      if (view.useKey(key, value, keyThang, range)) {
        return cursor.getSearchKeyRange(keyThang, primaryKeyThang, valueThang, lockMode);
      }
    }
    return OperationStatus.NOTFOUND;
  }
Beispiel #2
0
  /**
   * Find the given key and value using getSearchBoth if possible or a sequential scan otherwise, no
   * join cursor allowed.
   */
  OperationStatus findBoth(Object key, Object value, boolean lockForWrite)
      throws DatabaseException {

    checkNoJoinCursor();
    LockMode lockMode = getLockMode(lockForWrite);
    view.useValue(value, valueThang, null);
    if (view.dupsView) {
      if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) {
        KeyRange.copy(view.dupsKey, keyThang);
        if (otherThang == null) {
          otherThang = new DatabaseEntry();
        }
        OperationStatus status =
            cursor.getSearchBoth(keyThang, primaryKeyThang, otherThang, lockMode);
        if (status == OperationStatus.SUCCESS && KeyRange.equalBytes(otherThang, valueThang)) {
          return status;
        }
      }
    } else if (view.useKey(key, value, keyThang, range)) {
      if (view.isSecondary()) {
        if (otherThang == null) {
          otherThang = new DatabaseEntry();
        }
        OperationStatus status =
            cursor.getSearchKey(keyThang, primaryKeyThang, otherThang, lockMode);
        while (status == OperationStatus.SUCCESS) {
          if (KeyRange.equalBytes(otherThang, valueThang)) {
            return status;
          }
          status =
              cursor.getNextDup(
                  keyThang, primaryKeyThang,
                  otherThang, lockMode);
        }
        /* if status != SUCCESS set range cursor to invalid? */
      } else {
        return cursor.getSearchBoth(keyThang, null, valueThang, lockMode);
      }
    }
    return OperationStatus.NOTFOUND;
  }
Beispiel #3
0
  /** Do setup for a put() operation. */
  private void initForPut(Object key, Object value, Object[] oldValue, boolean useCurrentKey)
      throws DatabaseException {

    checkWriteAllowed(false);
    if (!useCurrentKey && !view.useKey(key, value, keyThang, range)) {
      throw new IllegalArgumentException("key out of range");
    }
    if (oldValue != null) {
      oldValue[0] = null;
      if (!view.dupsAllowed) {
        OperationStatus status = doGetSearchKey(true);
        if (status == OperationStatus.SUCCESS) {
          oldValue[0] = getCurrentValue();
        }
      }
    }
    view.useValue(value, valueThang, keyThang);
  }