Class Sabi
java.lang.Object
com.github.sttk.sabi.Sabi
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);
       }
   }- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an error reason that occurred when failing to cast theDataHubinstance itself to the expected data access interface type for aLogic.
- 
Method SummaryModifier and TypeMethodDescriptionstatic <D> voidExecutes the provided applicationLogicwithout transactional boundaries.static AutoCloseablesetup()Sets up all globally registeredDataSrcobjects.static <D> voidExecutes the provided applicationLogicwithin a transactional context.static voidRegisters aDataSrcobject with a unique name for global use within the Sabi framework.
- 
Method Details- 
usesRegisters aDataSrcobject 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.
- 
setupSets up all globally registeredDataSrcobjects. This involves calling thesetupmethod on each registered data source. This method should be called once at the application startup.The returned AutoCloseableobject can be used in a try-with-resources statement to automatically invoke the close operations upon exiting the try block.- Returns:
- An AutoCloseableobject 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.
 
- 
runExecutes the provided applicationLogicwithout transactional boundaries. TheDataHubinstance in the parameters is passed as the data access objectDto theLogic'srunmethod.- Type Parameters:
- D- The type of the data access object, which typically is- DataHubor an interface implemented by- DataHubthat- Logicexpects.
- 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- Excor- RuntimeExceptionoccurs during logic execution or if the- DataHubcannot be cast to the expected data access type.
 
- 
txnExecutes the provided applicationLogicwithin a transactional context. TheDataHubinstance in the parameter is passed as the data access objectDto theLogic'srunmethod. If the logic completes successfully, a commit operation is attempted. If anyExc,RuntimeException, orErroroccurs, a rollback operation is performed.- Type Parameters:
- D- The type of the data access object, which typically is- DataHubor an interface implemented by- DataHubthat- Logicexpects.
- 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- Erroroccurs during logic execution, pre-commit, or commit. The original exception is re-thrown after rollback.
 
 
-