From: Thomas R. <tri...@us...> - 2009-03-17 15:12:57
|
Update of /cvsroot/springframework/spring/src/org/springframework/jdbc/support In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14903/src/org/springframework/jdbc/support Modified Files: SQLErrorCodeSQLExceptionTranslator.java SQLErrorCodes.java sql-error-codes.xml Log Message: added a DuplicatKeyException catagory for SQLException translation (SPR-5125 backport) Index: SQLErrorCodes.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/SQLErrorCodes.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** SQLErrorCodes.java 7 Nov 2008 20:22:24 -0000 1.17 --- SQLErrorCodes.java 17 Mar 2009 15:12:21 -0000 1.18 *************** *** 18,21 **** --- 18,22 ---- import org.springframework.util.StringUtils; + import org.springframework.dao.InvalidDataAccessResourceUsageException; /** *************** *** 42,45 **** --- 43,48 ---- private String[] invalidResultSetAccessCodes = new String[0]; + private String[] duplicateKeyCodes = new String[0]; + private String[] dataIntegrityViolationCodes = new String[0]; *************** *** 58,62 **** private CustomSQLErrorCodesTranslation[] customTranslations; - /** * Set this property if the database name contains spaces, --- 61,64 ---- *************** *** 96,100 **** } - public void setBadSqlGrammarCodes(String[] badSqlGrammarCodes) { this.badSqlGrammarCodes = StringUtils.sortStringArray(badSqlGrammarCodes); --- 98,101 ---- *************** *** 113,116 **** --- 114,125 ---- } + public String[] getDuplicateKeyCodes() { + return duplicateKeyCodes; + } + + public void setDuplicateKeyCodes(String[] duplicateKeyCodes) { + this.duplicateKeyCodes = duplicateKeyCodes; + } + public void setDataIntegrityViolationCodes(String[] dataIntegrityViolationCodes) { this.dataIntegrityViolationCodes = StringUtils.sortStringArray(dataIntegrityViolationCodes); Index: sql-error-codes.xml =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/sql-error-codes.xml,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** sql-error-codes.xml 16 Oct 2008 19:17:16 -0000 1.32 --- sql-error-codes.xml 17 Mar 2009 15:12:21 -0000 1.33 *************** *** 22,27 **** <value>-007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>-407,-530,-531,-532,-543,-544,-545,-603,-667,-803</value> </property> <property name="dataAccessResourceFailureCodes"> --- 22,30 ---- <value>-007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491</value> </property> + <property name="duplicateKeyCodes"> + <value>-803</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>-407,-530,-531,-532,-543,-544,-545,-603,-667</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 46,51 **** <value>42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>22001,22005,23502,23503,23505,23513,X0Y32</value> </property> <property name="dataAccessResourceFailureCodes"> --- 49,57 ---- <value>42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08</value> </property> + <property name="duplicateKeyCodes"> + <value>23505</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>22001,22005,23502,23503,23513,X0Y32</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 64,69 **** <value>42000,42001,42101,42102,42111,42112,42121,42122,42132</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>22003,22012,22025,23000,23001</value> </property> <property name="dataAccessResourceFailureCodes"> --- 70,78 ---- <value>42000,42001,42101,42102,42111,42112,42121,42122,42132</value> </property> + <property name="duplicateKeyCodes"> + <value>23001</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>22003,22012,22025,23000</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 79,82 **** --- 88,94 ---- <value>-22,-28</value> </property> + <property name="duplicateKeyCodes"> + <value>-104</value> + </property> <property name="dataIntegrityViolationCodes"> <value>-9</value> *************** *** 94,99 **** <value>-201,-217,-696</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>-239,-268,-692,-11030</value> </property> </bean> --- 106,114 ---- <value>-201,-217,-696</value> </property> + <property name="duplicateKeyCodes"> + <value>-239,-268,-6017</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>-692,-11030</value> </property> </bean> *************** *** 109,114 **** <value>229</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>544,2601,2627,8114,8115</value> </property> <property name="cannotAcquireLockCodes"> --- 124,132 ---- <value>229</value> </property> + <property name="duplicateKeyCodes"> + <value>2601,2627</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>544,8114,8115</value> </property> <property name="cannotAcquireLockCodes"> *************** *** 124,129 **** <value>1054,1064,1146</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>630,839,840,893,1062,1169,1215,1216,1217,1451,1452,1557</value> </property> <property name="dataAccessResourceFailureCodes"> --- 142,150 ---- <value>1054,1064,1146</value> </property> + <property name="duplicateKeyCodes"> + <value>1062</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>630,839,840,893,1169,1215,1216,1217,1451,1452,1557</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 145,150 **** <value>17003</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>1,1400,1722,2291,2292</value> </property> <property name="dataAccessResourceFailureCodes"> --- 166,174 ---- <value>17003</value> </property> + <property name="duplicateKeyCodes"> + <value>1</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>1400,1722,2291,2292</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 169,174 **** <value>03000,42000,42601,42602,42622,42804,42P01</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>23000,23502,23503,23505,23514</value> </property> <property name="dataAccessResourceFailureCodes"> --- 193,201 ---- <value>03000,42000,42601,42602,42622,42804,42P01</value> </property> + <property name="duplicateKeyCodes"> + <value>23505</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>23000,23502,23503,23514</value> </property> <property name="dataAccessResourceFailureCodes"> *************** *** 197,202 **** <value>101,102,103,104,105,106,107,108,109,110,111,112,113,116,120,121,123,207,208,213,257,512</value> </property> <property name="dataIntegrityViolationCodes"> ! <value>233,423,511,515,530,547,2601,2615,2714</value> </property> <property name="transientDataAccessResourceCodes"> --- 224,232 ---- <value>101,102,103,104,105,106,107,108,109,110,111,112,113,116,120,121,123,207,208,213,257,512</value> </property> + <property name="duplicateKeyCodes"> + <value>2601</value> + </property> <property name="dataIntegrityViolationCodes"> ! <value>233,423,511,515,530,547,2615,2714</value> </property> <property name="transientDataAccessResourceCodes"> Index: SQLErrorCodeSQLExceptionTranslator.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** SQLErrorCodeSQLExceptionTranslator.java 16 Oct 2008 19:17:16 -0000 1.32 --- SQLErrorCodeSQLExceptionTranslator.java 17 Mar 2009 15:12:21 -0000 1.33 *************** *** 33,36 **** --- 33,37 ---- import org.springframework.dao.PermissionDeniedDataAccessException; import org.springframework.dao.TransientDataAccessResourceException; + import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.InvalidResultSetAccessException; *************** *** 228,231 **** --- 229,236 ---- return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx); } + else if (Arrays.binarySearch(this.sqlErrorCodes.getDuplicateKeyCodes(), errorCode) >= 0) { + logTranslation(task, sql, sqlEx, false); + return new DuplicateKeyException(buildMessage(task, sql, sqlEx), sqlEx); + } else if (Arrays.binarySearch(this.sqlErrorCodes.getPermissionDeniedCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); |