Ejemplo n.º 1
0
  public OperationStatus getSearchBoth(
      Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode)
      throws DatabaseException {

    checkEnv();
    DatabaseUtil.checkForNullDbt(key, "key", true);
    DatabaseUtil.checkForNullDbt(data, "data", true);
    checkRequiredDbState(OPEN, "Can't call Database.getSearchBoth:");
    trace(Level.FINEST, "Database.getSearchBoth", txn, key, data, lockMode);

    CursorConfig cursorConfig = CursorConfig.DEFAULT;
    if (lockMode == LockMode.READ_COMMITTED) {
      cursorConfig = CursorConfig.READ_COMMITTED;
      lockMode = null;
    }

    Cursor cursor = null;
    try {
      cursor = new Cursor(this, txn, cursorConfig);
      cursor.setNonCloning(true);
      return cursor.search(key, data, lockMode, SearchMode.BOTH);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
Ejemplo n.º 2
0
  /** Javadoc for this public method is generated via the doc templates in the doc_src directory. */
  public Sequence openSequence(Transaction txn, DatabaseEntry key, SequenceConfig config)
      throws DatabaseException {

    checkEnv();
    DatabaseUtil.checkForNullDbt(key, "key", true);
    checkRequiredDbState(OPEN, "Can't call Database.openSequence:");
    checkWritable("openSequence");
    trace(Level.FINEST, "Database.openSequence", txn, key, null, null);

    return new Sequence(this, txn, key, config);
  }
Ejemplo n.º 3
0
  public synchronized void close() throws DatabaseException {

    StringBuffer errors = null;

    checkEnv();
    checkProhibitedDbState(CLOSED, "Can't close Database:");

    trace(Level.FINEST, "Database.close: ", null, null);

    /* Disassociate triggers before closing. */
    removeAllTriggers();

    envHandle.removeReferringHandle(this);
    if (cursors.size() > 0) {
      errors = new StringBuffer("There are open cursors against the database.\n");
      errors.append("They will be closed.\n");

      /*
       * Copy the cursors set before iterating since the dbc.close()
       * mutates the set.
       */
      Iterator iter = cursors.copy().iterator();
      while (iter.hasNext()) {
        Cursor dbc = (Cursor) iter.next();

        try {
          dbc.close();
        } catch (DatabaseException DBE) {
          errors.append("Exception while closing cursors:\n");
          errors.append(DBE.toString());
        }
      }
    }

    if (databaseImpl != null) {
      databaseImpl.removeReferringHandle(this);
      databaseImpl = null;

      /*
       * Tell our protecting txn that we're closing. If this type
       * of transaction doesn't live beyond the life of the handle,
       * it will release the db handle lock.
       */
      handleLocker.setHandleLockOwner(true, this, true);
      handleLocker.operationEnd(true);
      state = CLOSED;
    }

    if (errors != null) {
      throw new DatabaseException(errors.toString());
    }
  }
Ejemplo n.º 4
0
  public OperationStatus putNoDupData(Transaction txn, DatabaseEntry key, DatabaseEntry data)
      throws DatabaseException {

    checkEnv();
    DatabaseUtil.checkForNullDbt(key, "key", true);
    DatabaseUtil.checkForNullDbt(data, "data", true);
    DatabaseUtil.checkForPartialKey(key);
    checkRequiredDbState(OPEN, "Can't call Database.putNoDupData");
    checkWritable("putNoDupData");
    trace(Level.FINEST, "Database.putNoDupData", txn, key, data, null);

    return putInternal(txn, key, data, PutMode.NODUP);
  }
Ejemplo n.º 5
0
  public synchronized Cursor openCursor(Transaction txn, CursorConfig cursorConfig)
      throws DatabaseException {

    checkEnv();
    checkRequiredDbState(OPEN, "Can't open a cursor");
    CursorConfig useConfig = (cursorConfig == null) ? CursorConfig.DEFAULT : cursorConfig;

    if (useConfig.getReadUncommitted() && useConfig.getReadCommitted()) {
      throw new IllegalArgumentException(
          "Only one may be specified: ReadCommitted or ReadUncommitted");
    }

    trace(Level.FINEST, "Database.openCursor", txn, cursorConfig);
    Cursor ret = newDbcInstance(txn, useConfig);

    return ret;
  }
Ejemplo n.º 6
0
  public OperationStatus delete(Transaction txn, DatabaseEntry key) throws DatabaseException {

    checkEnv();
    DatabaseUtil.checkForNullDbt(key, "key", true);
    checkRequiredDbState(OPEN, "Can't call Database.delete:");
    checkWritable("delete");
    trace(Level.FINEST, "Database.delete", txn, key, null, null);

    OperationStatus commitStatus = OperationStatus.NOTFOUND;
    Locker locker = null;
    try {
      locker = LockerFactory.getWritableLocker(envHandle, txn, isTransactional());
      commitStatus = deleteInternal(locker, key);
      return commitStatus;
    } finally {
      if (locker != null) {
        locker.operationEnd(commitStatus);
      }
    }
  }