Interface OfBizTransactionManager
- All Known Implementing Classes:
DefaultOfBizTransactionManager
public interface OfBizTransactionManager
Provides a simpler way of executing code within an OfBiz transaction.
To use:
- Use
withTransaction(Consumer)orwithTransaction(Function)depending on whether a return value is needed - To roll back the transaction, use
OfBizTransaction.rollback()inside the function passed in - The transaction is committed if the passed in function completes successfully
- The transaction is rolled back if an error occurs
Simple usage example:
transactionManager.withTransaction(t ->
{
//... do database code inside transaction
});
You can also return a value and rollback in case of business logic errors:
int numUpdates = OfBizTransaction.withTransaction(t ->
{
//... database code
});
Or if business logic fails, the transaction can be rolled back:
transactionManager.withTransaction(t ->
{
//.. do some database code
if (!businessLogicIsOk())
t.rollback();
});
- Since:
- v7.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidwithTransaction(Consumer<? super OfBizTransaction> transactionUsingFunction) <R> RwithTransaction(Function<? super OfBizTransaction, R> transactionUsingFunction)
-
Method Details
-
withTransaction
-
withTransaction
-