Class Sabi

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

public final class Sabi extends Object
Sabi is the class that provides the static methods related to the global functionalities of sabi framework.

This class declares uses method to register a DataSrc object used globally with its name. And this class also declares setup methods, which is the static method to setup all global registered DataSrc objects.

The usages of these static methods is as follows:

   public class Application {
       static {
           Sabi.uses("foo", new FooDataSrc());
           Sabi.uses("bar", new BarDataSrc());
       }
       public static void main(String ...args) {
           int exitCode = 0;
           try (var ac = Sabi.setup()) {
               ...
           } catch (Exception e) {
               exitCode = 1;
           }
           System.exit(exitCode);
       }
   }
  • Method Details

    • uses

      public static void uses(String name, DataSrc ds)
      Registers a DataSrc object with a unique name for global use within the Sabi framework. This method should typically be called in a static initializer block of your application's main class.
      Parameters:
      name - The unique name to associate with the DataSrc.
      ds - The DataSrc instance to be registered.
    • setup

      public static AutoCloseable setup() throws com.github.sttk.errs.Exc
      Sets up all globally registered DataSrc objects. This involves calling the setup method on each registered data source. This method should be called once at the application startup.

      The returned AutoCloseable object can be used in a try-with-resources statement to automatically invoke the close operations upon exiting the try block.

      Returns:
      An AutoCloseable object that, when closed, will trigger the global close operation.
      Throws:
      com.github.sttk.errs.Exc - if an error occurs during the setup of any DataSrc.
    • run

      public static <D> void run(Logic<D> logic, DataHub hub) throws com.github.sttk.errs.Exc
      Executes the provided application Logic without transactional boundaries. The DataHub instance in the parameters is passed as the data access object D to the Logic's run method.
      Type Parameters:
      D - The type of the data access object, which typically is DataHub or an interface implemented by DataHub that Logic expects.
      Parameters:
      logic - The application logic to execute.
      hub - An instance of a DataHub subclass that inherits the data interface for logic arguments.
      Throws:
      com.github.sttk.errs.Exc - if an Exc or RuntimeException occurs during logic execution or if the DataHub cannot be cast to the expected data access type.
    • txn

      public static <D> void txn(Logic<D> logic, DataHub hub) throws com.github.sttk.errs.Exc
      Executes the provided application Logic within a transactional context. The DataHub instance in the parameter is passed as the data access object D to the Logic's run method. If the logic completes successfully, a commit operation is attempted. If any Exc, RuntimeException, or Error occurs, a rollback operation is performed.
      Type Parameters:
      D - The type of the data access object, which typically is DataHub or an interface implemented by DataHub that Logic expects.
      Parameters:
      logic - The application logic to execute transactionally.
      hub - An instance of a DataHub subclass that inherits the data interface for logic arguments.
      Throws:
      com.github.sttk.errs.Exc - if an Exc, RuntimeException, or Error occurs during logic execution, pre-commit, or commit. The original exception is re-thrown after rollback.