org.springframework.jdbc.support
Class SQLStateSQLExceptionTranslator

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

public class SQLStateSQLExceptionTranslator
extends AbstractFallbackSQLExceptionTranslator

SQLExceptionTranslator implementation that analyzes the SQL state in the SQLException based on the first two digits (the SQL state "class"). Detects standard SQL state values and well-known vendor-specific SQL states.

Not able to diagnose all problems, but is portable between databases and does not require special initialization (no database vendor detection, etc.). For more precise translation, consider SQLErrorCodeSQLExceptionTranslator.

Author:
Rod Johnson, Juergen Hoeller, Thomas Risberg
See Also:
SQLException.getSQLState(), SQLErrorCodeSQLExceptionTranslator

Field Summary
private static java.util.Set<java.lang.String> BAD_SQL_GRAMMAR_CODES
           
private static java.util.Set<java.lang.String> CONCURRENCY_FAILURE_CODES
           
private static java.util.Set<java.lang.String> DATA_ACCESS_RESOURCE_FAILURE_CODES
           
private static java.util.Set<java.lang.String> DATA_INTEGRITY_VIOLATION_CODES
           
private static java.util.Set<java.lang.String> TRANSIENT_DATA_ACCESS_RESOURCE_CODES
           
 
Fields inherited from class org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
logger
 
Constructor Summary
SQLStateSQLExceptionTranslator()
           
 
Method Summary
protected  DataAccessException doTranslate(java.lang.String task, java.lang.String sql, java.sql.SQLException ex)
          Template method for actually translating the given exception.
private  java.lang.String getSqlState(java.sql.SQLException ex)
          Gets the SQL state code from the supplied exception.
 
Methods inherited from class org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
buildMessage, getFallbackTranslator, setFallbackTranslator, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BAD_SQL_GRAMMAR_CODES

private static final java.util.Set<java.lang.String> BAD_SQL_GRAMMAR_CODES

DATA_INTEGRITY_VIOLATION_CODES

private static final java.util.Set<java.lang.String> DATA_INTEGRITY_VIOLATION_CODES

DATA_ACCESS_RESOURCE_FAILURE_CODES

private static final java.util.Set<java.lang.String> DATA_ACCESS_RESOURCE_FAILURE_CODES

TRANSIENT_DATA_ACCESS_RESOURCE_CODES

private static final java.util.Set<java.lang.String> TRANSIENT_DATA_ACCESS_RESOURCE_CODES

CONCURRENCY_FAILURE_CODES

private static final java.util.Set<java.lang.String> CONCURRENCY_FAILURE_CODES
Constructor Detail

SQLStateSQLExceptionTranslator

public SQLStateSQLExceptionTranslator()
Method Detail

doTranslate

protected DataAccessException doTranslate(java.lang.String task,
                                          java.lang.String sql,
                                          java.sql.SQLException ex)
Description copied from class: AbstractFallbackSQLExceptionTranslator
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.

Specified by:
doTranslate in class AbstractFallbackSQLExceptionTranslator
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

getSqlState

private java.lang.String getSqlState(java.sql.SQLException ex)
Gets the SQL state code from the supplied exception.

Some JDBC drivers nest the actual exception from a batched update, so we might need to dig down into the nested exception.

Parameters:
ex - the exception from which the SQL state is to be extracted
Returns:
the SQL state code