diff --git a/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml b/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml index dd3b4b0b55e..50a5167aedd 100644 --- a/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml +++ b/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml @@ -121,7 +121,7 @@ Microsoft SQL Server - 156,170,207,208 + 156,170,207,208,209 229 diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodesFactoryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodesFactoryTests.java index 5049da9025b..6062ab5eb8a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodesFactoryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodesFactoryTests.java @@ -24,11 +24,14 @@ import java.util.Arrays; import javax.sql.DataSource; import junit.framework.TestCase; -import org.easymock.MockControl; +import org.easymock.MockControl; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + /** * Tests for SQLErrorCodes loading. * @@ -64,6 +67,40 @@ public class SQLErrorCodesFactoryTests extends TestCase { assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0); } + private void assertIsSQLServer(SQLErrorCodes sec) { + assertThat(sec.getDatabaseProductName(), equalTo("Microsoft SQL Server")); + + assertTrue(sec.getBadSqlGrammarCodes().length > 0); + + assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "156") >= 0); + assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "170") >= 0); + assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "207") >= 0); + assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "208") >= 0); + assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "209") >= 0); + assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0); + + assertTrue(sec.getPermissionDeniedCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "229") >= 0); + + assertTrue(sec.getDuplicateKeyCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2601") >= 0); + assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2627") >= 0); + + assertTrue(sec.getDataIntegrityViolationCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "544") >= 0); + assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8114") >= 0); + assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8115") >= 0); + + assertTrue(sec.getDataAccessResourceFailureCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "4060") >= 0); + + assertTrue(sec.getCannotAcquireLockCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "1222") >= 0); + + assertTrue(sec.getDeadlockLoserCodes().length > 0); + assertTrue(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "1205") >= 0); + } + private void assertIsHsql(SQLErrorCodes sec) { assertTrue(sec.getBadSqlGrammarCodes().length > 0); assertTrue(sec.getDataIntegrityViolationCodes().length > 0); @@ -252,6 +289,11 @@ public class SQLErrorCodesFactoryTests extends TestCase { return sec; } + public void testSQLServerRecognizedFromMetadata() throws Exception { + SQLErrorCodes sec = getErrorCodesFromDataSource("MS-SQL", null); + assertIsSQLServer(sec); + } + public void testOracleRecognizedFromMetadata() throws Exception { SQLErrorCodes sec = getErrorCodesFromDataSource("Oracle", null); assertIsOracle(sec);