|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
public class SQLErrorCodeSQLExceptionTranslator
Implementation of SQLExceptionTranslator
that analyzes vendor-specific error codes.
More precise than an implementation based on SQL state, but heavily vendor-specific.
This class applies the following matching rules:
SQLStateSQLExceptionTranslator
is the
default fallback translator, analyzing the exception's SQL state only. On Java 6
which introduces its own SQLException
subclass hierarchy, we will
use SQLExceptionSubclassTranslator
by default, which in turns falls back
to Spring's own SQL state translation when not encountering specific subclasses.
The configuration file named "sql-error-codes.xml" is by default read from this package. It can be overridden through a file of the same name in the root of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the Spring JDBC package is loaded from the same ClassLoader.
SQLErrorCodesFactory
,
SQLStateSQLExceptionTranslator
Field Summary |
---|
Fields inherited from class org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator |
---|
logger |
Constructor Summary | |
---|---|
SQLErrorCodeSQLExceptionTranslator()
Constructor for use as a JavaBean. |
|
SQLErrorCodeSQLExceptionTranslator(DataSource dataSource)
Create a SQL error code translator for the given DataSource. |
|
SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)
Create a SQLErrorCode translator given these error codes. |
|
SQLErrorCodeSQLExceptionTranslator(String dbName)
Create a SQL error code translator for the given database product name. |
Method Summary | |
---|---|
protected DataAccessException |
createCustomException(String task,
String sql,
SQLException sqlEx,
Class exceptionClass)
Create a custom DataAccessException, based on a given exception class from a CustomSQLErrorCodesTranslation definition. |
protected DataAccessException |
customTranslate(String task,
String sql,
SQLException sqlEx)
Subclasses can override this method to attempt a custom mapping from SQLException to DataAccessException. |
protected DataAccessException |
doTranslate(String task,
String sql,
SQLException ex)
Template method for actually translating the given exception. |
SQLErrorCodes |
getSqlErrorCodes()
Return the error codes used by this translator. |
void |
setDatabaseProductName(String dbName)
Set the database product name for this translator. |
void |
setDataSource(DataSource dataSource)
Set the DataSource for this translator. |
void |
setSqlErrorCodes(SQLErrorCodes sec)
Set custom error codes to be used for translation. |
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 |
Constructor Detail |
---|
public SQLErrorCodeSQLExceptionTranslator()
public SQLErrorCodeSQLExceptionTranslator(DataSource dataSource)
dataSource
- DataSource to use to find metadata and establish
which error codes are usableSQLErrorCodesFactory
public SQLErrorCodeSQLExceptionTranslator(String dbName)
dbName
- the database product name that identifies the error codes entrySQLErrorCodesFactory
,
DatabaseMetaData.getDatabaseProductName()
public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)
sec
- error codesMethod Detail |
---|
public void setDataSource(DataSource dataSource)
Setting this property will cause a Connection to be obtained from the DataSource to get the metadata.
dataSource
- DataSource to use to find metadata and establish
which error codes are usableSQLErrorCodesFactory.getErrorCodes(javax.sql.DataSource)
,
DatabaseMetaData.getDatabaseProductName()
public void setDatabaseProductName(String dbName)
Setting this property will avoid obtaining a Connection from the DataSource to get the metadata.
dbName
- the database product name that identifies the error codes entrySQLErrorCodesFactory.getErrorCodes(String)
,
DatabaseMetaData.getDatabaseProductName()
public void setSqlErrorCodes(SQLErrorCodes sec)
sec
- custom error codes to usepublic SQLErrorCodes getSqlErrorCodes()
setDataSource(javax.sql.DataSource)
protected DataAccessException doTranslate(String task, String sql, SQLException ex)
AbstractFallbackSQLExceptionTranslator
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.
doTranslate
in class AbstractFallbackSQLExceptionTranslator
task
- readable text describing the task being attemptedsql
- SQL query or update that caused the problem (may be null
)ex
- the offending SQLException
SQLException
;
or null
if no exception match foundprotected DataAccessException customTranslate(String task, String sql, SQLException sqlEx)
task
- readable text describing the task being attemptedsql
- SQL query or update that caused the problem. May be null
.sqlEx
- the offending SQLException
protected DataAccessException createCustomException(String task, String sql, SQLException sqlEx, Class exceptionClass)
task
- readable text describing the task being attemptedsql
- SQL query or update that caused the problem. May be null
.sqlEx
- the offending SQLExceptionexceptionClass
- the exception class to use, as defined in the
CustomSQLErrorCodesTranslation definition
CustomSQLErrorCodesTranslation.setExceptionClass(java.lang.Class)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |