Example #1
0
  /** @throws RunRecoveryException if the underlying environment is invalid */
  void checkEnv() throws RunRecoveryException {

    EnvironmentImpl env = envHandle.getEnvironmentImpl();
    if (env != null) {
      env.checkIfInvalid();
    }
  }
Example #2
0
 public JoinCursor join__wrappee__base(Cursor[] cursors, JoinConfig config)
     throws DatabaseException {
   checkEnv();
   checkRequiredDbState(OPEN, "Can't call Database.join");
   DatabaseUtil.checkForNullParam(cursors, "cursors");
   if (cursors.length == 0) {
     throw new IllegalArgumentException("At least one cursor is required.");
   }
   Locker locker = cursors[0].getCursorImpl().getLocker();
   if (!locker.isTransactional()) {
     EnvironmentImpl env = envHandle.getEnvironmentImpl();
     for (int i = 1; i < cursors.length; i += 1) {
       Locker locker2 = cursors[i].getCursorImpl().getLocker();
       if (locker2.isTransactional()) {
         throw new IllegalArgumentException("All cursors must use the same transaction.");
       }
       EnvironmentImpl env2 = cursors[i].getDatabaseImpl().getDbEnvironment();
       if (env != env2) {
         throw new IllegalArgumentException("All cursors must use the same environment.");
       }
     }
     locker = null;
   } else {
     for (int i = 1; i < cursors.length; i += 1) {
       Locker locker2 = cursors[i].getCursorImpl().getLocker();
       if (locker.getTxnLocker() != locker2.getTxnLocker()) {
         throw new IllegalArgumentException("All cursors must use the same transaction.");
       }
     }
   }
   return new JoinCursor(locker, this, cursors, config);
 }
Example #3
0
  /**
   * Releases a lock acquired by calling acquireTriggerListWriteLock(). If the list is now empty
   * then it is set to null, that is, hasTriggers() will subsequently return false.
   */
  private void releaseTriggerListWriteLock() throws DatabaseException {

    if (triggerList.size() == 0) {
      triggerList = null;
    }
    EnvironmentImpl env = envHandle.getEnvironmentImpl();
    env.getTriggerLatch().release();
  }
Example #4
0
  /**
   * Gets a write lock on the list of triggers. An empty list is created if necessary, so null is
   * never returned. releaseTriggerListWriteLock() must always be called to release the lock.
   */
  private void acquireTriggerListWriteLock() throws DatabaseException {

    EnvironmentImpl env = envHandle.getEnvironmentImpl();
    env.getTriggerLatch().acquireExclusive();
    if (triggerList == null) {
      triggerList = new ArrayList();
    }
  }
Example #5
0
  /**
   * @deprecated It has not been possible to implement this method with correct transactional
   *     semantics without incurring a performance penalty on all Database operations. Truncate
   *     functionality has been moved to Environment.truncateDatabase(), which requires that all
   *     Database handles on the database are closed before the truncate operation can execute.
   */
  public int truncate(Transaction txn, boolean countRecords) throws DatabaseException {

    checkEnv();
    checkRequiredDbState(OPEN, "Can't call Database.truncate");
    checkWritable("truncate");
    Tracer.trace(
        Level.FINEST,
        envHandle.getEnvironmentImpl(),
        "Database.truncate" + ": txnId=" + ((txn == null) ? "null" : Long.toString(txn.getId())));

    Locker locker = null;
    boolean triggerLock = false;
    boolean operationOk = false;

    try {
      locker =
          LockerFactory.getWritableLocker(
              envHandle, txn, isTransactional(), true /*retainLocks*/, null);

      /*
       * Pass true to always get a read lock on the triggers, so we are
       * sure that no secondaries are added during truncation.
       */
      acquireTriggerListReadLock();
      triggerLock = true;

      /* Truncate primary. */
      int count = truncateInternal(locker, countRecords);

      /* Truncate secondaries. */
      for (int i = 0; i < triggerList.size(); i += 1) {
        Object obj = triggerList.get(i);
        if (obj instanceof SecondaryTrigger) {
          SecondaryDatabase secDb = ((SecondaryTrigger) obj).getDb();
          secDb.truncateInternal(locker, false);
        }
      }

      operationOk = true;
      return count;
    } finally {
      if (locker != null) {
        locker.operationEnd(operationOk);
      }
      if (triggerLock) {
        releaseTriggerListReadLock();
      }
    }
  }
