Top Description Fields Constructors Methods
org.springframework.jdbc.support

public abstract Class AbstractFallbackSQLExceptionTranslator

extends Object
implements SQLExceptionTranslator
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.support.SQLExceptionTranslator
Known Direct Subclasses
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator, org.springframework.jdbc.support.SQLExceptionSubclassTranslator, org.springframework.jdbc.support.SQLStateSQLExceptionTranslator
Imports
java.sql.SQLException, org.apache.commons.logging.Log, .LogFactory, org.springframework.dao.DataAccessException, org.springframework.lang.Nullable, org.springframework.util.Assert

Base class for SQLExceptionTranslator implementations that allow for a fallback to some other SQLExceptionTranslator, as well as for custom overrides.
Author
Juergen Hoeller
Since
2.5.6
See Also
doTranslate, setFallbackTranslator, setCustomTranslator

Field Summary

Modifier and TypeField and Description
private SQLExceptionTranslator
private SQLExceptionTranslator
protected final Log
logger

Logger available to subclasses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String

Returns:

the message String to use
buildMessage
(String
readable text describing the task being attempted
task
,
String
the SQL statement that caused the problem
sql
,
SQLException
the offending SQLException
ex
)

Build a message String for the given java.sql.SQLException.

protected abstract DataAccessException

Returns:

the DataAccessException, wrapping the SQLException; or null if no exception match found
doTranslate
(String
readable text describing the task being attempted
task
,
String
the SQL query or update that caused the problem (if known)
sql
,
SQLException
the offending SQLException
ex
)

Template method for actually translating the given exception.

public SQLExceptionTranslator
getCustomTranslator()

Return a custom exception translator, if any.

public SQLExceptionTranslator
getFallbackTranslator()

Return the fallback exception translator, if any.

public void
setCustomTranslator(SQLExceptionTranslator customTranslator)

Set a custom exception translator to override any match that this translator would find.

public void
setFallbackTranslator(SQLExceptionTranslator fallback)

Set the fallback translator to use when this translator cannot find a specific match itself.

public DataAccessException
translate(String
readable text describing the task being attempted
task
,
String
the SQL query or update that caused the problem (if known)
sql
,
SQLException
the offending SQLException
ex
)

Implements org.springframework.jdbc.support.SQLExceptionTranslator.translate.

Pre-checks the arguments, calls doTranslate, and invokes the fallback translator if necessary.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

customTranslatorback to summary
private SQLExceptionTranslator customTranslator
Annotations
@Nullable
fallbackTranslatorback to summary
private SQLExceptionTranslator fallbackTranslator
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

Constructor Detail

AbstractFallbackSQLExceptionTranslatorback to summary
public AbstractFallbackSQLExceptionTranslator()

Method Detail

buildMessageback to summary
protected String buildMessage(String task, String sql, SQLException ex)

Build a message String for the given java.sql.SQLException.

To be called by translator subclasses when creating an instance of a generic org.springframework.dao.DataAccessException class.

Parameters
task:String

readable text describing the task being attempted

sql:String

the SQL statement that caused the problem

ex:SQLException

the offending SQLException

Returns:String

the message String to use

doTranslateback to summary
protected abstract DataAccessException doTranslate(String task, String sql, SQLException ex)

Template method for actually translating the given exception.

The passed-in arguments will have been pre-checked. Furthermore, this method is allowed to return null to indicate that no exception match has been found and that fallback translation should kick in.

Parameters
task:String

readable text describing the task being attempted

sql:String

the SQL query or update that caused the problem (if known)

ex:SQLException

the offending SQLException

Returns:DataAccessException

the DataAccessException, wrapping the SQLException; or null if no exception match found

Annotations
@Nullable
getCustomTranslatorback to summary
public SQLExceptionTranslator getCustomTranslator()

Return a custom exception translator, if any.

Annotations
@Nullable
Since
6.1
See Also
setCustomTranslator
getFallbackTranslatorback to summary
public SQLExceptionTranslator getFallbackTranslator()

Return the fallback exception translator, if any.

Annotations
@Nullable
See Also
setFallbackTranslator
setCustomTranslatorback to summary
public void setCustomTranslator(SQLExceptionTranslator customTranslator)

Set a custom exception translator to override any match that this translator would find. Note that such a custom SQLExceptionTranslator delegate is meant to return null if it does not have an override itself.

Since
6.1
setFallbackTranslatorback to summary
public void setFallbackTranslator(SQLExceptionTranslator fallback)

Set the fallback translator to use when this translator cannot find a specific match itself.

translateback to summary
public DataAccessException translate(String task, String sql, SQLException ex)

Implements org.springframework.jdbc.support.SQLExceptionTranslator.translate.

Pre-checks the arguments, calls doTranslate, and invokes the fallback translator if necessary.

Parameters
task:String

Doc from org.springframework.jdbc.support.SQLExceptionTranslator.translate.

readable text describing the task being attempted

sql:String

Doc from org.springframework.jdbc.support.SQLExceptionTranslator.translate.

the SQL query or update that caused the problem (if known)

ex:SQLException

Doc from org.springframework.jdbc.support.SQLExceptionTranslator.translate.

the offending SQLException

Returns:DataAccessException

Doc from org.springframework.jdbc.support.SQLExceptionTranslator.translate.

the DataAccessException wrapping the SQLException, or null if no specific translation could be applied

Annotations
@Override
@Nullable