Class DataHub

java.lang.Object
com.github.sttk.sabi.DataHub
All Implemented Interfaces:
DataAcc, AutoCloseable

public class DataHub extends Object implements 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
    Constructor
    Description
    Constructs a new DataHub inheriting ready global data sources.
    DataHub(String... names)
    Constructs a new DataHub with a predefined order for managing named data connections.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes all managed data connections and local data sources held by this DataHub.
    final <C extends DataConn>
    C
    getDataConn(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> void
    run(Logic<D> logic)
    Executes the specified Logic using this DataHub as the data access instance.
    final LogicRun
    Starts a nested LogicRun chain using this DataHub.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataHub

      public DataHub()
      Constructs a new DataHub inheriting ready global data sources.
    • DataHub

      public DataHub(String... names)
      Constructs a new DataHub with a predefined order for managing named data connections.

      When data connections are committed, those whose names appear in names are processed in that order, followed by any other connections in the order they were obtained. When data connections are closed, the order is reversed. If names contains 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 be null
      Throws:
      NullPointerException - if names or any of its elements is null
  • Method Details

    • close

      public void close()
      Closes all managed data connections and local data sources held by this DataHub.
      Specified by:
      close in interface AutoCloseable
    • 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:
      getDataConn in interface DataAcc
      Type Parameters:
      C - the expected type of DataConn
      Parameters:
      name - the registered logical name of the data source
      cls - the Class representing the target connection type C
      Returns:
      the data connection instance associated with the specified name
      Throws:
      com.github.sttk.errs.Err - if no data source is available for name, if creating the connection fails or returns null, or if the connection cannot be cast to cls
    • run

      public final <D> void run(Logic<D> logic) throws com.github.sttk.errs.Err
      Executes the specified Logic using this DataHub as the data access instance.
      Specified by:
      run in interface DataAcc
      Type Parameters:
      D - the type of data access interface expected by the logic
      Parameters:
      logic - the logic unit to execute
      Throws:
      com.github.sttk.errs.Err - if an error occurs during logic execution
    • start

      public final LogicRun start()
      Starts a nested LogicRun chain using this DataHub.
      Specified by:
      start in interface DataAcc
      Returns:
      a new nested LogicRun instance