Class SqlExceptionHelper


  • public class SqlExceptionHelper
    extends Object
    Helper for handling SQLExceptions in various manners.
    • Constructor Detail

      • SqlExceptionHelper

        public SqlExceptionHelper​(boolean logWarnings)
        Create an exception helper with a default exception converter.
      • SqlExceptionHelper

        public SqlExceptionHelper​(SQLExceptionConverter sqlExceptionConverter,
                                  boolean logWarnings)
        Create an exception helper with a specific exception converter.
        Parameters:
        sqlExceptionConverter - The exception converter to use.
    • Method Detail

      • getSqlExceptionConverter

        public SQLExceptionConverter getSqlExceptionConverter()
        Access the current exception converter being used internally.
        Returns:
        The current exception converter.
      • setSqlExceptionConverter

        public void setSqlExceptionConverter​(SQLExceptionConverter sqlExceptionConverter)
        Inject the exception converter to use.
        Parameters:
        sqlExceptionConverter - the converter to use, or null if the default converter should be used
      • convert

        public JDBCException convert​(SQLException sqlException,
                                     String message)
        Convert an SQLException using the current converter, doing some logging first.
        Parameters:
        sqlException - The exception to convert
        message - An error message.
        Returns:
        The converted exception
      • convert

        public JDBCException convert​(SQLException sqlException,
                                     String message,
                                     String sql)
        Convert an SQLException using the current converter, doing some logging first.
        Parameters:
        sqlException - The exception to convert
        message - An error message.
        sql - The SQL being executed when the exception occurred
        Returns:
        The converted exception
      • convert

        public JDBCException convert​(SQLException sqlException,
                                     Supplier<String> messageSupplier,
                                     String sql)
        Convert an SQLException using the current converter, doing some logging first.
        Parameters:
        sqlException - The exception to convert
        messageSupplier - An error message supplier.
        sql - The SQL being executed when the exception occurred
        Returns:
        The converted exception
      • logExceptions

        public void logExceptions​(SQLException sqlException,
                                  String message)
        Log the given (and any nested) exception.
        Parameters:
        sqlException - The exception to log
        message - The message text to use as a preamble.
      • walkWarnings

        public void walkWarnings​(SQLWarning warning,
                                 SqlExceptionHelper.WarningHandler handler)
        Generic algorithm to walk the hierarchy of SQLWarnings
        Parameters:
        warning - The warning to walk
        handler - The handler
      • logAndClearWarnings

        public void logAndClearWarnings​(Statement statement)