Caller must hold transaction lock. May throw FetchException if storage
is closed.
196585
Object getPrimaryDatabase() throws FetchException {
        Object database = mPrimaryDatabase;
        if (database == null) {
            checkClosed();
            throw new IllegalStateException("BDBStorage not opened");
        }
        return database;
    }
905628
public void lock() throws FileLockException, IOException {
        if (mode == AccessMode.READ_ONLY) {
            return;
        }

        for (int retries = 0; retries < max_retries_connect; retries++) {
            try {
                fileLock = channel.lock();
                break; // the lock was succesful
            } catch (OverlappingFileLockException e) {
                try {
                    logger.debug("Can't open file '" + osFile.getAbsolutePath()
                            + "' because it's locked. Waiting {} ms and retry {}", RETRY_CONNECT_WAITTIME,
                            retries);
                    System.runFinalization(); // FORCE FINALIZATION TO COLLECT ALL THE PENDING BUFFERS
                    Thread.sleep(RETRY_CONNECT_WAITTIME);
                } catch (InterruptedException ex) {
                    // will throw a FileLockException further
                }
            }
        }

        if (fileLock == null) {
            this.close();
            throw new FileLockException("File " + osFile.getPath()
                    + " is locked by another process, maybe the database is in use by another process.");
        }
    }
711847
public void acquireLock (final NodeObject.Lock lock, final ResultListener<String> listener)
    {
        // wait until any pending resolution is complete
        queryLock(lock, new ChainedResultListener<String, String>(listener) {
            public void requestCompleted (String result) {
                if (result == null) {
                    if (_suboids.isEmpty()) {
                        lockAcquired(lock, 0L, listener);
                    } else {
                        _locks.put(lock, new LockHandler(lock, true, listener));
                    }
                } else {
                    listener.requestCompleted(result);
                }
            }
        });
    }
492412
@Override
	public void commitChanges( SynchronizationBarrier barrier ) throws JMSException
    {
    	checkNotClosed();
    	checkTransactionLock();
    	
    	if (persistentStore != null)
    	{
    		long start = System.currentTimeMillis();
    		synchronized (storeLock)
			{
    			persistentStore.commitChanges(barrier);
			}
    		long end = System.currentTimeMillis();
    		notifyCommitTime(end-start);

    		// Clear pending commit flag
    		pendingChanges = false;
    	}
    }
1362556
function TransactionTask(readOnly, txnCallback, errorCallback, successCallback) {
  this.readOnly = readOnly;
  this.txnCallback = txnCallback;
  this.errorCallback = errorCallback;
  this.successCallback = successCallback;
}
228809
CompletableFuture<Collection<Xid>> fetchPreparedTransactions() {
      try {
         TransactionOperationFactory factory = assertStartedAndReturnFactory();
         return factory.newRecoveryOperation().execute();
      } catch (Exception e) {
         if (isTraceLogEnabled()) {
            getLog().trace("Exception while fetching prepared transactions", e);
         }
         return CompletableFuture.completedFuture(Collections.emptyList());
      }
   }
250708
void checkAllLocks() throws BackendException {
        StoreTransaction lt = getConsistentTx();
        for (ExpectedValueCheckingStore store : expectedValuesByStore.keySet()) {
            Locker locker = store.getLocker();
            // Ignore locks on stores without a locker
            if (null == locker)
                continue;
            locker.checkLocks(lt);
        }
    }
324330
private Transaction getAndValidateWrappedTransaction() throws IllegalStateException {
		final Transaction wrappedTransaction = getWrappedTransaction();
		if (wrappedTransaction == null) {
			throw new IllegalStateException();
		}
		else { 
			return wrappedTransaction;
		}
	}
1318920
public Connection getConnection() throws FetchException {
        try {
            if (mOpenConnections == null) {
                throw new FetchException("Repository is closed");
            }

            JDBCTransaction txn = localTransactionScope().getTxn();
            if (txn != null) {
                // Return the connection used by the current transaction.
                return txn.getConnection();
            }

            // Get connection outside lock section since it may block.
            Connection con = mDataSource.getConnection();
            con.setAutoCommit(true);

            mOpenConnectionsLock.lock();
            try {
                if (mOpenConnections == null) {
                    con.close();
                    throw new FetchException("Repository is closed");
                }
                mOpenConnections.put(con, null);
            } finally {
                mOpenConnectionsLock.unlock();
            }

            return con;
        } catch (Exception e) {
            throw toFetchException(e);
        }
    }
855752
public void commitTransaction()
   {
      CompressedISPNChangesBuffer changesContainer = getChangesBufferSafe();
      final TransactionManager tm = getTransactionManager();
      try
      {
         final List<ChangesContainer> containers = changesContainer.getSortedList();
         commitChanges(tm, containers);
      }
      finally
      {
         changesList.set(null);
         changesContainer = null;
      }
   }
587902
def transaction(&block)
			Thread.current[:txids] = []
			ODBA.storage.transaction(&block)
		rescue Exception => excp
			transaction_rollback
			raise excp
		ensure
			Thread.current[:txids] = nil
		end
