Package org.hibernate.engine.jdbc.spi
Class SqlExceptionHelper
- java.lang.Object
-
- org.hibernate.engine.jdbc.spi.SqlExceptionHelper
-
public class SqlExceptionHelper extends java.lang.ObjectHelper for handling SQLExceptions in various manners.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSqlExceptionHelper.StandardWarningHandlerStandard SQLWarning handler for logging warningsstatic interfaceSqlExceptionHelper.WarningHandlerContract for handlingwarningsstatic classSqlExceptionHelper.WarningHandlerLoggingSupportBasic support forSqlExceptionHelper.WarningHandlerimplementations which handlewarnings
-
Field Summary
Fields Modifier and Type Field Description static SqlExceptionHelper.StandardWarningHandlerSTANDARD_WARNING_HANDLERStatic 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 JDBCExceptionconvert(java.sql.SQLException sqlException, java.lang.String message)Convert an SQLException using the current converter, doing some logging first.JDBCExceptionconvert(java.sql.SQLException sqlException, java.lang.String message, java.lang.String sql)Convert an SQLException using the current converter, doing some logging first.SQLExceptionConvertergetSqlExceptionConverter()Access the current exception converter being used internally.voidhandleAndClearWarnings(java.sql.Connection connection, SqlExceptionHelper.WarningHandler handler)General purpose handling of warnings associated with a JDBCConnection.voidhandleAndClearWarnings(java.sql.Statement statement, SqlExceptionHelper.WarningHandler handler)General purpose handling of warnings associated with a JDBCStatement.voidlogAndClearWarnings(java.sql.Connection connection)Standard (legacy) behavior for logging warnings associated with a JDBCConnectionand clearing them.voidlogAndClearWarnings(java.sql.Statement statement)voidlogExceptions(java.sql.SQLException sqlException, java.lang.String message)Log the given (and any nested) exception.voidsetSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter)Inject the exception converter to use.voidwalkWarnings(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 JDBCConnectionand 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)
-
-