TransactionRunner (Sleepycat Software, Inc. - Berkeley DB Java API)
Keywords: com.sleepycat.bdb.TransactionRunner,TransactionRunner class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.2.52
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sleepycat.bdb
Class TransactionRunner

    java.lang.Object
      |
      +--com.sleepycat.bdb.TransactionRunner

public class TransactionRunner
extends Object

Starts a transaction, calls `TransactionWorker.doWork()`, and handles transaction retry and exceptions.

Constructor Summary
`TransactionRunner(DbEnv env)` Creates a transaction runner for a given Berkeley DB environment.
`TransactionRunner(DbEnv env, int maxRetries)` Creates a transaction runner for a given Berkeley DB environment and with a given number of maximum retries.

Method Summary
`boolean` | `getDirtyRead()` Returns whether transactions will read data that is modified by another transaction but not committed.
`int` | `getMaxRetries()` Returns the maximum number of retries that will be performed when deadlocks are detected.
`boolean` | `getNoWait()` Returns whether transactions will throw DbLockNotGrantedException instead of blocking when trying to access data that is locked by another transaction.
`void` | `run(TransactionWorker worker)` Calls the `TransactionWorker.doWork()` method and, for transactional environments, begins and ends a transaction.
`void` | `setDirtyRead(boolean dirtyRead)` Changes whether transactions will read data that is modified by another transaction but not committed.
`void` | `setMaxRetries(int maxRetries)` Changes the maximum number of retries that will be performed when deadlocks are detected.
`void` | `setNoWait(boolean noWait)` Changes whether transactions will throw DbLockNotGrantedException instead of blocking when trying to access data that is locked by another transaction.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### TransactionRunner

    public TransactionRunner(DbEnv env)

  Creates a transaction runner for a given Berkeley DB environment. The default maximum number of retries (10) will be used.

Parameters:
  `env` - is the environment for running transactions.

### TransactionRunner

    public TransactionRunner(DbEnv env,
                             int maxRetries)

  Creates a transaction runner for a given Berkeley DB environment and with a given number of maximum retries.

Parameters:
  `env` - is the environment for running transactions.
  `maxRetries` - is the maximum number of retries that will be performed when deadlocks are detected.

Method Detail

### getMaxRetries

    public int getMaxRetries()

  Returns the maximum number of retries that will be performed when deadlocks are detected.

### setMaxRetries

    public void setMaxRetries(int maxRetries)

  Changes the maximum number of retries that will be performed when deadlocks are detected. Calling this method does not impact transactions already running.

### getDirtyRead

    public boolean getDirtyRead()

  Returns whether transactions will read data that is modified by another transaction but not committed.

### setDirtyRead

    public void setDirtyRead(boolean dirtyRead)

  Changes whether transactions will read data that is modified by another transaction but not committed. Calling this method does not impact transaction already running.

### getNoWait

    public boolean getNoWait()

  Returns whether transactions will throw DbLockNotGrantedException instead of blocking when trying to access data that is locked by another transaction.

### setNoWait

    public void setNoWait(boolean noWait)

  Changes whether transactions will throw DbLockNotGrantedException instead of blocking when trying to access data that is locked by another transaction.

### run

    public void run(TransactionWorker worker)
             throws DbException,
                    Exception

  Calls the `TransactionWorker.doWork()` method and, for transactional environments, begins and ends a transaction. If the environment given is non-transactional, a transaction will not be used but the doWork() method will still be called.

  In a transactional environment, a new transaction is started before calling doWork(). This will start a nested transaction if one is already active. If DbDeadlockException is thrown by doWork(), the transaction will be aborted and the process will be repeated up to the maximum number of retries specified. If another exception is thrown by doWork() or the maximum number of retries has occurred, the transaction will be aborted and the exception will be rethrown by this method. If no exception is thrown by doWork(), the transaction will be committed. This method will not attempt to commit or abort a transaction if it has already been committed or aborted by doWork().

  Throws:
    `DbDeadlockException` - when it is thrown by doWork() and the maximum number of retries has occurred. The transaction will have been aborted by this method.
    `Exception` - when any other exception is thrown by doWork(). The exception will first be unwrapped by calling `ExceptionUnwrapper.unwrap(java.lang.Exception)`. The transaction will have been aborted by this method.
    `DbException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.2.52
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.