1155863
public static TransactionException transactionClosed(@Nullable TransactionOLTP tx, @Nullable String reason) {
        if (reason == null) {
            Preconditions.checkNotNull(tx);
            return create(ErrorMessage.TX_CLOSED.getMessage(tx.keyspace()));
        } else {
            return create(reason);
        }
    }
315707
def _AcquireLock(self,
                   urn,
                   blocking=None,
                   blocking_lock_timeout=None,
                   lease_time=None,
                   blocking_sleep_interval=None):
    """"""
    if urn is None:
      raise ValueError("URN cannot be None")

    urn = rdfvalue.RDFURN(urn)

    try:
      return data_store.DB.LockRetryWrapper(
          urn,
          retrywrap_timeout=blocking_sleep_interval,
          retrywrap_max_timeout=blocking_lock_timeout,
          blocking=blocking,
          lease_time=lease_time)
    except data_store.DBSubjectLockError as e:
      raise LockError(e)
1339135
private int tryAcquireExclusiveTransaction(@NotNull final Thread thread, final int timeout) {
        long nanos = TimeUnit.MILLISECONDS.toNanos(timeout);
        try (CriticalSection ignored = criticalSection.enter()) {
            if (getThreadPermits(thread) > 0) {
                throw new ExodusException("Exclusive transaction can't be nested");
            }
            final Condition condition = criticalSection.newCondition();
            final long currentOrder = acquireOrder++;
            regularQueue.put(currentOrder, condition);
            while (acquiredPermits > 0 || regularQueue.firstKey() != currentOrder) {
                try {
                    nanos = condition.awaitNanos(nanos);
                    if (nanos < 0) {
                        break;
                    }
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    break;
                }
            }
            if (acquiredPermits == 0 && regularQueue.firstKey() == currentOrder) {
                regularQueue.pollFirstEntry();
                acquiredPermits = availablePermits;
                threadPermits.put(thread, availablePermits);
                return availablePermits;
            }
            regularQueue.remove(currentOrder);
            notifyNextWaiters();
        }
        return 0;
    }
1155483
public synchronized void unlock() throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "unlock", this);

        // If the subscription locks are down to zero then notify the threads waiting
        // for the subscriptionTable lock.
        synchronized (iMutex)
        {
            // If we are exclusively locked, then just return, as long as
            // the thread that is calling is the thread that holds the
            // exclusive lock.
            if (iExclusivelyLocked && iExclusiveLockHolder == Thread.currentThread())
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
                return;
            }

            // Decrement the lock count and notify the other threads if no
            // one holds the lock any more.
            if (--iLockCount == 0)
                notifyAll();

            if (iLockCount < 0)
            {
            	if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.event(this, tc, "Unlock caused lock count to drop below zero!");
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
                throw new SevereMessageStoreException("Unlock caused lock count to drop below zero!");
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unlock");
    }
392953
public final void commitPersistUnlock(PersistentTransaction transaction) throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "commitPersistUnlock", transaction);

        AbstractItem item = null;
        boolean hasBecomeAvailable = false;
        boolean linkHasBecomeReleasable = false;
        synchronized (this)
        {
            if (ItemLinkState.STATE_UNLOCKING_PERSISTENTLY_LOCKED == _itemLinkState)
            {
                _assertCorrectTransaction(transaction);

                item = getItem();

                ListStatistics stats = getParentStatistics();
                synchronized (stats)
                {
                    stats.decrementLocked();
                    stats.incrementAvailable();
                }

                // Save the item before we change the state
                _lockID = NO_LOCK_ID;
                _unlockCount++;
                linkHasBecomeReleasable = _declareDiscardable();
                _itemLinkState = ItemLinkState.STATE_AVAILABLE;
                hasBecomeAvailable = true;
            }
            else
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                    SibTr.event(this, tc, "Invalid Item state: " + _itemLinkState);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(this, tc, "commitPersistUnlock");
                throw new StateException(_itemLinkState.toString());
            }
            _transactionId = null;
        }
        // this stuff has to be done outside the synchronized block
        if (linkHasBecomeReleasable)
        {
            _declareReleasable(item);
        }

        // PK37596
        // Now we have completed an unlock we have become available again
        // and so need to inform our containing list in case we need to
        // be added to a cursors jumpback list.
        if (hasBecomeAvailable)
        {
            // all items are discardable in avaialable state.
            if (_owningStreamLink != null)
            {
                _owningStreamLink.linkAvailable(this);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "commitPersistUnlock");
    }
37255
public void fetchRemaining() throws SQLException {
    if (!isEof) {
      lock.lock();
      try {
        lastRowPointer = -1;
        while (!isEof) {
          addStreamingValue();
        }

      } catch (SQLException queryException) {
        throw ExceptionMapper.getException(queryException, null, statement, false);
      } catch (IOException ioe) {
        throw handleIoException(ioe);
      } finally {
        lock.unlock();
      }
      dataFetchTime++;
    }
  }