Example #6
0
  public JoinCursor join(Cursor[] cursors, JoinConfig config) throws DatabaseException {

    checkEnv();
    checkRequiredDbState(OPEN, "Can't call Database.join");
    DatabaseUtil.checkForNullParam(cursors, "cursors");
    if (cursors.length == 0) {
      throw new IllegalArgumentException("At least one cursor is required.");
    }

    /*
     * Check that all cursors use the same locker, if any cursor is
     * transactional.  And if non-transactional, that all databases are in
     * the same environment.
     */
    Locker locker = cursors[0].getCursorImpl().getLocker();
    if (!locker.isTransactional()) {
      EnvironmentImpl env = envHandle.getEnvironmentImpl();
      for (int i = 1; i < cursors.length; i += 1) {
        Locker locker2 = cursors[i].getCursorImpl().getLocker();
        if (locker2.isTransactional()) {
          throw new IllegalArgumentException("All cursors must use the same transaction.");
        }
        EnvironmentImpl env2 = cursors[i].getDatabaseImpl().getDbEnvironment();
        if (env != env2) {
          throw new IllegalArgumentException("All cursors must use the same environment.");
        }
      }
      locker = null; /* Don't reuse a non-transactional locker. */
    } else {
      for (int i = 1; i < cursors.length; i += 1) {
        Locker locker2 = cursors[i].getCursorImpl().getLocker();
        if (locker.getTxnLocker() != locker2.getTxnLocker()) {
          throw new IllegalArgumentException("All cursors must use the same transaction.");
        }
      }
    }

    /* Create the join cursor. */
    return new JoinCursor(locker, this, cursors, config);
  }
Example #7
0
  /**
   * Internal unchecked truncate that optionally counts records.
   *
   * @deprecated
   */
  int truncateInternal(Locker locker, boolean countRecords) throws DatabaseException {

    if (databaseImpl == null) {
      throw new DatabaseException("couldn't find database - truncate");
    }
    databaseImpl.checkIsDeleted("truncate");

    /*
     * Truncate must obtain a write lock. In order to do so, it assumes
     * ownership for the handle lock and transfers it from this Database
     * object to the txn.
     */
    if (handleLocker.isHandleLockTransferrable()) {
      handleLocker.transferHandleLock(this, locker, false);
    }

    boolean operationOk = false;
    try {

      /*
       * truncate clones the existing database and returns a new one to
       * replace it with.  The old databaseImpl object is marked
       * 'deleted'.
       */
      TruncateResult result = envHandle.getEnvironmentImpl().truncate(locker, databaseImpl);
      databaseImpl = result.getDatabase();

      operationOk = true;
      return countRecords ? result.getRecordCount() : -1;
    } finally {

      /*
       * The txn will know if it's living past the end of this operation,
       * and if it needs to transfer the handle lock.  operationEnd()
       * will be called one level up by the public truncate() method.
       */
      locker.setHandleLockOwner(operationOk, this, false);
    }
  }
Example #8
0
  /** Releases a lock acquired by calling acquireTriggerListReadLock(). */
  private void releaseTriggerListReadLock() throws DatabaseException {

    EnvironmentImpl env = envHandle.getEnvironmentImpl();
    env.getTriggerLatch().release();
  }
Example #9
0
 /**
  * Creates a database but does not open or fully initialize it. Is protected for use in compat
  * package.
  */
 protected Database(Environment env) {
   this.envHandle = env;
   handleLocker = null;
   logger = envHandle.getEnvironmentImpl().getLogger();
 }