This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 8df024f9473 Simplify exception firebird (#40312)
8df024f9473 is described below
commit 8df024f94734d2363ccb7bc4bcaef4a465606d96
Author: Maxim Igoshin <[email protected]>
AuthorDate: Thu Oct 22 12:57:35 2026 +0300
Simplify exception firebird (#40312)
* Remove redundant cast in Firebird dialect SQL parsing exception mapping
* Parameterize Firebird dialect exception mapper test
* Add release note for Firebird exception mapping simplification
* Add PR link to Firebird exception mapping release note
* Retrigger CI
---------
Co-authored-by: Liang Zhang <[email protected]>
---
RELEASE-NOTES.md | 1 +
.../mapper/FirebirdDialectExceptionMapper.java | 3 +-
.../mapper/FirebirdDialectExceptionMapperTest.java | 144 ++++++---------------
3 files changed, 39 insertions(+), 109 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index f84e5fc695f..ed9471429bb 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -192,6 +192,7 @@
1. Sharding: Fix HASH_MOD routing mismatch for same negative numeric values
across numeric Java types with compatibility switch
`normalize-numeric-int-range` -
[#38327](https://github.com/apache/shardingsphere/pull/38327)
1. SQL Parser: Support parsing SYSTEM_USER in SQL92 dialect and bind it as a
niladic function instead of a column -
[#39102](https://github.com/apache/shardingsphere/pull/39102)
1. E2E: Add Firebird to SQL E2E tests through ShardingSphere-Proxy
+1. Proxy: Simplify SQL dialect exception mapping in Firebird -
[#40312](https://github.com/apache/shardingsphere/pull/40312)
1. Proxy: Simplify protocol codec and packets in Firebird -
[#40314](https://github.com/apache/shardingsphere/pull/40314)
1. SQL Parser: Simplify SQL statement visitors in Firebird -
[#40315](https://github.com/apache/shardingsphere/pull/40315)
diff --git
a/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapper.java
b/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapper.java
index 4854d59a53b..c8d1b59b76e 100644
---
a/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapper.java
+++
b/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapper.java
@@ -93,8 +93,7 @@ public final class FirebirdDialectExceptionMapper implements
SQLDialectException
return toSQLException(FirebirdVendorError.EXCESS_TRANSACTIONS,
((ExcessTransactionsException) sqlDialectException).getMaxTransactions());
}
if (sqlDialectException instanceof DialectSQLParsingException) {
- DialectSQLParsingException ex = (DialectSQLParsingException)
sqlDialectException;
- return toSQLException(FirebirdVendorError.DYNAMIC_SQL_ERROR,
ex.getMessage());
+ return toSQLException(FirebirdVendorError.DYNAMIC_SQL_ERROR,
sqlDialectException.getMessage());
}
if (sqlDialectException instanceof TableExistsException) {
return toSQLException(FirebirdVendorError.TABLE_ALREADY_EXISTS,
((TableExistsException) sqlDialectException).getTableName());
diff --git
a/database/exception/dialect/firebird/src/test/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapperTest.java
b/database/exception/dialect/firebird/src/test/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapperTest.java
index f94379c3fa2..1899e32723f 100644
---
a/database/exception/dialect/firebird/src/test/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapperTest.java
+++
b/database/exception/dialect/firebird/src/test/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapperTest.java
@@ -45,8 +45,12 @@ import
org.apache.shardingsphere.database.exception.firebird.vendor.FirebirdVend
import
org.apache.shardingsphere.infra.exception.external.sql.vendor.VendorError;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
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 java.sql.SQLException;
+import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@ -58,116 +62,42 @@ class FirebirdDialectExceptionMapperTest {
private final SQLDialectExceptionMapper mapper =
DatabaseTypedSPILoader.getService(SQLDialectExceptionMapper.class,
databaseType);
- @Test
- void assertConvertWithUnknownDatabase() {
- assertSQLException(mapper.convert(new
UnknownDatabaseException("logic_db")),
FirebirdVendorError.UNAVAILABLE_DATABASE, "logic_db");
- }
-
- @Test
- void assertConvertWithDatabaseCreateExists() {
- assertSQLException(mapper.convert(new
DatabaseCreateExistsException("logic_db")),
FirebirdVendorError.DATABASE_ALREADY_EXISTS, "logic_db");
- }
-
- @Test
- void assertConvertWithDatabaseDropNotExists() {
- assertSQLException(mapper.convert(new
DatabaseDropNotExistsException("logic_db")),
FirebirdVendorError.UNAVAILABLE_DATABASE, "logic_db");
- }
-
- @Test
- void assertConvertWithAccessDenied() {
- assertSQLException(mapper.convert(new AccessDeniedException("root",
"127.0.0.1", true)), FirebirdVendorError.LOGIN_FAILED);
- }
-
- @Test
- void assertConvertWithBatchTooBig() {
- assertSQLException(mapper.convert(new BatchTooBigException(42, 1L, 8L,
8L)), FirebirdVendorError.BATCH_TOO_BIG);
- }
-
- @Test
- void assertConvertWithTableExists() {
- assertSQLException(mapper.convert(new
TableExistsException("t_order")), FirebirdVendorError.TABLE_ALREADY_EXISTS,
"t_order");
- }
-
- @Test
- void assertConvertWithDialectSQLParsing() {
- assertSQLException(mapper.convert(new DialectSQLParsingException("You
have an error in your SQL syntax", "SELEC", 1)),
FirebirdVendorError.DYNAMIC_SQL_ERROR,
- "You have an error in your SQL syntax");
- }
-
- @Test
- void assertConvertWithInvalidBatchHandle() {
- assertSQLException(mapper.convert(new
InvalidBatchHandleException(42)), FirebirdVendorError.INVALID_BATCH_HANDLE);
- }
-
- @Test
- void assertConvertWithBatchAlreadyOpened() {
- assertSQLException(mapper.convert(new
BatchAlreadyOpenedException(42)), FirebirdVendorError.BATCH_ALREADY_OPENED);
- }
-
- @Test
- void assertConvertWithInvalidBatchParameterVersion() {
- assertSQLException(mapper.convert(new
InvalidBatchParameterVersionException(2, 1)),
FirebirdVendorError.INVALID_BATCH_PARAMETER_VERSION, 2, 1);
- }
-
- @Test
- void assertConvertWithBatchParametersRequired() {
- assertSQLException(mapper.convert(new
BatchParametersRequiredException(42)),
FirebirdVendorError.BATCH_PARAMETERS_REQUIRED);
- }
-
- @Test
- void assertConvertWithInvalidBatchMessageFormat() {
- assertSQLException(mapper.convert(new
InvalidBatchMessageFormatException("invalid message length")),
FirebirdVendorError.SQLDA_ERROR);
- }
-
- @Test
- void assertConvertWithInvalidStatementHandle() {
- assertSQLException(mapper.convert(new
InvalidStatementHandleException(42)),
FirebirdVendorError.INVALID_STATEMENT_HANDLE);
- }
-
- @Test
- void assertConvertWithInvalidTransactionHandle() {
- assertSQLException(mapper.convert(new
InvalidTransactionHandleException(42)),
FirebirdVendorError.INVALID_TRANSACTION_HANDLE);
- }
-
- @Test
- void assertConvertWithExcessTransactions() {
- assertSQLException(mapper.convert(new ExcessTransactionsException(1)),
FirebirdVendorError.EXCESS_TRANSACTIONS, 1);
- }
-
- @Test
- void assertConvertWithInvalidParameterValue() {
- assertSQLException(mapper.convert(new
InvalidParameterValueException("names", "foo_charset")),
FirebirdVendorError.CHARSET_NOT_FOUND, "foo_charset");
- }
-
- @Test
- void assertConvertWithInvalidSegstrHandle() {
- assertSQLException(mapper.convert(new
InvalidSegstrHandleException(42)), FirebirdVendorError.INVALID_SEGSTR_HANDLE);
- }
-
- @Test
- void assertConvertWithInvalidSegstrId() {
- assertSQLException(mapper.convert(new InvalidSegstrIdException(99L)),
FirebirdVendorError.INVALID_SEGSTR_ID);
- }
-
- @Test
- void assertConvertWithInvalidSegstrType() {
- assertSQLException(mapper.convert(new InvalidSegstrTypeException(42)),
FirebirdVendorError.INVALID_SEGSTR_TYPE);
- }
-
- @Test
- void assertConvertWithCannotUpdateOldBlob() {
- assertSQLException(mapper.convert(new
CannotUpdateOldBlobException(42)), FirebirdVendorError.CANNOT_UPDATE_OLD_BLOB);
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("convertArguments")
+ void assertConvert(final String name, final SQLDialectException
sqlDialectException, final VendorError vendorError, final Object[] messageArgs)
{
+ SQLException actual = mapper.convert(sqlDialectException);
+ assertThat(actual.getSQLState(),
is(vendorError.getSqlState().getValue()));
+ assertThat(actual.getErrorCode(), is(vendorError.getVendorCode()));
+ assertThat(actual.getMessage(),
is(String.format(vendorError.getReason(), messageArgs)));
}
@Test
void assertConvertWithUnknownException() {
- SQLException actual = mapper.convert(mock(SQLDialectException.class));
- assertThat(actual.getSQLState(), is("HY000"));
- }
-
- private void assertSQLException(final SQLException actual, final
VendorError vendorError, final Object... messageArgs) {
- assertThat(actual.getSQLState(),
is(vendorError.getSqlState().getValue()));
- assertThat(actual.getErrorCode(), is(vendorError.getVendorCode()));
- assertThat(actual.getMessage(),
is(String.format(vendorError.getReason(), messageArgs)));
+
assertThat(mapper.convert(mock(SQLDialectException.class)).getSQLState(),
is("HY000"));
+ }
+
+ private static Stream<Arguments> convertArguments() {
+ return Stream.of(
+ Arguments.of("unknown_database", new
UnknownDatabaseException("logic_db"), FirebirdVendorError.UNAVAILABLE_DATABASE,
new Object[]{"logic_db"}),
+ Arguments.of("database_create_exists", new
DatabaseCreateExistsException("logic_db"),
FirebirdVendorError.DATABASE_ALREADY_EXISTS, new Object[]{"logic_db"}),
+ Arguments.of("database_drop_not_exists", new
DatabaseDropNotExistsException("logic_db"),
FirebirdVendorError.UNAVAILABLE_DATABASE, new Object[]{"logic_db"}),
+ Arguments.of("access_denied", new
AccessDeniedException("root", "127.0.0.1", true),
FirebirdVendorError.LOGIN_FAILED, new Object[0]),
+ Arguments.of("batch_too_big", new BatchTooBigException(42, 1L,
8L, 8L), FirebirdVendorError.BATCH_TOO_BIG, new Object[0]),
+ Arguments.of("table_exists", new
TableExistsException("t_order"), FirebirdVendorError.TABLE_ALREADY_EXISTS, new
Object[]{"t_order"}),
+ Arguments.of("dialect_sql_parsing", new
DialectSQLParsingException("You have an error in your SQL syntax", "SELEC", 1),
FirebirdVendorError.DYNAMIC_SQL_ERROR,
+ new Object[]{"You have an error in your SQL syntax"}),
+ Arguments.of("invalid_batch_handle", new
InvalidBatchHandleException(42), FirebirdVendorError.INVALID_BATCH_HANDLE, new
Object[0]),
+ Arguments.of("batch_already_opened", new
BatchAlreadyOpenedException(42), FirebirdVendorError.BATCH_ALREADY_OPENED, new
Object[0]),
+ Arguments.of("invalid_batch_parameter_version", new
InvalidBatchParameterVersionException(2, 1),
FirebirdVendorError.INVALID_BATCH_PARAMETER_VERSION, new Object[]{2, 1}),
+ Arguments.of("batch_parameters_required", new
BatchParametersRequiredException(42),
FirebirdVendorError.BATCH_PARAMETERS_REQUIRED, new Object[0]),
+ Arguments.of("invalid_batch_message_format", new
InvalidBatchMessageFormatException("invalid message length"),
FirebirdVendorError.SQLDA_ERROR, new Object[0]),
+ Arguments.of("invalid_statement_handle", new
InvalidStatementHandleException(42),
FirebirdVendorError.INVALID_STATEMENT_HANDLE, new Object[0]),
+ Arguments.of("invalid_transaction_handle", new
InvalidTransactionHandleException(42),
FirebirdVendorError.INVALID_TRANSACTION_HANDLE, new Object[0]),
+ Arguments.of("excess_transactions", new
ExcessTransactionsException(1), FirebirdVendorError.EXCESS_TRANSACTIONS, new
Object[]{1}),
+ Arguments.of("invalid_parameter_value", new
InvalidParameterValueException("names", "foo_charset"),
FirebirdVendorError.CHARSET_NOT_FOUND, new Object[]{"foo_charset"}),
+ Arguments.of("invalid_segstr_handle", new
InvalidSegstrHandleException(42), FirebirdVendorError.INVALID_SEGSTR_HANDLE,
new Object[0]),
+ Arguments.of("invalid_segstr_id", new
InvalidSegstrIdException(99L), FirebirdVendorError.INVALID_SEGSTR_ID, new
Object[0]),
+ Arguments.of("invalid_segstr_type", new
InvalidSegstrTypeException(42), FirebirdVendorError.INVALID_SEGSTR_TYPE, new
Object[0]),
+ Arguments.of("cannot_update_old_blob", new
CannotUpdateOldBlobException(42), FirebirdVendorError.CANNOT_UPDATE_OLD_BLOB,
new Object[0]));
}
}