|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
public class SQLErrorCodeSQLExceptionTranslator
Implementation of SQLExceptionTranslator that uses specific vendor codes. More precise than SQL state implementation, but vendor-specific.
This class applies the following matching rules:
SQLErrorCodesFactory
,
SQLStateSQLExceptionTranslator
Field Summary | |
---|---|
protected Log |
logger
Logger available to subclasses |
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 String |
buildMessage(String task,
String sql,
SQLException sqlEx)
Build a message String for the given SQLException. |
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. |
SQLExceptionTranslator |
getFallbackTranslator()
Return the fallback exception translator. |
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 |
setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQL state fallback translator. |
void |
setSqlErrorCodes(SQLErrorCodes sec)
Set custom error codes to be used for translation. |
DataAccessException |
translate(String task,
String sql,
SQLException sqlEx)
Translate the given SQL exception into a generic data access exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
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)
public void setFallbackTranslator(SQLExceptionTranslator fallback)
fallback
- custom fallback exception translator to use if error code
translation failsSQLStateSQLExceptionTranslator
public SQLExceptionTranslator getFallbackTranslator()
public DataAccessException translate(String task, String sql, SQLException sqlEx)
SQLExceptionTranslator
translate
in interface SQLExceptionTranslator
task
- readable text describing the task being attemptedsql
- SQL query or update that caused the problem. May be null
.sqlEx
- the offending SQLException
protected String buildMessage(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 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 |