java.lang.Object
org.litebridgedb.orm.api.tx.TransactionContextTerminal
- Direct Known Subclasses:
TransactionContext
Represents the terminal stage of a transactional context, providing core methods for configuring
and managing transactions. This class defines basic transactional operations such as setting the
transaction as read-only, specifying isolation levels, and handling the lifecycle of transactions.
This is a sealed class, permitting only specific subclasses to extend it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Isolationprotected booleanprotected final TransactionManager -
Method Summary
-
Field Details
-
transactionManager
-
readOnly
protected boolean readOnly -
isolation
-
-
Method Details
-
begin
Begins a new transaction for the current thread.This method should be called before performing operations that need to be executed within a transactional context. It ensures that subsequent database interactions are part of the same transaction until it is either committed or rolled back.
This method may be called multiple times (nested).
- Returns:
- a
Transactionauto-closeable, suitable for use in a try-with-resources statement. - Throws:
TransactionException- if an error occurs during starting the transaction
-
execute
Executes a givenRunnablewithin the context of a transaction.This method begins a new transaction, executes the provided
Runnable, and commits the transaction if no exception occurs. In case of an exception, the transaction is rolled back, and aTransactionExceptionis thrown.- Parameters:
runnable- theRunnablecontaining the operations to be executed within the transactional context- Throws:
TransactionException- if an error occurs during execution or if the transaction is rolled back due to an exception
-