Add error code for SAP Hana

This commit adds a SQLErrorCodes instance for SAP DB, based on a
contribution from Andrew Clemons

Mostly based on SAP Hana SPS 07 with a few additional codes that are
only present is previous versions:

* -813 - Cannot connect to host somehost:30115 [Connection refused]
* -709 - Unknown host somehost:30115 [somehost], -709.]
* -708 - Cannot connect to jdbc:sap://somehost:30115 [Receive of connect failed.]
* -11210 - Invalid column index XYZ.

Issue: SPR-11770
This commit is contained in:
Stephane Nicoll 2014-05-09 14:25:26 +02:00
parent 0d22719e06
commit 8614df8bd4
2 changed files with 64 additions and 1 deletions

View File

@ -248,4 +248,44 @@
</property>
</bean>
<!-- http://help.sap.com/saphelp_hanaplatform/helpdata/en/20/a78d3275191014b41bae7c4a46d835/content.htm -->
<bean id="Hana" class="org.springframework.jdbc.support.SQLErrorCodes">
<property name="databaseProductName">
<value>SAP DB</value>
</property>
<property name="badSqlGrammarCodes">
<value>
257,259,260,261,262,263,264,267,268,269,270,271,272,273,275,276,277,278,
278,279,280,281,282,283,284,285,286,288,289,290,294,295,296,297,299,308,309,
313,315,316,318,319,320,321,322,323,324,328,329,330,333,335,336,337,338,340,
343,350,351,352,362,368
</value>
</property>
<property name="permissionDeniedCodes">
<value>10,258</value>
</property>
<property name="duplicateKeyCodes">
<value>301</value>
</property>
<property name="dataIntegrityViolationCodes">
<value>461,462</value>
</property>
<property name="dataAccessResourceFailureCodes">
<value>-813,-709,-708,1024,1025,1026,1027,1029,1030,1031</value>
</property>
<property name="invalidResultSetAccessCodes">
<value>-11210,582,587,588,594</value>
</property>
<property name="cannotAcquireLockCodes">
<value>131</value>
</property>
<property name="cannotSerializeTransactionCodes">
<value>138,143</value>
</property>
<property name="deadlockLoserCodes">
<value>133</value>
</property>
</bean>
</beans>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -36,6 +36,7 @@ import static org.mockito.BDDMockito.*;
*
* @author Rod Johnson
* @author Thomas Risberg
* @author Stephane Nicoll
*/
public class SQLErrorCodesFactoryTests {
@ -120,6 +121,22 @@ public class SQLErrorCodesFactoryTests {
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-204") >= 0);
}
private void assertIsHana(SQLErrorCodes sec) {
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "368") >= 0);
assertTrue(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "10") >= 0);
assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "301") >= 0);
assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "461") >= 0);
assertTrue(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "-813") >=0);
assertTrue(Arrays.binarySearch(sec.getInvalidResultSetAccessCodes(), "582") >=0);
assertTrue(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "131") >= 0);
assertTrue(Arrays.binarySearch(sec.getCannotSerializeTransactionCodes(), "138") >= 0);
assertTrue(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "133") >= 0);
}
@Test
public void testLookupOrder() {
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
@ -297,6 +314,12 @@ public class SQLErrorCodesFactoryTests {
assertIsEmpty(sec);
}
@Test
public void testHanaIsRecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("SAP DB", null);
assertIsHana(sec);
}
/**
* Check that wild card database name works.
*/