Class DataHub

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

public class DataHub extends Object implements 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.

  • Constructor Details

    • DataHub

      public DataHub()
      Constructs a new DataHub instance.
  • Method Details

    • uses

      public void uses(String name, DataSrc ds)
      Registers a local DataSrc with the specified name for use within this DataHub instance. This allows specific data sources to be managed independently from globally registered ones.
      Parameters:
      name - The unique name for the DataSrc.
      ds - The DataSrc instance to register.
    • disuses

      public void disuses(String name)
      Unregisters a local DataSrc with the given name from this DataHub instance.
      Parameters:
      name - The name of the DataSrc to unregister.
    • getDataConn

      public <C extends DataConn> C getDataConn(String name, Class<C> cls) throws com.github.sttk.errs.Exc
      Retrieves a DataConn instance from the managed data sources. This method is part of the DataAcc interface implementation.
      Specified by:
      getDataConn in interface DataAcc
      Type Parameters:
      C - The type of the DataConn to retrieve, which must extend DataConn.
      Parameters:
      name - The name of the data source from which to get the connection.
      cls - The Class 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 all DataConn instances managed by this DataHub, releasing their resources. This method is part of the AutoCloseable interface and should be called to ensure proper resource cleanup, ideally in a try-with-resources statement.
      Specified by:
      close in interface AutoCloseable