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 recordRepresents an error reason where the createdDataConninstance was null.static final recordRepresents an error reason that occurred when failing to cast aDataConnto the requested type.static final recordRepresents an error reason that occurred when failing to commit one or moreDataConninstances.static final recordRepresents an error reason that occurred when failing to create aDataConninstance.static final recordRepresents an error reason that occurred when failing to pre-commit one or moreDataConninstances.static final recordRepresents an error reason that occurred when failing to set up globalDataSrcinstances.static final recordRepresents an error reason that occurred when failing to set up localDataSrcinstances.static final recordstatic final recordRepresents an unexpectedRuntimeExceptionthat occurred during pre-commit or commit operations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes allDataConninstances managed by thisDataHub, releasing their resources.voidUnregisters a localDataSrcwith the given name from thisDataHubinstance.<C extends DataConn>
CgetDataConn(String name, Class<C> cls) Retrieves aDataConninstance from the managed data sources.voidRegisters a localDataSrcwith the specified name for use within thisDataHubinstance.
-
Constructor Details
-
DataHub
public DataHub()Constructs a newDataHubinstance.
-
-
Method Details
-
uses
Registers a localDataSrcwith the specified name for use within thisDataHubinstance. 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 aDataConninstance from the managed data sources. This method is part of theDataAccinterface implementation.- Specified by:
getDataConnin interfaceDataAcc- Type Parameters:
C- The type of theDataConnto retrieve, which must extendDataConn.- Parameters:
name- The name of the data source from which to get the connection.cls- TheClassobject representing the desired type of the data connection.- Returns:
- A
DataConninstance 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 allDataConninstances managed by thisDataHub, releasing their resources. This method is part of theAutoCloseableinterface and should be called to ensure proper resource cleanup, ideally in a try-with-resources statement.- Specified by:
closein interfaceAutoCloseable
-