Browse Source

Polish contribution

See gh-31554
pull/31571/head
Sam Brannen 11 months ago
parent
commit
c5bcfc7682
  1. 10
      spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java
  2. 2
      spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java

10
spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java

@ -90,8 +90,8 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException @@ -90,8 +90,8 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
);
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
@ -163,12 +163,12 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException @@ -163,12 +163,12 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
/**
* 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 {@link DuplicateKeyException}:
* either SQL state 23505 as a specific indication, or the generic SQL state
* 23000 with well-known vendor codes.
* 23000 with a well-known vendor code.
* @param sqlState the SQL state value
* @param errorCode the error code value
* @param errorCode the error code
*/
static boolean indicatesDuplicateKey(@Nullable String sqlState, int errorCode) {
return ("23505".equals(sqlState) ||

2
spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java

@ -84,7 +84,7 @@ class SQLStateSQLExceptionTranslatorTests { @@ -84,7 +84,7 @@ class SQLStateSQLExceptionTranslatorTests {
assertTranslation("23000", 2627, DuplicateKeyException.class);
}
@Test
@Test // gh-31554
void translateDuplicateKeySapHana() {
assertTranslation("23000", 301, DuplicateKeyException.class);
}

Loading…
Cancel
Save