RunTransaction (Oracle - Berkeley DB Java Edition Examples)
Date: 2014-12-16

je.rep.quote

## Class RunTransaction

- java.lang.Object
- - je.rep.quote.RunTransaction

-     public abstract class RunTransaction
      extends Object

  Utility class to begin and commit/abort a transaction and handle exceptions according to this application's policies. The doTransactionWork method is abstract and must be implemented by callers. The transaction is run and doTransactionWork is called by the run() method of this class. The onReplicaWrite and onRetryFailure methods may optionally be overridden.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `doTransactionWork(Transaction txn)` Must be implemented to perform operations using the given Transaction.
    `void` | `onReplicaWrite(ReplicaWriteException replicaWrite)` May be optionally overridden to handle a ReplicaWriteException.
    `void` | `onRetryFailure(OperationFailureException lastException)` May be optionally overridden to handle a failure after the TRANSACTION_RETRY_MAX has been exceeded.
    `void` | `run(boolean readOnly)` Runs a transaction, calls the doTransactionWork method, and retries as needed.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### run

          public void run(boolean readOnly)
                   throws InterruptedException,
                          EnvironmentFailureException

      Runs a transaction, calls the doTransactionWork method, and retries as needed.

      If the transaction is read only, it uses Durability.READ_ONLY_TXN for the Transaction. Since this Durability policy does not call for any acknowledgments, it eliminates the possibility of a `InsufficientReplicasException` being thrown from the call to `Environment.beginTransaction(com.sleepycat.je.Transaction, com.sleepycat.je.TransactionConfig)` for a read only transaction on a Master, which is an overly stringent requirement. This makes the Master more available for read operations.

      Parameters:
        `readOnly` - determines whether the transaction to be run is read only.
      Throws:
        `InterruptedException`
        `EnvironmentFailureException`

    - #### doTransactionWork

          public abstract void doTransactionWork(Transaction txn)

      Must be implemented to perform operations using the given Transaction.

    - #### onReplicaWrite

          public void onReplicaWrite(ReplicaWriteException replicaWrite)

      May be optionally overridden to handle a ReplicaWriteException. After this method is called, the RunTransaction constructor will return. By default, this method throws the ReplicaWriteException.

    - #### onRetryFailure

          public void onRetryFailure(OperationFailureException lastException)

      May be optionally overridden to handle a failure after the TRANSACTION_RETRY_MAX has been exceeded. After this method is called, the RunTransaction constructor will return. By default, this method prints the last exception.

Copyright (c) 2004, 2014 Oracle and/or its affiliates. All rights reserved.