Top Description Inners Fields Constructors Methods
org.hibernate.engine.jdbc.spi

public Class SqlExceptionHelper

extends Object
Class Inheritance
Imports
java.sql.Connection, .SQLException, .SQLWarning, .Statement, java.util.ArrayList, .List, org.hibernate.JDBCException, org.hibernate.exception.internal.SQLStateConverter, org.hibernate.exception.spi.SQLExceptionConverter, .ViolatedConstraintNameExtracter, org.hibernate.internal.CoreMessageLogger, org.hibernate.internal.util.StringHelper, org.jboss.logging.Logger, .Logger.Level

Helper for handling SQLExceptions in various manners.
Author
Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
SqlExceptionHelper.StandardWarningHandler

Standard SQLWarning handler for logging warnings

public static interface
public abstract static class
SqlExceptionHelper.WarningHandlerLoggingSupport

Basic support for WarningHandler implementations which handle warnings

Field Summary

Modifier and TypeField and Description
private static final SQLExceptionConverter
private static final String
private static final String
private static final CoreMessageLogger
private final boolean
private SQLExceptionConverter
public static final SqlExceptionHelper.StandardWarningHandler
STANDARD_WARNING_HANDLER

Static access to the standard handler for logging warnings

Constructor Summary

AccessConstructor and Description
public
SqlExceptionHelper(boolean logWarnings)

Create an exception helper with a default exception converter.

public
SqlExceptionHelper(SQLExceptionConverter
The exception converter to use.
sqlExceptionConverter
,
boolean logWarnings)

Create an exception helper with a specific exception converter.

Method Summary

Modifier and TypeMethod and Description
public JDBCException

Returns:

The converted exception
convert
(SQLException
The exception to convert
sqlException
,
String
An error message.
message
)

Convert an SQLException using the current converter, doing some logging first.

public JDBCException

Returns:

The converted exception
convert
(SQLException
The exception to convert
sqlException
,
String
An error message.
message
,
String
The SQL being executed when the exception occurred
sql
)

Convert an SQLException using the current converter, doing some logging first.

public SQLExceptionConverter

Returns:

The current exception converter.
getSqlExceptionConverter
()

Access the current exception converter being used internally.

public void
handleAndClearWarnings(Connection
The JDBC connection potentially containing warnings
connection
,
SqlExceptionHelper.WarningHandler
The handler for each individual warning in the stack.
handler
)

General purpose handling of warnings associated with a JDBC Connection.

public void
handleAndClearWarnings(Statement
The JDBC statement potentially containing warnings
statement
,
SqlExceptionHelper.WarningHandler
The handler for each individual warning in the stack.
handler
)

General purpose handling of warnings associated with a JDBC Statement.

public void
logAndClearWarnings(Connection
The JDBC connection potentially containing warnings
connection
)

Standard (legacy) behavior for logging warnings associated with a JDBC Connection and clearing them.

public void
public void
logExceptions(SQLException
The exception to log
sqlException
,
String
The message text to use as a preamble.
message
)

Log the given (and any nested) exception.

public void
setSqlExceptionConverter(SQLExceptionConverter
The converter to use.
sqlExceptionConverter
)

Inject the exception converter to use.

public void
walkWarnings(SQLWarning
The warning to walk
warning
,
SqlExceptionHelper.WarningHandler
The handler
handler
)

Generic algorithm to walk the hierarchy of SQLWarnings

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_CONVERTERback to summary
private static final SQLExceptionConverter DEFAULT_CONVERTER
DEFAULT_EXCEPTION_MSGback to summary
private static final String DEFAULT_EXCEPTION_MSG
DEFAULT_WARNING_MSGback to summary
private static final String DEFAULT_WARNING_MSG
LOGback to summary
private static final CoreMessageLogger LOG
logWarningsback to summary
private final boolean logWarnings
sqlExceptionConverterback to summary
private SQLExceptionConverter sqlExceptionConverter
STANDARD_WARNING_HANDLERback to summary
public static final SqlExceptionHelper.StandardWarningHandler STANDARD_WARNING_HANDLER

Static access to the standard handler for logging warnings

Constructor Detail

SqlExceptionHelperback to summary
public SqlExceptionHelper(boolean logWarnings)

Create an exception helper with a default exception converter.

SqlExceptionHelperback to summary
public SqlExceptionHelper(SQLExceptionConverter sqlExceptionConverter, boolean logWarnings)

Create an exception helper with a specific exception converter.

Parameters
sqlExceptionConverter:SQLExceptionConverter

The exception converter to use.

Method Detail

convertback to summary
public JDBCException convert(SQLException sqlException, String message)

Convert an SQLException using the current converter, doing some logging first.

Parameters
sqlException:SQLException

The exception to convert

message:String

An error message.

Returns:JDBCException

The converted exception

convertback to summary
public JDBCException convert(SQLException sqlException, String message, String sql)

Convert an SQLException using the current converter, doing some logging first.

Parameters
sqlException:SQLException

The exception to convert

message:String

An error message.

sql:String

The SQL being executed when the exception occurred

Returns:JDBCException

The converted exception

getSqlExceptionConverterback to summary
public SQLExceptionConverter getSqlExceptionConverter()

Access the current exception converter being used internally.

Returns:SQLExceptionConverter

The current exception converter.

handleAndClearWarningsback to summary
public void handleAndClearWarnings(Connection connection, SqlExceptionHelper.WarningHandler handler)

General purpose handling of warnings associated with a JDBC Connection.

Parameters
connection:Connection

The JDBC connection potentially containing warnings

handler:SqlExceptionHelper.WarningHandler

