The Spring Framework

org.springframework.jdbc.support
Class SQLExceptionSubclassTranslator

java.lang.Object
  extended by org.springframework.jdbc.support.SQLExceptionSubclassTranslator
All Implemented Interfaces:
SQLExceptionTranslator

public class SQLExceptionSubclassTranslator
extends Object
implements SQLExceptionTranslator

SQLExceptionTranslator implementation that analyzes the SQLException subclass that was returned. This is only available with JDBC 4.0 and later drivers when using Java 6 or later.

Since:
2.5
Author:
Thomas Risberg
See Also:
SQLException

Field Summary
protected  Log logger
          Logger available to subclasses
 
Constructor Summary
SQLExceptionSubclassTranslator()
           
 
Method Summary
protected  String buildMessage(String task, String sql, SQLException ex)
          Build a message String for the given SQLException.
 DataAccessException translate(String task, String sql, SQLException ex)
          Translate the given SQLException into a generic DataAccessException.
 
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

SQLExceptionSubclassTranslator

public SQLExceptionSubclassTranslator()
Method Detail

translate

public DataAccessException translate(String task,
                                     String sql,
                                     SQLException ex)
Description copied from interface: SQLExceptionTranslator
Translate the given SQLException into a generic DataAccessException.

The returned DataAccessException is supposed to contain the original SQLException as root cause. However, client code may not generally rely on this due to DataAccessExceptions possibly being caused by other resource APIs as well. That said, a getRootCause() instanceof SQLException check (and subsequent cast) is considered reliable when expecting JDBC-based access to have happened.

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()

buildMessage

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

Called 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

The Spring Framework

Copyright © 2002-2007 The Spring Framework.