Merge branch '6.0.x'
This commit is contained in:
@@ -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
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
@@ -257,11 +257,13 @@ public abstract class ConnectionFactoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) ||
|
||||
|
||||
@@ -45,17 +45,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Mark Paluch
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ConnectionFactoryUtilsUnitTests {
|
||||
class ConnectionFactoryUtilsUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldTranslateTransientResourceException() {
|
||||
void shouldTranslateTransientResourceException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcTransientResourceException(""));
|
||||
assertThat(exception).isExactlyInstanceOf(TransientDataAccessResourceException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslateRollbackException() {
|
||||
void shouldTranslateRollbackException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcRollbackException());
|
||||
assertThat(exception).isExactlyInstanceOf(PessimisticLockingFailureException.class);
|
||||
@@ -66,28 +66,28 @@ public class ConnectionFactoryUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslateTimeoutException() {
|
||||
void shouldTranslateTimeoutException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcTimeoutException());
|
||||
assertThat(exception).isExactlyInstanceOf(QueryTimeoutException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotTranslateUnknownExceptions() {
|
||||
void shouldNotTranslateUnknownExceptions() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new MyTransientException());
|
||||
assertThat(exception).isExactlyInstanceOf(UncategorizedR2dbcException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslateNonTransientResourceException() {
|
||||
void shouldTranslateNonTransientResourceException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcNonTransientResourceException());
|
||||
assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslateIntegrityViolationException() {
|
||||
void shouldTranslateIntegrityViolationException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcDataIntegrityViolationException());
|
||||
assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);
|
||||
@@ -98,41 +98,41 @@ public class ConnectionFactoryUtilsUnitTests {
|
||||
|
||||
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcDataIntegrityViolationException("reason", "23000", 1));
|
||||
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
assertThat(exception).as("Oracle").isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
|
||||
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));
|
||||
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
assertThat(exception).as("MySQL/MariaDB").isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
|
||||
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcDataIntegrityViolationException("reason", "23000", 2601));
|
||||
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
|
||||
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcDataIntegrityViolationException("reason", "23000", 2627));
|
||||
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslatePermissionDeniedException() {
|
||||
void shouldTranslatePermissionDeniedException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcPermissionDeniedException());
|
||||
assertThat(exception).isExactlyInstanceOf(PermissionDeniedDataAccessException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTranslateBadSqlGrammarException() {
|
||||
void shouldTranslateBadSqlGrammarException() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
||||
new R2dbcBadGrammarException());
|
||||
assertThat(exception).isExactlyInstanceOf(BadSqlGrammarException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageGeneration() {
|
||||
void messageGeneration() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK",
|
||||
"SOME-SQL", new R2dbcTransientResourceException("MESSAGE"));
|
||||
assertThat(exception).isExactlyInstanceOf(
|
||||
@@ -140,7 +140,7 @@ public class ConnectionFactoryUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageGenerationNullSQL() {
|
||||
void messageGenerationNullSQL() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK", null,
|
||||
new R2dbcTransientResourceException("MESSAGE"));
|
||||
assertThat(exception).isExactlyInstanceOf(
|
||||
@@ -148,7 +148,7 @@ public class ConnectionFactoryUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageGenerationNullMessage() {
|
||||
void messageGenerationNullMessage() {
|
||||
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK",
|
||||
"SOME-SQL", new R2dbcTransientResourceException());
|
||||
assertThat(exception).isExactlyInstanceOf(
|
||||
|
||||
Reference in New Issue
Block a user