Package org.hibernate.engine.jdbc.spi
Class SqlExceptionHelper
java.lang.Object
org.hibernate.engine.jdbc.spi.SqlExceptionHelper
Helper for handling
SQLException
s in various manners.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Standard SQLWarning handler for logging warningsstatic interface
Contract for handling warningsstatic class
Basic support forSqlExceptionHelper.WarningHandler
implementations which handle warnings -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SqlExceptionHelper.StandardWarningHandler
Static access to the standard handler for logging warnings -
Constructor Summary
ConstructorsConstructorDescriptionSqlExceptionHelper
(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
Modifier and TypeMethodDescriptionconvert
(SQLException sqlException, String message) Convert an SQLException using the current converter, doing some logging first.convert
(SQLException sqlException, String message, String sql) Convert an SQLException using the current converter, doing some logging first.convert
(SQLException sqlException, Supplier<String> messageSupplier, String sql) Convert an SQLException using the current converter, doing some logging first.Access the current exception converter being used internally.void
handleAndClearWarnings
(Connection connection, SqlExceptionHelper.WarningHandler handler) General purpose handling of warnings associated with a JDBCConnection
.void
handleAndClearWarnings
(Statement statement, SqlExceptionHelper.WarningHandler handler) General purpose handling of warnings associated with a JDBCStatement
.void
logAndClearWarnings
(Connection connection) Standard (legacy) behavior for logging warnings associated with a JDBCConnection
and clearing them.void
logAndClearWarnings
(Statement statement) 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) Generic algorithm to walk the hierarchy of SQLWarnings
-
Field Details
-
STANDARD_WARNING_HANDLER
Static access to the standard handler for logging warnings
-
-
Constructor Details
-
SqlExceptionHelper
public SqlExceptionHelper(boolean logWarnings) Create an exception helper with a default exception converter. -
SqlExceptionHelper
Create an exception helper with a specific exception converter.- Parameters:
sqlExceptionConverter
- The exception converter to use.
-
-
Method Details
-
getSqlExceptionConverter
Access the current exception converter being used internally.- Returns:
- The current exception converter.
-
setSqlExceptionConverter
Inject the exception converter to use.- Parameters:
sqlExceptionConverter
- the converter to use, ornull
if the default converter should be used
-
convert
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
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
-
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 convertmessageSupplier
- An error message supplier.sql
- The SQL being executed when the exception occurred- Returns:
- The converted exception
-
logExceptions
Log the given (and any nested) exception.- Parameters:
sqlException
- The exception to logmessage
- The message text to use as a preamble.
-
walkWarnings
Generic algorithm to walk the hierarchy of SQLWarnings- Parameters:
warning
- The warning to walkhandler
- The handler
-
logAndClearWarnings
Standard (legacy) behavior for logging warnings associated with a JDBCConnection
and clearing them.Calls
handleAndClearWarnings(Connection, WarningHandler)
usingSTANDARD_WARNING_HANDLER
- Parameters:
connection
- The JDBC connection potentially containing warnings
-
logAndClearWarnings
-
handleAndClearWarnings
public void handleAndClearWarnings(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:
-
handleAndClearWarnings
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:
-