org.springframework.jdbc.support
Class AbstractFallbackSQLExceptionTranslator

java.lang.Object
  extended by 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 fallback to some other SQLExceptionTranslator.

Since:
2.5.6
Author:
Juergen Hoeller

Field Summary
protected  Log logger
          Logger available to subclasses
 
Constructor Summary
AbstractFallbackSQLExceptionTranslator()
           
 
Method Summary
protected  String buildMessage(String task, String sql, SQLException ex)
          Build a message String for the given SQLException.
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 a SQLStateSQLExceptionTranslator).
 DataAccessException translate(String task, String sql, SQLException ex)
          Pre-checks the arguments, calls doTranslate(java.lang.String, java.lang.String, java.sql.SQLException), and invokes the fallback translator if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

AbstractFallbackSQLExceptionTranslator

public AbstractFallbackSQLExceptionTranslator()
Method Detail

setFallbackTranslator

public void setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQL state fallback translator (typically a SQLStateSQLExceptionTranslator).


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, calls doTranslate(java.lang.String, java.lang.String, java.sql.SQLException), and invokes the fallback translator if necessary.

Specified by:
translate in interface SQLExceptionTranslator
Parameters:
task - readable text describing the task being attempted
sql - SQL query or update that caused the problem (may be null)
ex - the offending SQLException
Returns:
the DataAccessException, wrapping the SQLException
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 attempted
sql - SQL query or update that caused the problem (may be null)
ex - the offending SQLException
Returns:
the DataAccessException, wrapping the SQLException; or null if no exception match found

buildMessage

protected String buildMessage(String task,
                              String sql,
                              SQLException ex)
Build a message String for the given SQLException.

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

Parameters:
task - readable text describing the task being attempted
sql - the SQL statement that caused the problem (may be null)
ex - the offending SQLException
Returns:
the message String to use