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 for
SQLExceptionTranslator
implementations that allow for a
fallback to some other SQLExceptionTranslator
, as well as for custom
overrides.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.Return a custom exception translator, if any.Return the fallback exception translator, if any.void
setCustomTranslator
(SQLExceptionTranslator customTranslator) Set a custom exception translator to override any match that this translator would find.void
setFallbackTranslator
(SQLExceptionTranslator fallback) Set the fallback translator to use when this translator cannot find a specific match itself.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.
-
Field Details
-
logger
Logger available to subclasses.
-
-
Constructor Details
-
AbstractFallbackSQLExceptionTranslator
public AbstractFallbackSQLExceptionTranslator()
-
-
Method Details
-
setFallbackTranslator
Set the fallback translator to use when this translator cannot find a specific match itself. -
getFallbackTranslator
Return the fallback exception translator, if any. -
setCustomTranslator
Set a custom exception translator to override any match that this translator would find. Note that such a customSQLExceptionTranslator
delegate is meant to returnnull
if it does not have an override itself.- Since:
- 6.1
-
getCustomTranslator
Return a custom exception translator, if any.- Since:
- 6.1
- See Also:
-
translate
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 specific translation could be applied - See Also:
-
doTranslate
@Nullable protected abstract DataAccessException doTranslate(String task, @Nullable 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
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
-