Class LogicTxn

java.lang.Object
com.github.sttk.sabi.LogicTxn

public final class LogicTxn extends Object
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 Details

    • run

      public <D> LogicTxn run(Logic<D> logic)
      Executes the specified Logic if no prior Err has occurred and execution has not been blocked or terminated abnormally.

      If logic throws an Err, it is recorded and the transaction will be rolled back when endTxn() is called. If an unhandled RuntimeException or Error is thrown, uncommitted connections are rolled back, the DataHub is 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 LogicTxn instance for method chaining
    • runForce

      public <D> LogicTxn runForce(Logic<D> logic)
      Executes the specified Logic even if a prior run(Logic) or runForce(Logic) call recorded an Err, provided execution has not been blocked by runOrBlock(Logic), setup did not fail, and the DataHub is 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 LogicTxn instance for method chaining
    • runOrBlock

      public <D> LogicTxn runOrBlock(Logic<D> logic)
      Executes the specified Logic if no prior Err has occurred, and blocks all subsequent run(Logic), runForce(Logic), and runOrBlock(Logic) calls in this transaction if it throws an Err.
      Type Parameters:
      D - the type of data access interface expected by the logic
      Parameters:
      logic - the logic unit to execute
      Returns:
      this LogicTxn instance for method chaining
    • endTxn

      public void endTxn() throws com.github.sttk.errs.Err
      Completes 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 the DataHub is in an abnormal state, local data source setup failed, one or more logic executions failed, or committing the transaction failed