Polish duplicate key exception error code support for SAP HANA database for R2DBC

See gh-31554
This commit is contained in:
Sam Brannen 2023-11-07 16:53:25 +01:00
parent c5bcfc7682
commit e778d2e908
2 changed files with 10 additions and 8 deletions

View File

@ -73,7 +73,7 @@ public abstract class ConnectionFactoryUtils {
private static final Set<Integer> DUPLICATE_KEY_ERROR_CODES = Set.of( private static final Set<Integer> DUPLICATE_KEY_ERROR_CODES = Set.of(
1, // Oracle 1, // Oracle
301, // Sap Hana 301, // SAP HANA
1062, // MySQL/MariaDB 1062, // MySQL/MariaDB
2601, // MS SQL Server 2601, // MS SQL Server
2627 // MS SQL Server 2627 // MS SQL Server
@ -257,11 +257,13 @@ public abstract class ConnectionFactoryUtils {
} }
/** /**
* Check whether the given SQL state (and the associated error code in case * Check whether the given SQL state and the associated error code (in case
* of a generic SQL state value) indicate a duplicate key exception. See * of a generic SQL state value) indicate a duplicate key exception:
* {@code org.springframework.jdbc.support.SQLStateSQLExceptionTranslator#indicatesDuplicateKey}. * either SQL state 23505 as a specific indication, or the generic SQL state
* 23000 with a well-known vendor code.
* @param sqlState the SQL state value * @param sqlState the SQL state value
* @param errorCode the error code value * @param errorCode the error code
* @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator#indicatesDuplicateKey
*/ */
static boolean indicatesDuplicateKey(@Nullable String sqlState, int errorCode) { static boolean indicatesDuplicateKey(@Nullable String sqlState, int errorCode) {
return ("23505".equals(sqlState) || return ("23505".equals(sqlState) ||

View File

@ -102,7 +102,7 @@ class ConnectionFactoryUtilsUnitTests {
exception = ConnectionFactoryUtils.convertR2dbcException("", "", exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 301)); new R2dbcDataIntegrityViolationException("reason", "23000", 301));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class); assertThat(exception).as("SAP HANA").isExactlyInstanceOf(DuplicateKeyException.class);
exception = ConnectionFactoryUtils.convertR2dbcException("", "", exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1062)); new R2dbcDataIntegrityViolationException("reason", "23000", 1062));