@Component(value="cuba_TransactionalAction") @Scope(value="prototype") public class TransactionalActionBean extends java.lang.Object implements TransactionalAction
Modifier and Type | Field and Description |
---|---|
protected java.util.function.Consumer<CommitContext> |
afterCommitAction |
protected CommitContext |
commitContext |
protected DataManager |
dataManager |
protected java.util.function.Supplier<CommitContext> |
getCommitContextAction |
protected boolean |
joinTransaction |
protected java.util.function.BiConsumer<CommitContext,java.lang.Throwable> |
onFailAction |
protected java.util.function.Consumer<EntitySet> |
onSuccessAction |
NAME
Constructor and Description |
---|
TransactionalActionBean() |
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). |
@Inject protected DataManager dataManager
protected CommitContext commitContext
protected java.util.function.Supplier<CommitContext> getCommitContextAction
protected java.util.function.Consumer<EntitySet> onSuccessAction
protected java.util.function.BiConsumer<CommitContext,java.lang.Throwable> onFailAction
protected java.util.function.Consumer<CommitContext> afterCommitAction
protected boolean joinTransaction
public TransactionalAction onSuccess(java.util.function.Consumer<EntitySet> consumer)
TransactionalAction
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.
onSuccess
in interface TransactionalAction
consumer
- implementation of Consumer
interfacepublic TransactionalAction onFail(java.util.function.BiConsumer<CommitContext,java.lang.Throwable> consumer)
TransactionalAction
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.
onFail
in interface TransactionalAction
consumer
- implementation of BiConsumer
interface.
The first parameter - CommitContext
that was used for unsuccessful commit.
The second parameter - Throwable
that was thrown during the commitpublic TransactionalAction afterCompletion(java.util.function.Consumer<CommitContext> consumer)
TransactionalAction
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.
afterCompletion
in interface TransactionalAction
consumer
- implementation of Consumer
interfacepublic TransactionalAction withCommitContext(java.util.function.Supplier<CommitContext> supplier)
TransactionalAction
CommitContext
with all required changes (created, updated, deleted entities).
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
withCommitContext
in interface TransactionalAction
supplier
- implementation of Supplier
interfacepublic TransactionalAction withCommitContext(CommitContext commitContext)
TransactionalAction
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.
withCommitContext
in interface TransactionalAction
commitContext
- contains all required changes (created, updated and deleted entities)public EntitySet perform()
TransactionalAction
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
perform
in interface TransactionalAction
EntitySet
with all committed entities. This EntitySet might be modified by onSuccess
actionpublic CommitContext getCommitContext()
getCommitContext
in interface TransactionalAction
withCommitContext(CommitContext commitContext)
methodpublic boolean isJoinTransaction()
isJoinTransaction
in interface TransactionalAction
public TransactionalAction setJoinTransaction(boolean joinTransaction)
TransactionalAction
joinTransaction
parameter.
Method returns the same instance of TransactionalAction
so
it can be used for method chaining.
setJoinTransaction
in interface TransactionalAction
joinTransaction
- defines should CommitContext
be joined to existing transaction or not.
Default value = false