public interface TransactionalAction
CommitContext
and set of actions to be performed before/after commit.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME |
Modifier and Type | Method and Description |
---|---|
TransactionalAction |
afterCompletion(java.util.function.Consumer<CommitContext> consumer)
Specifies the action to be performed after the commit (regardless of whether it is successful or not).
|
CommitContext |
getCommitContext() |
boolean |
isJoinTransaction() |
TransactionalAction |
onFail(java.util.function.BiConsumer<CommitContext,java.lang.Throwable> consumer)
Specifies the action to be performed right after the unsuccessful commit.
|
TransactionalAction |
onSuccess(java.util.function.Consumer<EntitySet> consumer)
Specifies the action to be performed right after the successful commit.
|
EntitySet |
perform()
Terminal operation.
|
TransactionalAction |
setJoinTransaction(boolean joinTransaction)
Specifies the
joinTransaction parameter. |
TransactionalAction |
withCommitContext(CommitContext commitContext)
Specifies the
CommitContext with all required changes (created, updated, deleted entities). |
TransactionalAction |
withCommitContext(java.util.function.Supplier<CommitContext> supplier)
Specifies the action to retrieve the
CommitContext with all required changes (created, updated, deleted entities). |
static final java.lang.String NAME
@CheckReturnValue TransactionalAction onSuccess(java.util.function.Consumer<EntitySet> consumer)
Entities in the EntitySet can be modified but these modifications don't change entities in a database.
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
consumer
- implementation of Consumer
interface@CheckReturnValue TransactionalAction onFail(java.util.function.BiConsumer<CommitContext,java.lang.Throwable> consumer)
If this action is specified (not null) and an exception occurs during commit
then this exception won't be re-thrown during perform()
execution.
In this case null
value will be returned by perform()
method
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
consumer
- implementation of BiConsumer
interface.
The first parameter - CommitContext
that was used for unsuccessful commit.
The second parameter - Throwable
that was thrown during the commit@CheckReturnValue TransactionalAction afterCompletion(java.util.function.Consumer<CommitContext> consumer)
All changes of the CommitContext
won't be saved in a database.
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
consumer
- implementation of Consumer
interface@CheckReturnValue TransactionalAction withCommitContext(java.util.function.Supplier<CommitContext> supplier)
CommitContext
with all required changes (created, updated, deleted entities).
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
supplier
- implementation of Supplier
interface@CheckReturnValue TransactionalAction withCommitContext(CommitContext commitContext)
CommitContext
with all required changes (created, updated, deleted entities).
If this method is used with commitContext != null
then action
from withCommitContext(Supplier<CommitContext> supplier)
will be ignored
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
commitContext
- contains all required changes (created, updated and deleted entities)EntitySet perform()
Actions are invoked in the following order: 1)withCommitContext
action to retrieve the commitContext; 2)beforeCommit
action; 3.1) if the commit was successful thenonSuccess
action; 3.2) if the commit was unsuccessful thenonFail
action; 4)afterCompletion
action.
If onFail
action is specified (not null) and an exception occurs during commit
then this exception won't be re-thrown by perform()
method.
In this case null
value will be returned as a result
EntitySet
with all committed entities. This EntitySet might be modified by onSuccess
action@CheckReturnValue TransactionalAction setJoinTransaction(boolean joinTransaction)
joinTransaction
parameter.
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
joinTransaction
- defines should CommitContext
be joined to existing transaction or not.
Default value = falseCommitContext getCommitContext()
withCommitContext(CommitContext commitContext)
methodboolean isJoinTransaction()