The handler for each individual warning in the stack.

Annotations
@SuppressWarnings:ThrowableResultOfMethodCallIgnored
See Also
walkWarnings
handleAndClearWarningsback to summary
public void handleAndClearWarnings(Statement statement, SqlExceptionHelper.WarningHandler handler)

General purpose handling of warnings associated with a JDBC Statement.

Parameters
statement:Statement

The JDBC statement potentially containing warnings

handler:SqlExceptionHelper.WarningHandler

The handler for each individual warning in the stack.

Annotations
@SuppressWarnings:ThrowableResultOfMethodCallIgnored
See Also
walkWarnings
logAndClearWarningsback to summary
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:Connection

The JDBC connection potentially containing warnings

logAndClearWarningsback to summary
public void logAndClearWarnings(Statement statement)
logExceptionsback to summary
public void logExceptions(SQLException sqlException, String message)

Log the given (and any nested) exception.

Parameters
sqlException:SQLException

The exception to log

message:String

The message text to use as a preamble.

setSqlExceptionConverterback to summary
public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter)

Inject the exception converter to use.

NOTE : null is allowed and signifies to use the default.

Parameters
sqlExceptionConverter:SQLExceptionConverter

The converter to use.

walkWarningsback to summary
public void walkWarnings(SQLWarning warning, SqlExceptionHelper.WarningHandler handler)

Generic algorithm to walk the hierarchy of SQLWarnings

Parameters
warning:SQLWarning

The warning to walk

handler:SqlExceptionHelper.WarningHandler

The handler

org.hibernate.engine.jdbc.spi back to summary

public Class SqlExceptionHelper.StandardWarningHandler

extends WarningHandlerLoggingSupport
Class Inheritance

Standard SQLWarning handler for logging warnings

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
StandardWarningHandler(String
The introduction message for the hierarchy
introMessage
)

Creates a StandardWarningHandler

Method Summary

Modifier and TypeMethod and Description
public boolean
protected void
logWarning(String
A description of the warning
description
,
String
The warning message
message
)

Implements abstract org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport.logWarning.

Delegate to log common details of a warning
public void
prepare(SQLWarning
The first warning in the stack.
warning
)

Implements org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.prepare.

Prepare for processing of a warning stack.
Inherited from org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport:
handleWarning

Field Detail

introMessageback to summary
private final String introMessage

Constructor Detail

StandardWarningHandlerback to summary
public StandardWarningHandler(String introMessage)

Creates a StandardWarningHandler

Parameters
introMessage:String

The introduction message for the hierarchy

Method Detail

doProcessback to summary
public boolean doProcess()

Implements org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.doProcess.

Doc from org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.doProcess.

Should processing be done? Allows short-circuiting if not.

Returns:boolean

True to process warnings, false otherwise.

Annotations
@Override
logWarningback to summary
protected void logWarning(String description, String message)

Implements abstract org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport.logWarning.

Doc from org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport.logWarning.

Delegate to log common details of a warning

Parameters
description:String

A description of the warning

message:String

The warning message

Annotations
@Override
prepareback to summary
public void prepare(SQLWarning warning)

Implements org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.prepare.

Doc from org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.prepare.

Prepare for processing of a warning stack.

Note that the warning here is also the first passed to handleWarning

Parameters
warning:SQLWarning

The first warning in the stack.

Annotations
@Override
org.hibernate.engine.jdbc.spi back to summary

public Interface SqlExceptionHelper.WarningHandler

Known Direct Implementers
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport

Contract for handling warnings

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

True to process warnings, false otherwise.
doProcess
()

Should processing be done?

public void
handleWarning(SQLWarning
The warning to handle.
warning
)

Handle an individual warning in the stack.

public void
prepare(SQLWarning
The first warning in the stack.
warning
)

Prepare for processing of a warning stack.

Method Detail

doProcessback to summary
public boolean doProcess()

Should processing be done? Allows short-circuiting if not.

Returns:boolean

True to process warnings, false otherwise.

handleWarningback to summary
public void handleWarning(SQLWarning warning)

Handle an individual warning in the stack.

Parameters
warning:SQLWarning

The warning to handle.

prepareback to summary
public void prepare(SQLWarning warning)

Prepare for processing of a warning stack.

Note that the warning here is also the first passed to handleWarning

Parameters
warning:SQLWarning

The first warning in the stack.

org.hibernate.engine.jdbc.spi back to summary

public abstract Class SqlExceptionHelper.WarningHandlerLoggingSupport

extends Object
implements WarningHandler
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandlerLoggingSupport
All Implemented Interfaces
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler
Known Direct Subclasses
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.StandardWarningHandler

Basic support for WarningHandler implementations which handle warnings

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
handleWarning(SQLWarning
The warning to handle.
warning
)

Implements org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.handleWarning.

Handle an individual warning in the stack.
protected abstract void
logWarning(String
A description of the warning
description
,
String
The warning message
message
)

Delegate to log common details of a warning

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

WarningHandlerLoggingSupportback to summary
public WarningHandlerLoggingSupport()

Method Detail

handleWarningback to summary
public final void handleWarning(SQLWarning warning)

Implements org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.handleWarning.

Doc from org.hibernate.engine.jdbc.spi.SqlExceptionHelper.WarningHandler.handleWarning.

Handle an individual warning in the stack.

Parameters
warning:SQLWarning

The warning to handle.

Annotations
@Override
logWarningback to summary
protected abstract void logWarning(String description, String message)

Delegate to log common details of a warning

Parameters
description:String

A description of the warning

message:String

The warning message