|
From: Thomas R. <tho...@tr...> - 2004-06-30 13:18:52
|
I have added new feature for specifying custom translations in the
sql-error-codes.xml:
<bean id="Oracle" class="org.springframework.jdbc.support.SQLErrorCodes">
<property
name="badSqlGrammarCodes"><value>900,903,904,917,936,942,17006</value></property>
<property
name="dataIntegrityViolationCodes"><value>1,1400,1722,2291</value></property>
<property name="customTranslations">
<list>
<bean
class="org.springframework.jdbc.support.CustomSQLErrorCodesTranslation">
<property name="errorCodes"><value>942</value></property>
<property
name="exceptionClass"><value>com.mycompany.test.MyCustomException</value></property>
</bean>
</list>
</property>
</bean>
The custom exception class must currently be a subclass of
DataAccessException - I'm considering allowing any runtime exception
unless someone objects to that. Right now there is support for the
following constructors (String), (String, Throwable), (String,
SQLException), (String, String, Throwable) and (String, String,
SQLException). If there are two String parameters, the first one gets
the task and the second one gets the sql that was used. If there is
only one String, it gets the task and the sql concatenated. This is
consistent with the current DataAccessException usage.
I have added SQLErrorCodes tests and I am still working on the
SQLErrorCodeExceptionTranslator tests - I will commit them later today
or tomorrow.
The order of translation is now:
1. call to customTranslate overridden method
2. custom translations (your own exception) specified in customized
sql-error-codes.xml (!! NEW Feature !!)
3. translation of error codes (standard 5 categories) in customized
sql-error-codes.xml
4. standard translation of codes in standard sql-error-codes.xml
5. fallback on sql state translation
Thomas
|