Class SqlExceptionHelper

java.lang.Object
org.hibernate.engine.jdbc.spi.SqlExceptionHelper

public class SqlExceptionHelper extends Object
Helper for handling SQLExceptions in various manners.
  • Field Details

  • Constructor Details

    • 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 Details

    • 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(Connection connection)
      Standard (legacy) behavior for logging warnings associated with a JDBC Connection and clearing them.

      Calls handleAndClearWarnings(Connection, WarningHandler) using STANDARD_WARNING_HANDLER

      Parameters:
      connection - The JDBC connection potentially containing warnings
    • logAndClearWarnings

      public void logAndClearWarnings(Statement statement)
    • handleAndClearWarnings

      public void handleAndClearWarnings(Connection connection, SqlExceptionHelper.WarningHandler handler)
      General purpose handling of warnings associated with a JDBC Connection.
      Parameters:
      connection - The JDBC connection potentially containing warnings
      handler - The handler for each individual warning in the stack.
      See Also:
    • handleAndClearWarnings

      public void handleAndClearWarnings(Statement statement, SqlExceptionHelper.WarningHandler handler)
      General purpose handling of warnings associated with a JDBC Statement.
      Parameters:
      statement - The JDBC statement potentially containing warnings
      handler - The handler for each individual warning in the stack.
      See Also: