SQLErrorCodeSQLExceptionTranslator tries to find SQLException with actual error code, looping through the causes.

Issue: SPR-10260
This commit is contained in:
Juergen Hoeller
2013-02-06 21:32:42 +01:00
parent 188a11bdb9
commit 8a4ce142c4
2 changed files with 30 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,9 @@
package org.springframework.jdbc.support;
import java.sql.SQLException;
import java.sql.BatchUpdateException;
import java.sql.DataTruncation;
import java.sql.SQLException;
import junit.framework.TestCase;
@@ -33,6 +34,7 @@ import org.springframework.jdbc.InvalidResultSetAccessException;
/**
* @author Rod Johnson
* @author Juergen Hoeller
*/
public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
@@ -92,13 +94,21 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
SQLException badSqlEx = new SQLException("", "", 1);
BatchUpdateException batchUdateEx = new BatchUpdateException();
batchUdateEx.setNextException(badSqlEx);
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", batchUdateEx);
BatchUpdateException batchUpdateEx = new BatchUpdateException();
batchUpdateEx.setNextException(badSqlEx);
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", batchUpdateEx);
assertEquals("SQL", bsgex.getSql());
assertEquals(badSqlEx, bsgex.getSQLException());
}
public void testDataTruncationTranslation() {
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
SQLException dataAccessEx = new SQLException("", "", 5);
DataTruncation dataTruncation = new DataTruncation(1, true, true, 1, 1, dataAccessEx);
DataAccessResourceFailureException daex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataTruncation);
assertEquals(dataTruncation, daex.getCause());
}
@SuppressWarnings("serial")
public void testCustomTranslateMethodTranslation() {