@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)
TransactionalActionEntities 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 TransactionalActionconsumer - implementation of Consumer interfacepublic TransactionalAction onFail(java.util.function.BiConsumer<CommitContext,java.lang.Throwable> consumer)
TransactionalActionIf 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 TransactionalActionconsumer - 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)
TransactionalActionAll 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 TransactionalActionconsumer - implementation of Consumer interfacepublic TransactionalAction withCommitContext(java.util.function.Supplier<CommitContext> supplier)
TransactionalActionCommitContext 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 TransactionalActionsupplier - implementation of Supplier interfacepublic TransactionalAction withCommitContext(CommitContext commitContext)
TransactionalActionCommitContext 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 TransactionalActioncommitContext - contains all required changes (created, updated and deleted entities)public EntitySet perform()
TransactionalActionActions are invoked in the following order:
1) withCommitContext action to retrieve the commitContext;
2) beforeCommit action;
3.1) if the commit was successful then onSuccess action;
3.2) if the commit was unsuccessful then onFail 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 TransactionalActionEntitySet with all committed entities. This EntitySet might be modified by onSuccess actionpublic CommitContext getCommitContext()
getCommitContext in interface TransactionalActionwithCommitContext(CommitContext commitContext) methodpublic boolean isJoinTransaction()
isJoinTransaction in interface TransactionalActionpublic TransactionalAction setJoinTransaction(boolean joinTransaction)
TransactionalActionjoinTransaction parameter.
Method returns the same instance of TransactionalAction so
it can be used for method chaining.
setJoinTransaction in interface TransactionalActionjoinTransaction - defines should CommitContext be joined to existing transaction or not.
Default value = false