Package org.hibernate.engine.jdbc.spi
Class SqlExceptionHelper
- java.lang.Object
-
- org.hibernate.engine.jdbc.spi.SqlExceptionHelper
-
public class SqlExceptionHelper extends java.lang.Object
Helper for handling SQLExceptions in various manners.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlExceptionHelper.StandardWarningHandler
Standard SQLWarning handler for logging warningsstatic interface
SqlExceptionHelper.WarningHandler
Contract for handlingwarnings
static class
SqlExceptionHelper.WarningHandlerLoggingSupport
Basic support forSqlExceptionHelper.WarningHandler
implementations which handlewarnings
-
Field Summary
Fields Modifier and Type Field Description static SqlExceptionHelper.StandardWarningHandler
STANDARD_WARNING_HANDLER
Static access to the standard handler for logging warnings
-
Constructor Summary
Constructors Constructor Description SqlExceptionHelper(boolean logWarnings)
Create an exception helper with a default exception converter.SqlExceptionHelper(SQLExceptionConverter sqlExceptionConverter, boolean logWarnings)
Create an exception helper with a specific exception converter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JDBCException
convert(java.sql.SQLException sqlException, java.lang.String message)
Convert an SQLException using the current converter, doing some logging first.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.SQLExceptionConverter
getSqlExceptionConverter()
Access the current exception converter being used internally.void
handleAndClearWarnings(java.sql.Connection connection, SqlExceptionHelper.WarningHandler handler)
General purpose handling of warnings associated with a JDBCConnection
.void
handleAndClearWarnings(java.sql.Statement statement, SqlExceptionHelper.WarningHandler handler)
General purpose handling of warnings associated with a JDBCStatement
.void
logAndClearWarnings(java.sql.Connection connection)
Standard (legacy) behavior for logging warnings associated with a JDBCConnection
and clearing them.void
logAndClearWarnings(java.sql.Statement statement)
void
logExceptions(java.sql.SQLException sqlException, java.lang.String message)
Log the given (and any nested) exception.void
setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter)
Inject the exception converter to use.void
walkWarnings(java.sql.SQLWarning warning, SqlExceptionHelper.WarningHandler handler)
Generic algorithm to walk the hierarchy of SQLWarnings
-
-
-
Field Detail
-
STANDARD_WARNING_HANDLER
public static final SqlExceptionHelper.StandardWarningHandler STANDARD_WARNING_HANDLER
Static access to the standard handler for logging warnings
-
-
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 convertmessage
- 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 convertmessage
- 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 logmessage
- 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 walkhandler
- The handler
-
logAndClearWarnings
public void logAndClearWarnings(java.sql.Connection connection)
Standard (legacy) behavior for logging warnings associated with a JDBCConnection
and clearing them. CallshandleAndClearWarnings(Connection, WarningHandler)
usingSTANDARD_WARNING_HANDLER
- Parameters:
connection
- The JDBC connection potentially containing warnings
-
logAndClearWarnings
public void logAndClearWarnings(java.sql.Statement statement)
-
handleAndClearWarnings
public void handleAndClearWarnings(java.sql.Connection connection, SqlExceptionHelper.WarningHandler handler)
General purpose handling of warnings associated with a JDBCConnection
.- Parameters:
connection
- The JDBC connection potentially containing warningshandler
- 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(java.sql.Statement statement, SqlExceptionHelper.WarningHandler handler)
General purpose handling of warnings associated with a JDBCStatement
.- Parameters:
statement
- The JDBC statement potentially containing warningshandler
- The handler for each individual warning in the stack.- See Also:
walkWarnings(java.sql.SQLWarning, org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler)
-
-