Class Sabi

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

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

This class declares uses method to register a DaxSrc object used globally with its name. And this class also declares setup, close, and startApp methods. setup is the static method to setup all global registered DaxSrc objects, and close is the static method to free each resource of global DaxSrc objects. startApp is the method that executes setup and return AutoCloseable object which executes the close method in its AutoCloseable.close() method.

The usages of these static methods is as follows:

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

    • uses

      public static void uses(String name, DaxSrc ds)
      Registers a global DaxSrc object with its name to enable to use DaxConn created by the argument DaxSrc in all transactions.

      If a DaxSrc is tried to register with a name already registered, it is ignored and a DaxSrc registered with the same name first is used. And this method ignore adding DaxSrc(s) after setup or beginning of DaxBase.txn(com.github.sttk.sabi.Logic<D>...).

      Parameters:
      name - The name for the argument DaxSrc object.
      ds - A DaxSrc object.
    • setup

      public static void setup() throws Err
      Makes the globally registered DaxSrc object usable.

      This method forbids adding more global DaxSrc, and called each setup method of all registered DaxSrc objects. If one of global DaxSrc objects fails to execute synchronous setup, this function stops other setting up and returns an Err containing the error reason of that failure.

      If one of global DaxSrc objects fails to execute asynchronous setup, this function continue to other setting up and returns an Err containing the error reason of that failure and other errors if any.

      Throws:
      Err - If one of global DaxSrc objects.
    • close

      public static void close()
      Closes and frees each resource of registered global DaxSrc objects.
    • startApp

      public static AutoCloseable startApp() throws Err
      Executes setup method, and returns an AutoCloseable object of which close method executes close method of this class in it.
      Returns:
      An AutoCloseable object.
      Throws:
      Err - If one of global DaxSrc objects.