Berkeley DB Java Edition Examples
version 4.0.103

je.rep.quote
Class RunTransaction

java.lang.Object
  extended by 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
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.


Berkeley DB Java Edition Examples
version 4.0.103

Copyright (c) 2004-2010 Oracle. All rights reserved.