org.hibernate.engine.jdbc.spi
Class SqlExceptionHelper

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

public class SqlExceptionHelper
extends Object

Helper for handling SQLExceptions in various manners.


Nested Class Summary
static class SqlExceptionHelper.StandardWarningHandler
           
static interface SqlExceptionHelper.WarningHandler
          Contract for handling warnings
static class SqlExceptionHelper.WarningHandlerLoggingSupport
          Basic support for SqlExceptionHelper.WarningHandler implementations which log
 
Field Summary
static SQLExceptionConverter DEFAULT_CONVERTER
           
static String DEFAULT_EXCEPTION_MSG
           
static String DEFAULT_WARNING_MSG
           
static SqlExceptionHelper.StandardWarningHandler STANDARD_WARNING_HANDLER
           
 
Constructor Summary
SqlExceptionHelper()
          Create an exception helper with a default exception converter.
SqlExceptionHelper(SQLExceptionConverter sqlExceptionConverter)
          Create an exception helper with a specific exception converter.
 
Method Summary
 JDBCException convert(SQLException sqlException, String message)
          Convert an SQLException using the current converter, doing some logging first.
 JDBCException convert(SQLException sqlException, String message, String sql)
          Convert an SQLException using the current converter, doing some logging first.
 SQLExceptionConverter getSqlExceptionConverter()
          Access the current exception converter being used internally.
 void handleAndClearWarnings(Connection connection, SqlExceptionHelper.WarningHandler handler)
          General purpose handling of warnings associated with a JDBC Connection.
 void handleAndClearWarnings(Statement statement, SqlExceptionHelper.WarningHandler handler)
          General purpose handling of warnings associated with a JDBC Statement.
 void logAndClearWarnings(Connection connection)
          Standard (legacy) behavior for logging warnings associated with a JDBC Connection and clearing them.
 void logExceptions(SQLException sqlException, String message)
          Log the given (and any nested) exception.
 void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter)
          Inject the exception converter to use.
 void walkWarnings(SQLWarning warning, SqlExceptionHelper.WarningHandler handler)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXCEPTION_MSG

public static final String DEFAULT_EXCEPTION_MSG
See Also:
Constant Field Values

DEFAULT_WARNING_MSG

public static final String DEFAULT_WARNING_MSG
See Also:
Constant Field Values

DEFAULT_CONVERTER

public static final SQLExceptionConverter DEFAULT_CONVERTER

STANDARD_WARNING_HANDLER

public static SqlExceptionHelper.StandardWarningHandler STANDARD_WARNING_HANDLER
Constructor Detail

SqlExceptionHelper

public SqlExceptionHelper()
Create an exception helper with a default exception converter.


SqlExceptionHelper

public SqlExceptionHelper(SQLExceptionConverter sqlExceptionConverter)
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(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

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)

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

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:
walkWarnings(java.sql.SQLWarning, org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler)

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:
walkWarnings(java.sql.SQLWarning, org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler)


Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.