Class DataHub
java.lang.Object
com.github.sttk.sabi.DataHub
- All Implemented Interfaces:
DataAcc, AutoCloseable
Manages data sources and data connections for executing business logic.
A DataHub inherits global DataSrc instances registered via Globals.uses(String, DataSrc) and manages session-local DataSrc and DataConn
instances. Subclasses typically implement application-specific data access interfaces alongside
DataAcc so that Logic instances can access required operations without depending
on concrete data sources.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes all managed data connections and local data sources held by thisDataHub.final <C extends DataConn>
CgetDataConn(String name, Class<C> cls) Retrieves a data connection associated with the specified data source name and casts it to the requested connection class type.final <D> voidExecutes the specifiedLogicusing thisDataHubas the data access instance.final LogicRunstart()Starts a nestedLogicRunchain using thisDataHub.
-
Constructor Details
-
DataHub
public DataHub()Constructs a newDataHubinheriting ready global data sources. -
DataHub
Constructs a newDataHubwith a predefined order for managing named data connections.When data connections are committed, those whose names appear in
namesare processed in that order, followed by any other connections in the order they were obtained. When data connections are closed, the order is reversed. Ifnamescontains duplicates, only the first occurrence of each name is used and the rest are ignored.- Parameters:
names- the ordered logical names of data connections; neither the array nor its elements may benull- Throws:
NullPointerException- ifnamesor any of its elements isnull
-
-
Method Details
-
close
public void close()Closes all managed data connections and local data sources held by thisDataHub.- Specified by:
closein interfaceAutoCloseable
-
getDataConn
public final <C extends DataConn> C getDataConn(String name, Class<C> cls) throws com.github.sttk.errs.Err Retrieves a data connection associated with the specified data source name and casts it to the requested connection class type.- Specified by:
getDataConnin interfaceDataAcc- Type Parameters:
C- the expected type ofDataConn- Parameters:
name- the registered logical name of the data sourcecls- theClassrepresenting the target connection typeC- Returns:
- the data connection instance associated with the specified name
- Throws:
com.github.sttk.errs.Err- if no data source is available forname, if creating the connection fails or returnsnull, or if the connection cannot be cast tocls
-
run
Executes the specifiedLogicusing thisDataHubas the data access instance. -
start
-