Package org.hibernate.engine.jdbc.spi
Class SqlExceptionHelper
- java.lang.Object
-
- org.hibernate.engine.jdbc.spi.SqlExceptionHelper
-
public class SqlExceptionHelper extends 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 handling warningsstatic class
SqlExceptionHelper.WarningHandlerLoggingSupport
Basic support forSqlExceptionHelper.WarningHandler
implementations which handle warnings
-
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(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.JDBCException
convert(SQLException sqlException, Supplier<String> messageSupplier, 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 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 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.- Parameters:
sqlExceptionConverter
- the converter to use, ornull
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 convertmessage
- 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 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
public void logExceptions(SQLException sqlException, 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(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(Connection connection)
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
public void logAndClearWarnings(Statement statement)
-
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:
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 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)
-
-