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

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

## com.sleepycat.collections
Class TransactionRunner

    java.lang.Object
      com.sleepycat.collections.TransactionRunner

public class TransactionRunner
extends Object

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

Field Summary
`static int` | `DEFAULT_MAX_RETRIES` The default maximum number of retries.

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

Method Summary
`boolean` | `getAllowNestedTransactions()` Returns whether nested transactions will be created if `run()` is called when a transaction is already active for the current thread.
`int` | `getMaxRetries()` Returns the maximum number of retries that will be performed when deadlocks are detected.
`TransactionConfig` | `getTransactionConfig()` Returns the transaction configuration used for calling `Environment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig)`.
`void` | `run(TransactionWorker worker)` Calls the `TransactionWorker.doWork()` method and, for transactional environments, begins and ends a transaction.
`void` | `setAllowNestedTransactions(boolean allowNestedTxn)` Changes whether nested transactions will be created if `run()` is called when a transaction is already active for the current thread.
`void` | `setMaxRetries(int maxRetries)` Changes the maximum number of retries that will be performed when deadlocks are detected.
`void` | `setTransactionConfig(TransactionConfig config)` Changes the transaction configuration used for calling `Environment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig)`.

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

Field Detail

### DEFAULT_MAX_RETRIES

    public static final int DEFAULT_MAX_RETRIES

  The default maximum number of retries.

  See Also:
    Constant Field Values

Constructor Detail

### TransactionRunner

    public TransactionRunner(Environment env)

  Creates a transaction runner for a given Berkeley DB environment. The default maximum number of retries (`DEFAULT_MAX_RETRIES`) and a null (default) `TransactionConfig` will be used.

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

### TransactionRunner

    public TransactionRunner(Environment env,
                             int maxRetries,
                             TransactionConfig config)

  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.
  `config` - the transaction configuration used for calling `Environment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig)`, or null to use the default configuration. The configuration object is not cloned, and any modifications to it will impact subsequent transactions.

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.

### getAllowNestedTransactions

    public boolean getAllowNestedTransactions()

  Returns whether nested transactions will be created if `run()` is called when a transaction is already active for the current thread. By default this property is false.

### setAllowNestedTransactions

    public void setAllowNestedTransactions(boolean allowNestedTxn)

  Changes whether nested transactions will be created if `run()` is called when a transaction is already active for the current thread. Calling this method does not impact transactions already running.

### getTransactionConfig

    public TransactionConfig getTransactionConfig()

  Returns the transaction configuration used for calling `Environment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig)`.

  If this property is null, the default configuration is used. The configuration object is not cloned, and any modifications to it will impact subsequent transactions.

  Returns:
    the transaction configuration.

### setTransactionConfig

    public void setTransactionConfig(TransactionConfig config)

  Changes the transaction configuration used for calling `Environment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig)`.

  If this property is null, the default configuration is used. The configuration object is not cloned, and any modifications to it will impact subsequent transactions.

  Parameters:
    `config` - the transaction configuration.

### run

    public void run(TransactionWorker worker)
             throws DatabaseException,
                    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 DeadlockException 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:
    `DeadlockException` - 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.
    `DatabaseException`

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

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