Class TransactionHolder
java.lang.Object
io.github.blyznytsiaorg.bibernate.transaction.TransactionHolder
The
TransactionHolder
class is a utility for managing thread-local transactions.
It uses a ThreadLocal
variable to store and retrieve transactions associated with a particular thread.
This class is designed to be used in scenarios where transactional information needs to be accessible
within the scope of a single thread.
The class provides methods for getting, setting, and removing transactions associated with the current thread.
The class uses a ThreadLocal
variable to ensure that each thread has its own isolated transaction reference,
preventing interference between threads.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final ThreadLocal
<Transaction> AThreadLocal
variable for storing transactions associated with a specific thread. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Transaction
Retrieves the transaction associated with the current thread, if any.static void
Removes the transaction association for the current thread.static void
setTransaction
(Transaction transaction) Sets the transaction for the current thread, allowing transactions to be associated with the execution context of a thread.
-
Field Details
-
transactionHolder
AThreadLocal
variable for storing transactions associated with a specific thread.
-
-
Constructor Details
-
TransactionHolder
public TransactionHolder()
-
-
Method Details
-
getTransaction
Retrieves the transaction associated with the current thread, if any.- Returns:
- The transaction associated with the current thread, or
null
if no transaction is associated
-
setTransaction
Sets the transaction for the current thread, allowing transactions to be associated with the execution context of a thread.- Parameters:
transaction
- The transaction to associate with the current thread
-
removeTransaction
public static void removeTransaction()Removes the transaction association for the current thread. This method is typically used to clean up resources associated with a thread-local transaction.
-