Package com.sleepycat.collections
Class CurrentTransaction
java.lang.Object
com.sleepycat.collections.CurrentTransaction
Provides access to the current transaction for the current thread within the
context of a Berkeley DB environment. This class provides explicit
transaction control beyond that provided by the
TransactionRunner
class. However, both methods of transaction control manage per-thread
transactions.-
Method Summary
Modifier and TypeMethodDescriptionfinal TransactionAborts the transaction that is active for the current thread for this environment and makes the parent transaction (if any) the current transaction.final TransactionbeginTransaction(TransactionConfig config) Begins a new transaction for this environment and associates it with the current thread.final TransactionCommits the transaction that is active for the current thread for this environment and makes the parent transaction (if any) the current transaction.final EnvironmentReturns the underlying Berkeley DB environment.static CurrentTransactiongetInstance(Environment env) Gets the CurrentTransaction accessor for a specified Berkeley DB environment.final TransactionReturns the transaction associated with the current thread for this environment, or null if no transaction is active.
-
Method Details
-
getInstance
Gets the CurrentTransaction accessor for a specified Berkeley DB environment. This method always returns the same reference when called more than once with the same environment parameter.- Parameters:
env- is an open Berkeley DB environment.- Returns:
- the CurrentTransaction accessor for the given environment, or null if the environment is not transactional.
-
getEnvironment
Returns the underlying Berkeley DB environment. -
getTransaction
Returns the transaction associated with the current thread for this environment, or null if no transaction is active. -
beginTransaction
Begins a new transaction for this environment and associates it with the current thread. If a transaction is already active for this environment and thread, a nested transaction will be created.- Parameters:
config- the transaction configuration used for callingEnvironment.beginTransaction(com.sleepycat.db.Transaction, com.sleepycat.db.TransactionConfig), or null to use the default configuration.- Returns:
- the new transaction.
- Throws:
DatabaseException- if the transaction cannot be started, in which case any existing transaction is not affected.IllegalStateException- if a transaction is already active and nested transactions are not supported by the environment.
-
commitTransaction
Commits the transaction that is active for the current thread for this environment and makes the parent transaction (if any) the current transaction.- Returns:
- the parent transaction or null if the committed transaction was not nested.
- Throws:
DatabaseException- if an error occurs committing the transaction. The transaction will still be closed and the parent transaction will become the current transaction.IllegalStateException- if no transaction is active for the current thread for this environment.
-
abortTransaction
Aborts the transaction that is active for the current thread for this environment and makes the parent transaction (if any) the current transaction.- Returns:
- the parent transaction or null if the aborted transaction was not nested.
- Throws:
DatabaseException- if an error occurs aborting the transaction. The transaction will still be closed and the parent transaction will become the current transaction.IllegalStateException- if no transaction is active for the current thread for this environment.
-