Class DataHub
java.lang.Object
com.github.sttk.sabi.DataHub
- All Implemented Interfaces:
DataAcc
,AutoCloseable
DataHub
is a central component in the Sabi framework that manages DataSrc
and
DataConn
instances, facilitating data access and transaction management. It implements
both DataAcc
for data access operations and AutoCloseable
for resource
management.
This class allows for the registration and unregistration of local DataSrc
objects,
and provides methods to execute application logic with or without transactional boundaries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Represents an error reason where the createdDataConn
instance was null.static final record
Represents an error reason that occurred when failing to cast aDataConn
to the requested type.static final record
Represents an error reason that occurred when failing to commit one or moreDataConn
instances.static final record
Represents an error reason that occurred when failing to create aDataConn
instance.static final record
Represents an error reason that occurred when failing to pre-commit one or moreDataConn
instances.static final record
Represents an error reason that occurred when failing to set up globalDataSrc
instances.static final record
Represents an error reason that occurred when failing to set up localDataSrc
instances.static final record
static final record
Represents an unexpectedRuntimeException
that occurred during pre-commit or commit operations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes allDataConn
instances managed by thisDataHub
, releasing their resources.void
Unregisters a localDataSrc
with the given name from thisDataHub
instance.<C extends DataConn>
CgetDataConn
(String name, Class<C> cls) Retrieves aDataConn
instance from the managed data sources.void
Registers a localDataSrc
with the specified name for use within thisDataHub
instance.
-
Constructor Details
-
DataHub
public DataHub()Constructs a newDataHub
instance.
-
-
Method Details
-
uses
Registers a localDataSrc
with the specified name for use within thisDataHub
instance. This allows specific data sources to be managed independently from globally registered ones. -
disuses
-
getDataConn
public <C extends DataConn> C getDataConn(String name, Class<C> cls) throws com.github.sttk.errs.Exc Retrieves aDataConn
instance from the managed data sources. This method is part of theDataAcc
interface implementation.- Specified by:
getDataConn
in interfaceDataAcc
- Type Parameters:
C
- The type of theDataConn
to retrieve, which must extendDataConn
.- Parameters:
name
- The name of the data source from which to get the connection.cls
- TheClass
object representing the desired type of the data connection.- Returns:
- A
DataConn
instance of the specified type. - Throws:
com.github.sttk.errs.Exc
- if no data source is found, if the connection cannot be created, if the created connection is null, or if the connection cannot be cast to the specified class.
-
close
public void close()Closes allDataConn
instances managed by thisDataHub
, releasing their resources. This method is part of theAutoCloseable
interface and should be called to ensure proper resource cleanup, ideally in a try-with-resources statement.- Specified by:
close
in interfaceAutoCloseable
-