Class SimpleDataSource<CommonReadResultException extends java.lang.Exception>

  • Type Parameters:
    CommonReadResultException - common type of all used ResultReaders during DataSource.executeQuery(String, ResultReader) -operations to signal business-exceptions during ResultReader.readResult(ResultSet)

    public class SimpleDataSource<CommonReadResultException extends java.lang.Exception>
    extends DataSource<java.lang.IllegalStateException,​CommonReadResultException>

    SimpleDataSource is a simple implementation of an DataSource that can be used directly and that has no logging, no runtime-information and treats all errors as IllegalStateExceptions. While this class is easy to use, it is still strongly recommended to write your own subclass of DataSource in any real project to provide improved treatment.

    Author:
    agz
    • Constructor Detail

      • SimpleDataSource

        public SimpleDataSource​(javax.sql.DataSource dataSource)
        Creates a new SimpleDataSource encapsulating the specified DataSource.

        The specified DataSource must not be null.

        Parameters:
        dataSource - underlying DataSource
    • Method Detail

      • onErrorGettingConnection

        protected java.lang.IllegalStateException onErrorGettingConnection​(java.lang.Throwable t,
                                                                           java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called by all SQL-execution-methods if there is no Connection available from the underlying DataSource. This method must return a suitable Exception.
        Specified by:
        onErrorGettingConnection in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by DataSource.getConnection()
        sql - SQL-statement of the SQL-execution-method
        Returns:
        a suitable Exception
      • onErrorCreatingStatement

        protected java.lang.IllegalStateException onErrorCreatingStatement​(java.lang.Throwable t,
                                                                           java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called by all SQL-execution-methods if there is no Statement available from the underlying Connection. This method must return a suitable Exception.
        Specified by:
        onErrorCreatingStatement in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by Connection.createStatement()
        sql - SQL-statement of the SQL-execution-method
        Returns:
        a suitable Exception
      • onErrorExecutingQuery

        protected java.lang.IllegalStateException onErrorExecutingQuery​(java.lang.Throwable t,
                                                                        java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called by DataSource.executeQuery(String, ResultReader) if there is any error executing the statement. This method must return a suitable Exception.
        Specified by:
        onErrorExecutingQuery in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by Statement.executeQuery(String)
        sql - SQL-statement of the SQL-execution-method
        Returns:
        a suitable Exception
      • onErrorExecutingUpdate

        protected java.lang.IllegalStateException onErrorExecutingUpdate​(java.lang.Throwable t,
                                                                         java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called by DataSource.executeUpdate(String) if there is any error executing the statement. This method must return a suitable Exception.
        Specified by:
        onErrorExecutingUpdate in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by Statement.executeUpdate(String)
        sql - SQL-statement of the SQL-execution-method
        Returns:
        a suitable Exception
      • onErrorReadingResultSet

        protected java.lang.IllegalStateException onErrorReadingResultSet​(java.lang.Throwable t,
                                                                          java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called by DataSource.executeQuery(String, ResultReader) if there is any error reading the ResultSet. This method must return a suitable Exception.
        Specified by:
        onErrorReadingResultSet in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by any of the ResultSet.get...()-methods
        sql - SQL-statement of the SQL-execution-method
        Returns:
        a suitable Exception
      • onErrorGettingMetaData

        protected java.lang.IllegalStateException onErrorGettingMetaData​(java.lang.Throwable t)
        Description copied from class: DataSource
        This event-method is called by DataSource.getSqlDialect() if there is any error getting the DatabaseMetaData. This method must return a suitable Exception.
        Specified by:
        onErrorGettingMetaData in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by Connection.getMetaData()
        Returns:
        a suitable Exception
      • onErrorGettingDatabaseProductName

        protected java.lang.IllegalStateException onErrorGettingDatabaseProductName​(java.lang.Throwable t)
        Description copied from class: DataSource
        This event-method is called by DataSource.getSqlDialect() if there is any error getting the database product name. This method must return a suitable Exception.
        Specified by:
        onErrorGettingDatabaseProductName in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        t - original Throwable thrown by DatabaseMetaData.getDatabaseProductName()
        Returns:
        a suitable Exception
      • beforeExecuteUpdate

        protected void beforeExecuteUpdate​(java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called immediately before Statement.executeUpdate(String) is called.
        Specified by:
        beforeExecuteUpdate in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        sql - SQL-statement of the SQL-execution-method
      • noteExecuteUpdateTime

        protected void noteExecuteUpdateTime​(java.lang.String sql,
                                             long timeNanoseconds,
                                             boolean success)
        Description copied from class: DataSource
        This event-method is called immediately after Statement.executeUpdate(String) is called, no matter whether the call was successful or not.
        Specified by:
        noteExecuteUpdateTime in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        sql - SQL-statement of the SQL-execution-method
        timeNanoseconds - the execution-time of Statement.executeUpdate(String) in nanoseconds, no matter whether the call was successful or not
        success - indicates whether the call was successful or not
      • beforeExecuteQuery

        protected void beforeExecuteQuery​(java.lang.String sql)
        Description copied from class: DataSource
        This event-method is called immediately before Statement.executeQuery(String) is called.
        Specified by:
        beforeExecuteQuery in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        sql - SQL-statement of the SQL-execution-method
      • noteExecuteQueryTime

        protected void noteExecuteQueryTime​(java.lang.String sql,
                                            long timeNanoseconds,
                                            boolean success)
        Description copied from class: DataSource
        This event-method is called immediately after Statement.executeQuery(String) is called, no matter whether the call was successful or not.
        Specified by:
        noteExecuteQueryTime in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        sql - SQL-statement of the SQL-execution-method
        timeNanoseconds - the execution-time of Statement.executeQuery(String) in nanoseconds, no matter whether the call was successful or not
        success - indicates whether the call was successful or not
      • noteReadResultTime

        protected void noteReadResultTime​(java.lang.String sql,
                                          long timeNanoseconds,
                                          boolean success)
        Description copied from class: DataSource
        This event-method is called immediately after ResultReader.readResult(ResultSet) is called, no matter whether the call was successful or not.
        Specified by:
        noteReadResultTime in class DataSource<java.lang.IllegalStateException,​CommonReadResultException extends java.lang.Exception>
        Parameters:
        sql - SQL-statement of the SQL-execution-method
        timeNanoseconds - the execution-time of ResultReader.readResult(ResultSet) in nanoseconds, no matter whether the call was successful or not
        success - indicates whether the call was successful or not