Class LogicTxn
java.lang.Object
com.github.sttk.sabi.LogicTxn
Executes a sequence of
Logic units within a single transaction scope.
A LogicTxn is started via LogicRunner.beginTxn() and completed by calling
endTxn(). If all executed logic units succeed without Err, connections are
committed; otherwise, uncommitted connections are rolled back and failure reports are dispatched.
-
Method Summary
Modifier and TypeMethodDescriptionvoidendTxn()Completes this transaction by committing all connections if no errors occurred, or rolling back uncommitted connections and closing resources otherwise.<D> LogicTxnExecutes the specifiedLogicif no priorErrhas occurred and execution has not been blocked or terminated abnormally.<D> LogicTxnExecutes the specifiedLogiceven if a priorrun(Logic)orrunForce(Logic)call recorded anErr, provided execution has not been blocked byrunOrBlock(Logic), setup did not fail, and theDataHubis not in an abnormal state.<D> LogicTxnrunOrBlock(Logic<D> logic) Executes the specifiedLogicif no priorErrhas occurred, and blocks all subsequentrun(Logic),runForce(Logic), andrunOrBlock(Logic)calls in this transaction if it throws anErr.
-
Method Details
-
run
Executes the specifiedLogicif no priorErrhas occurred and execution has not been blocked or terminated abnormally.If
logicthrows anErr, it is recorded and the transaction will be rolled back whenendTxn()is called. If an unhandledRuntimeExceptionorErroris thrown, uncommitted connections are rolled back, theDataHubis terminated abnormally, and the exception or error is rethrown.- Type Parameters:
D- the type of data access interface expected by the logic- Parameters:
logic- the logic unit to execute- Returns:
- this
LogicTxninstance for method chaining
-
runForce
Executes the specifiedLogiceven if a priorrun(Logic)orrunForce(Logic)call recorded anErr, provided execution has not been blocked byrunOrBlock(Logic), setup did not fail, and theDataHubis not in an abnormal state.- Type Parameters:
D- the type of data access interface expected by the logic- Parameters:
logic- the logic unit to execute- Returns:
- this
LogicTxninstance for method chaining
-
runOrBlock
Executes the specifiedLogicif no priorErrhas occurred, and blocks all subsequentrun(Logic),runForce(Logic), andrunOrBlock(Logic)calls in this transaction if it throws anErr.- Type Parameters:
D- the type of data access interface expected by the logic- Parameters:
logic- the logic unit to execute- Returns:
- this
LogicTxninstance for method chaining
-
endTxn
public void endTxn() throws com.github.sttk.errs.ErrCompletes this transaction by committing all connections if no errors occurred, or rolling back uncommitted connections and closing resources otherwise.- Throws:
com.github.sttk.errs.Err- if theDataHubis in an abnormal state, local data source setup failed, one or more logic executions failed, or committing the transaction failed
-