Interface DataSourceHandler

  • All Known Implementing Classes:
    DefaultDataSourceHandler

    public interface DataSourceHandler
    Represents the interaction logic for a data source.

    Different implementations may change the logic of methods open() and close().

    NOTE: implementations should do a little exception (although it may not be necessary) handling for methods open() and close(), when the adopted strategy is Strategy.CONNECTION_POOL.

    This is because the DataTemplate class cannot handle these methods when they are dealing with a connection pool.

    This is not needed when the adopted strategy is Strategy.SIMPLE_CONNECTION: those methods will be managed by aSQL DataTemplate and possible exceptions will be passed to a CompletableFuture for further analysis by the user.

    See Also:
    DataSourceCredentials, Strategy, DataTemplate
    • Method Detail

      • getConnection

        @NotNull
        Connection getConnection()
                          throws SQLException
        Gets the existing connection to a data source.
        Returns:
        The connection to a data source
        Throws:
        SQLException - if something gone wrong while attempting to get the connection (no need to catch)
      • open

        void open()
           throws SQLException
        Opens the connection to a data source.
        It can be used for opening connection pools.
        Throws:
        SQLException - if something gone wrong while attempting to perform the implemented open operation. No need to catch with Strategy.SIMPLE_CONNECTION
      • close

        void close()
            throws SQLException
        Closes the connection to a data source.
        It can be used for closing connection pools.
        Throws:
        SQLException - if something gone wrong while attempting to perform the implemented close operation. No need to catch with Strategy.SIMPLE_CONNECTION
      • getStrategy

        @NotNull
        Strategy getStrategy()
        Gets the implementation's adopted strategy.
        Returns:
        the adopted strategy for connection management
        See Also:
        Strategy