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

## com.sleepycat.je
Class Transaction

    java.lang.Object
      com.sleepycat.je.Transaction

    public class Transaction

extends Object

The Transaction object is the handle for a transaction. Methods off the transaction handle are used to configure, abort and commit the transaction. Transaction handles are provided to other Berkeley DB methods in order to transactionally protect those operations.

Transaction handles are free-threaded; transactions handles may be used concurrently by multiple threads. Once the `Transaction.abort` or `Transaction.commit` methods are called, the handle may not be accessed again, regardless of the success or failure of the method.

To obtain a transaction with default attributes:

>          Transaction txn = myEnvironment.beginTransaction(null, null);

To customize the attributes of a transaction:

>          TransactionConfig config = new TransactionConfig();
>          config.setReadUncommitted(true);
>          Transaction txn = myEnvironment.beginTransaction(null, config);

Method Summary
`void` | `abort()` Cause an abnormal termination of the transaction.
`void` | `commit()` End the transaction.
`void` | `commitNoSync()` End the transaction, not committing synchronously.
`void` | `commitSync()` End the transaction, committing synchronously.
`void` | `commitWriteNoSync()` End the transaction, committing synchronously.
`long` | `getId()` Return the transaction's unique ID.
`String` | `getName()` Get the user visible name for the transaction.
`void` | `setLockTimeout(long timeOut)` Configure the lock request timeout value for the transaction.
`void` | `setName(String name)` Set the user visible name for the transaction.
`void` | `setTxnTimeout(long timeOut)` Configure the timeout value for the transaction lifetime.
`String` | `toString()`

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

Method Detail

### abort

    public void abort()
               throws DatabaseException

  Cause an abnormal termination of the transaction.

  The log is played backward, and any necessary undo operations are done. Before Transaction.abort returns, any locks held by the transaction will have been released.

  In the case of nested transactions, aborting a parent transaction causes all children (unresolved or not) of the parent transaction to be aborted.

  All cursors opened within the transaction must be closed before the transaction is aborted.

  After Transaction.abort has been called, regardless of its return, the `Transaction` handle may not be accessed again.

  Throws:
    `DatabaseException` - if a failure occurs.

### getId

    public long getId()
               throws DatabaseException

  Return the transaction's unique ID.

  Returns:
    The transaction's unique ID.
  Throws:
    `DatabaseException` - if a failure occurs.

### commit

    public void commit()
                throws DatabaseException

  End the transaction. If the environment is configured for synchronous commit, the transaction will be committed synchronously to stable storage before the call returns. This means the transaction will exhibit all of the ACID (atomicity, consistency, isolation, and durability) properties.

  If the environment is not configured for synchronous commit, the commit will not necessarily have been committed to stable storage before the call returns. This means the transaction will exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but it is possible this transaction may be undone during recovery.

  All cursors opened within the transaction must be closed before the transaction is committed.

  After this method returns the `Transaction` handle may not be accessed again, regardless of the method's success or failure. If the method encounters an error, the transaction and all child transactions of the transaction will have been aborted when the call returns.

  Throws:
    `DatabaseException` - if a failure occurs.

### commitSync

    public void commitSync()
                    throws DatabaseException

  End the transaction, committing synchronously. This means the transaction will exhibit all of the ACID (atomicity, consistency, isolation, and durability) properties.

  This behavior is the default for database environments unless otherwise configured using the `EnvironmentConfig.setTxnNoSync` method. This behavior may also be set for a single transaction using the `Environment.beginTransaction` method. Any value specified to this method overrides both of those settings.

  All cursors opened within the transaction must be closed before the transaction is committed.

  After this method returns the `Transaction` handle may not be accessed again, regardless of the method's success or failure. If the method encounters an error, the transaction and all child transactions of the transaction will have been aborted when the call returns.

  Throws:
    `DatabaseException` - if a failure occurs.

### commitNoSync

    public void commitNoSync()
                      throws DatabaseException

  End the transaction, not committing synchronously. This means the transaction will exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but it is possible this transaction may be undone during recovery.

  This behavior may be set for a database environment using the `EnvironmentConfig.setTxnNoSync` method or for a single transaction using the `Environment.beginTransaction` method. Any value specified to this method overrides both of those settings.

  All cursors opened within the transaction must be closed before the transaction is committed.

  After this method returns the `Transaction` handle may not be accessed again, regardless of the method's success or failure. If the method encounters an error, the transaction and all child transactions of the transaction will have been aborted when the call returns.

  Throws:
    `DatabaseException` - if a failure occurs.

### commitWriteNoSync

    public void commitWriteNoSync()
                           throws DatabaseException

  End the transaction, committing synchronously. This means the transaction will exhibit all of the ACID (atomicity, consistency, isolation, and durability) properties.

  This behavior is the default for database environments unless otherwise configured using the `EnvironmentConfig.setTxnNoSync` method. This behavior may also be set for a single transaction using the `Environment.beginTransaction` method. Any value specified to this method overrides both of those settings.

  All cursors opened within the transaction must be closed before the transaction is committed.

  After this method returns the `Transaction` handle may not be accessed again, regardless of the method's success or failure. If the method encounters an error, the transaction and all child transactions of the transaction will have been aborted when the call returns.

  Throws:
    `DatabaseException` - if a failure occurs.

### setTxnTimeout

    public void setTxnTimeout(long timeOut)
                       throws IllegalArgumentException,
                              DatabaseException

  Configure the timeout value for the transaction lifetime.

  If the transaction runs longer than this time, the transaction may throw `DatabaseException`.

  Timeouts are checked whenever a thread of control blocks on a lock or when deadlock detection is performed. For this reason, the accuracy of the timeout depends on how often deadlock detection is performed.

  Parameters:
    `timeOut` - The timeout value for the transaction lifetime, in microseconds. A value of 0 disables timeouts for the transaction.
  Throws:
    `IllegalArgumentException` - If the value of timeout is negative
    `DatabaseException` - if a failure occurs.

### setLockTimeout

    public void setLockTimeout(long timeOut)
                        throws IllegalArgumentException,
                               DatabaseException

  Configure the lock request timeout value for the transaction.

  If a lock request cannot be granted in this time, the transaction may throw `DatabaseException`.

  Timeouts are checked whenever a thread of control blocks on a lock or when deadlock detection is performed. For this reason, the accuracy of the timeout depends on how often deadlock detection is performed.

  Parameters:
    `timeOut` - The lock request timeout value for the transaction, in microseconds. A value of 0 disables timeouts for the transaction.

    This method may be called at any time during the life of the application.

  Throws:
    `IllegalArgumentException` - If the value of timeout is negative.
    `DatabaseException` - if a failure occurs.

### setName

    public void setName(String name)

  Set the user visible name for the transaction.

  Parameters:
    `name` - The user visible name for the transaction.

### getName

    public String getName()

  Get the user visible name for the transaction.

  Returns:
    The user visible name for the transaction.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

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

Copyright (c) 2004,2008 Oracle. All rights reserved.