From: Thomas R. <tri...@us...> - 2009-03-17 15:20:56
|
Update of /cvsroot/springframework/spring/src/org/springframework/jdbc/support In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16163/src/org/springframework/jdbc/support Modified Files: SQLErrorCodeSQLExceptionTranslator.java SQLErrorCodes.java Log Message: added the option of providing a database specific custom SQLExceptionTranslator to provide customized translation for any SQLException before the error codes translation happens (SPR-4899 backport) Index: SQLErrorCodes.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/SQLErrorCodes.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** SQLErrorCodes.java 17 Mar 2009 15:12:21 -0000 1.18 --- SQLErrorCodes.java 17 Mar 2009 15:20:29 -0000 1.19 *************** *** 39,42 **** --- 39,44 ---- private boolean useSqlStateForTranslation = false; + private SQLExceptionTranslator customSqlExceptionTranslator = null; + private String[] badSqlGrammarCodes = new String[0]; *************** *** 98,101 **** --- 100,124 ---- } + public SQLExceptionTranslator getCustomSqlExceptionTranslator() { + return customSqlExceptionTranslator; + } + + public void setCustomSqlExceptionTranslatorClass(Class customSqlExceptionTranslatorClass) { + if (customSqlExceptionTranslatorClass != null) { + try { + this.customSqlExceptionTranslator = + (SQLExceptionTranslator) customSqlExceptionTranslatorClass.newInstance(); + } + catch (InstantiationException e) { + throw new InvalidDataAccessResourceUsageException( + "Unable to instantiate " + customSqlExceptionTranslatorClass.getName(), e); + } + catch (IllegalAccessException e) { + throw new InvalidDataAccessResourceUsageException( + "Unable to instantiate " + customSqlExceptionTranslatorClass.getName(), e); + } + } + } + public void setBadSqlGrammarCodes(String[] badSqlGrammarCodes) { this.badSqlGrammarCodes = StringUtils.sortStringArray(badSqlGrammarCodes); Index: SQLErrorCodeSQLExceptionTranslator.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** SQLErrorCodeSQLExceptionTranslator.java 17 Mar 2009 15:12:21 -0000 1.33 --- SQLErrorCodeSQLExceptionTranslator.java 17 Mar 2009 15:20:29 -0000 1.34 *************** *** 188,191 **** --- 188,202 ---- } + // Next, try the custom SQLException translator, if available. + if (this.sqlErrorCodes != null) { + SQLExceptionTranslator customTranslator = this.sqlErrorCodes.getCustomSqlExceptionTranslator(); + if (customTranslator != null) { + DataAccessException customDex = customTranslator.translate(task, sql, sqlEx); + if (customDex != null) { + return customDex; + } + } + } + // Check SQLErrorCodes with corresponding error code, if available. if (this.sqlErrorCodes != null) { |