Class SqlExceptionHelper


  • public class SqlExceptionHelper
    extends java.lang.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.

        NOTE : null is allowed and signifies to use the default.

        Parameters:
        sqlExceptionConverter - The converter to use.
      • convert

        public JDBCException convert​(java.sql.SQLException sqlException,
                                     java.lang.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​(java.sql.SQLException sqlException,
                                     java.lang.String message,
                                     java.lang.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
      • logExceptions

        public void logExceptions​(java.sql.SQLException sqlException,
                                  java.lang.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​(java.sql.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​(java.sql.Statement statement)