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 Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Represents an error reason that occurred when failing to cast theDataHub
instance itself to the expected data access interface type for aLogic
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <D> void
Executes the provided applicationLogic
without transactional boundaries.static AutoCloseable
setup()
Sets up all globally registeredDataSrc
objects.static <D> void
Executes the provided applicationLogic
within a transactional context.static void
Registers aDataSrc
object with a unique name for global use within the Sabi framework.
-
Method Details
-
uses
Registers aDataSrc
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. -
setup
Sets up all globally registeredDataSrc
objects. This involves calling thesetup
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 anyDataSrc
.
-
run
Executes the provided applicationLogic
without transactional boundaries. TheDataHub
instance in the parameters is passed as the data access objectD
to theLogic
'srun
method.- Type Parameters:
D
- The type of the data access object, which typically isDataHub
or an interface implemented byDataHub
thatLogic
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 anExc
orRuntimeException
occurs during logic execution or if theDataHub
cannot be cast to the expected data access type.
-
txn
Executes the provided applicationLogic
within a transactional context. TheDataHub
instance in the parameter is passed as the data access objectD
to theLogic
'srun
method. If the logic completes successfully, a commit operation is attempted. If anyExc
,RuntimeException
, orError
occurs, a rollback operation is performed.- Type Parameters:
D
- The type of the data access object, which typically isDataHub
or an interface implemented byDataHub
thatLogic
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 anExc
,RuntimeException
, orError
occurs during logic execution, pre-commit, or commit. The original exception is re-thrown after rollback.
-