Skip to content

Commit

Permalink
Polish duplicate key exception error code support for SAP HANA databa…
Browse files Browse the repository at this point in the history
…se for R2DBC

See spring-projectsgh-31554
  • Loading branch information
sbrannen committed Nov 7, 2023
1 parent c5bcfc7 commit e778d2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public abstract class ConnectionFactoryUtils {
public static final int CONNECTION_SYNCHRONIZATION_ORDER = 1000;

private static final Set<Integer> DUPLICATE_KEY_ERROR_CODES = Set.of(
1, // Oracle
301, // Sap Hana
1, // Oracle
301, // SAP HANA
1062, // MySQL/MariaDB
2601, // MS SQL Server
2627 // MS SQL Server
);
);


/**
Expand Down Expand Up @@ -257,11 +257,13 @@ else if (ex instanceof R2dbcNonTransientException) {
}

/**
* 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
* {@code org.springframework.jdbc.support.SQLStateSQLExceptionTranslator#indicatesDuplicateKey}.
* Check whether the given SQL state and the associated error code (in case
* of a generic SQL state value) indicate a duplicate key exception:
* 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 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) {
return ("23505".equals(sqlState) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void shouldTranslateIntegrityViolationException() {

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 301));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
assertThat(exception).as("SAP HANA").isExactlyInstanceOf(DuplicateKeyException.class);

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1062));
Expand Down

0 comments on commit e778d2e

Please sign in to comment.