Package org.springframework.jdbc.support
Class AbstractFallbackSQLExceptionTranslator
- java.lang.Object
- org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
- All Implemented Interfaces:
SQLExceptionTranslator
- Direct Known Subclasses:
SQLErrorCodeSQLExceptionTranslator
,SQLExceptionSubclassTranslator
,SQLStateSQLExceptionTranslator
public abstract class AbstractFallbackSQLExceptionTranslator extends Object implements SQLExceptionTranslator
Base class forSQLExceptionTranslator
implementations that allow for fallback to some otherSQLExceptionTranslator
.- Since:
- 2.5.6
- Author:
- Juergen Hoeller
Constructor Summary
Constructors Constructor Description AbstractFallbackSQLExceptionTranslator()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
buildMessage(String task, String sql, SQLException ex)
Build a messageString
for the givenSQLException
.protected abstract DataAccessException
doTranslate(String task, String sql, SQLException ex)
Template method for actually translating the given exception.SQLExceptionTranslator
getFallbackTranslator()
Return the fallback exception translator, if any.void
setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQL state fallback translator (typically aSQLStateSQLExceptionTranslator
).DataAccessException
translate(String task, String sql, SQLException ex)
Pre-checks the arguments, callsdoTranslate(java.lang.String, java.lang.String, java.sql.SQLException)
, and invokes thefallback translator
if necessary.
Constructor Detail
AbstractFallbackSQLExceptionTranslator
public AbstractFallbackSQLExceptionTranslator()
Method Detail
setFallbackTranslator
public void setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQL state fallback translator (typically aSQLStateSQLExceptionTranslator
).
getFallbackTranslator
public SQLExceptionTranslator getFallbackTranslator()
Return the fallback exception translator, if any.
translate
public DataAccessException translate(String task, String sql, SQLException ex)
Pre-checks the arguments, callsdoTranslate(java.lang.String, java.lang.String, java.sql.SQLException)
, and invokes thefallback translator
if necessary.- Specified by:
translate
in interfaceSQLExceptionTranslator
- Parameters:
task
- readable text describing the task being attemptedsql
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- Returns:
- the DataAccessException wrapping the
SQLException
, ornull
if no translation could be applied (in a custom translator; the default translators always throw anUncategorizedSQLException
in such a case) - See Also:
NestedRuntimeException.getRootCause()
doTranslate
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
- readable text describing the task being attemptedsql
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- Returns:
- the DataAccessException, wrapping the
SQLException
; ornull
if no exception match found
buildMessage
protected String buildMessage(String task, String sql, SQLException ex)
Build a messageString
for the givenSQLException
.To be called by translator subclasses when creating an instance of a generic
DataAccessException
class.- Parameters:
task
- readable text describing the task being attemptedsql
- the SQL statement that caused the problemex
- the offendingSQLException
- Returns:
- the message
String
to use