Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
301, // SAP HANA
1062, // MySQL/MariaDB
2601, // MS SQL Server
2627 // MS SQL Server
2627, // MS SQL Server
-239, // Informix
-268 // Informix
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ void translateDuplicateKeySapHana() {
assertTranslation("23000", 301, DuplicateKeyException.class);
}

@Test
void translateDuplicateKeyInformix1() {
assertTranslation("23000", -239, DuplicateKeyException.class);
}

@Test
void translateDuplicateKeyInformix2() {
assertTranslation("23000", -268, DuplicateKeyException.class);
}

@Test
void translateDataAccessResourceFailure() {
assertTranslation("53", DataAccessResourceFailureException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public abstract class ConnectionFactoryUtils {
301, // SAP HANA
1062, // MySQL/MariaDB
2601, // MS SQL Server
2627 // MS SQL Server
2627, // MS SQL Server
-239, // Informix
-268 // Informix
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import io.r2dbc.spi.R2dbcTimeoutException;
import io.r2dbc.spi.R2dbcTransientResourceException;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.DataIntegrityViolationException;
Expand All @@ -37,8 +39,12 @@
import org.springframework.r2dbc.BadSqlGrammarException;
import org.springframework.r2dbc.UncategorizedR2dbcException;

import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;



/**
* Tests for {@link ConnectionFactoryUtils}.
*
Expand Down Expand Up @@ -86,35 +92,32 @@ void shouldTranslateNonTransientResourceException() {
assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class);
}

private static Stream<Arguments> duplicateKeyErrorCodes() {
return Stream.of(
Arguments.of("Oracle", "23505", 0),
Arguments.of("Oracle", "23000", 1),
Arguments.of("SAP HANA", "23000", 301),
Arguments.of("MySQL/MariaDB", "23000", 1062),
Arguments.of("MS SQL Server", "23000", 2601),
Arguments.of("MS SQL Server", "23000", 2627),
Arguments.of("Informix", "23000", -239),
Arguments.of("Informix", "23000", -268)
);
}

@ParameterizedTest
@MethodSource("duplicateKeyErrorCodes")
void shouldTranslateIntegrityViolationException(final String db, String sqlState, final int errorCode) {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", sqlState, errorCode));
assertThat(exception).as(db).isExactlyInstanceOf(DuplicateKeyException.class);
}

@Test
void shouldTranslateIntegrityViolationException() {
void shouldTranslateGenericIntegrityViolationException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException());
assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23505"));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1));
assertThat(exception).as("Oracle").isExactlyInstanceOf(DuplicateKeyException.class);

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

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1062));
assertThat(exception).as("MySQL/MariaDB").isExactlyInstanceOf(DuplicateKeyException.class);

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 2601));
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);

exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 2627));
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);
}

@Test
Expand Down
Loading