Skip to content

Commit e778d2e

Browse files
committed
Polish duplicate key exception error code support for SAP HANA database for R2DBC
See gh-31554
1 parent c5bcfc7 commit e778d2e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public abstract class ConnectionFactoryUtils {
7272
public static final int CONNECTION_SYNCHRONIZATION_ORDER = 1000;
7373

7474
private static final Set<Integer> DUPLICATE_KEY_ERROR_CODES = Set.of(
75-
1, // Oracle
76-
301, // Sap Hana
75+
1, // Oracle
76+
301, // SAP HANA
7777
1062, // MySQL/MariaDB
7878
2601, // MS SQL Server
7979
2627 // MS SQL Server
80-
);
80+
);
8181

8282

8383
/**
@@ -257,11 +257,13 @@ else if (ex instanceof R2dbcNonTransientException) {
257257
}
258258

259259
/**
260-
* Check whether the given SQL state (and the associated error code in case
261-
* of a generic SQL state value) indicate a duplicate key exception. See
262-
* {@code org.springframework.jdbc.support.SQLStateSQLExceptionTranslator#indicatesDuplicateKey}.
260+
* Check whether the given SQL state and the associated error code (in case
261+
* of a generic SQL state value) indicate a duplicate key exception:
262+
* either SQL state 23505 as a specific indication, or the generic SQL state
263+
* 23000 with a well-known vendor code.
263264
* @param sqlState the SQL state value
264-
* @param errorCode the error code value
265+
* @param errorCode the error code
266+
* @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator#indicatesDuplicateKey
265267
*/
266268
static boolean indicatesDuplicateKey(@Nullable String sqlState, int errorCode) {
267269
return ("23505".equals(sqlState) ||

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void shouldTranslateIntegrityViolationException() {
102102

103103
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
104104
new R2dbcDataIntegrityViolationException("reason", "23000", 301));
105-
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
105+
assertThat(exception).as("SAP HANA").isExactlyInstanceOf(DuplicateKeyException.class);
106106

107107
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
108108
new R2dbcDataIntegrityViolationException("reason", "23000", 1062));

0 commit comments

Comments
 (0)