This is an automated email from the ASF dual-hosted git repository.
panjuan 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 2f0b4b627f7 Reuse SQLWrapperException (#20416)
2f0b4b627f7 is described below
commit 2f0b4b627f7649cecacc650aebdc66bccb47dcea
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 22 20:44:34 2022 +0800
Reuse SQLWrapperException (#20416)
---
.../shardingsphere/infra/database/type/DatabaseTypeEngine.java | 4 ++--
.../infra/database/type/DatabaseTypeEngineTest.java | 4 ++--
.../executor/advanced/table/TranslatableTableScanExecutor.java | 8 ++++----
.../infra/federation/executor/common/row/CommonRowEnumerator.java | 4 ++--
.../executor/original/table/FilterableTableScanExecutor.java | 8 ++++----
.../infra/util/exception/sql/ShardingSphereSQLException.java | 2 +-
.../jdbc/core/statement/ShardingSpherePreparedStatement.java | 3 ++-
.../driver/jdbc/core/statement/ShardingSphereStatement.java | 3 ++-
.../distsql/ral/updatable/ImportDatabaseConfigurationHandler.java | 5 +++--
9 files changed, 22 insertions(+), 19 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
index e1301706ecf..66b66ee5099 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
@@ -23,7 +23,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -110,7 +110,7 @@ public final class DatabaseTypeEngine {
try (Connection connection = dataSource.getConnection()) {
return getDatabaseType(connection.getMetaData().getURL());
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex.getMessage(), ex);
+ throw new SQLWrapperException(ex);
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
index 9519f82605d..696f33e6cf4 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
@@ -24,8 +24,8 @@ import
org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import
org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;
@@ -87,7 +87,7 @@ public final class DatabaseTypeEngineTest {
DatabaseTypeEngine.getDatabaseType(dataSources);
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected = SQLWrapperException.class)
public void assertGetDatabaseTypeWhenGetConnectionError() throws
SQLException {
DataSource dataSource = mock(DataSource.class);
when(dataSource.getConnection()).thenThrow(SQLException.class);
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/table/TranslatableTableScanExecutor.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/table/TranslatableTableScanExecutor.java
index 938db637738..3db55b4f04a 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/table/TranslatableTableScanExecutor.java
+++
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/table/TranslatableTableScanExecutor.java
@@ -47,7 +47,6 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
import
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
@@ -62,14 +61,14 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.dr
import
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine;
import
org.apache.shardingsphere.infra.executor.sql.process.ExecuteProcessEngine;
import org.apache.shardingsphere.infra.federation.executor.FederationContext;
-import
org.apache.shardingsphere.infra.federation.executor.common.row.EmptyRowEnumerator;
import
org.apache.shardingsphere.infra.federation.executor.common.row.CommonRowEnumerator;
+import
org.apache.shardingsphere.infra.federation.executor.common.row.EmptyRowEnumerator;
import
org.apache.shardingsphere.infra.federation.executor.common.table.CommonTableScanExecutorContext;
import
org.apache.shardingsphere.infra.federation.executor.original.SQLDialectFactory;
import
org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import
org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory;
-import
org.apache.shardingsphere.infra.federation.optimizer.executor.TableScanExecutor;
import
org.apache.shardingsphere.infra.federation.optimizer.executor.ScanNodeExecutorContext;
+import
org.apache.shardingsphere.infra.federation.optimizer.executor.TableScanExecutor;
import
org.apache.shardingsphere.infra.federation.optimizer.executor.TranslatableScanNodeExecutorContext;
import
org.apache.shardingsphere.infra.federation.optimizer.metadata.filter.FilterableSchema;
import
org.apache.shardingsphere.infra.federation.optimizer.planner.QueryOptimizePlannerFactory;
@@ -82,6 +81,7 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
import org.apache.shardingsphere.infra.session.ConnectionContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.sql.Connection;
@@ -146,7 +146,7 @@ public final class TranslatableTableScanExecutor implements
TableScanExecutor {
Collection<Statement> statements =
getStatements(executionGroupContext.getInputGroups());
return createEnumerable(mergedResult,
queryResults.get(0).getMetaData(), statements);
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
+ throw new SQLWrapperException(ex);
} finally {
ExecuteProcessEngine.clean();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/common/row/CommonRowEnumerator.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/common/row/CommonRowEnumerator.java
index b0cf4b47f09..fec58878c0e 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/common/row/CommonRowEnumerator.java
+++
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/common/row/CommonRowEnumerator.java
@@ -19,9 +19,9 @@ package
org.apache.shardingsphere.infra.federation.executor.common.row;
import lombok.RequiredArgsConstructor;
import org.apache.calcite.linq4j.Enumerator;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import java.sql.SQLException;
import java.sql.Statement;
@@ -82,7 +82,7 @@ public final class CommonRowEnumerator implements
Enumerator<Object[]> {
}
currentRow = null;
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
+ throw new SQLWrapperException(ex);
}
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java
index b7b3987dc28..a81f786c0cb 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java
+++
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java
@@ -41,7 +41,6 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
import
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
@@ -56,10 +55,10 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.dr
import
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine;
import
org.apache.shardingsphere.infra.executor.sql.process.ExecuteProcessEngine;
import org.apache.shardingsphere.infra.federation.executor.FederationContext;
+import
org.apache.shardingsphere.infra.federation.executor.common.row.CommonRowEnumerator;
+import
org.apache.shardingsphere.infra.federation.executor.common.row.EmptyRowEnumerator;
import
org.apache.shardingsphere.infra.federation.executor.common.table.CommonTableScanExecutorContext;
import
org.apache.shardingsphere.infra.federation.executor.original.SQLDialectFactory;
-import
org.apache.shardingsphere.infra.federation.executor.common.row.EmptyRowEnumerator;
-import
org.apache.shardingsphere.infra.federation.executor.common.row.CommonRowEnumerator;
import
org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import
org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory;
import
org.apache.shardingsphere.infra.federation.optimizer.executor.FilterableScanNodeExecutorContext;
@@ -76,6 +75,7 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
import org.apache.shardingsphere.infra.session.ConnectionContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.sql.Connection;
@@ -141,7 +141,7 @@ public final class FilterableTableScanExecutor implements
TableScanExecutor {
Collection<Statement> statements =
getStatements(executionGroupContext.getInputGroups());
return createEnumerable(mergedResult,
queryResults.get(0).getMetaData(), statements);
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
+ throw new SQLWrapperException(ex);
} finally {
ExecuteProcessEngine.clean();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
index 65e0ffeb6df..8db1d216401 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
@@ -43,7 +43,7 @@ public abstract class ShardingSphereSQLException extends
ShardingSphereInsideExc
public ShardingSphereSQLException(final String sqlState, final int
vendorCode, final String reason, final String... messageArguments) {
this.sqlState = sqlState;
this.vendorCode = vendorCode;
- this.reason = String.format(reason, messageArguments);
+ this.reason = null == reason ? null : String.format(reason,
messageArguments);
}
/**
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index ce7124b87db..58860aa0597 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -79,6 +79,7 @@ import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRul
import org.apache.shardingsphere.infra.rule.identifier.type.RawExecutionRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.StorageConnectorReusableRule;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -463,7 +464,7 @@ public final class ShardingSpherePreparedStatement extends
AbstractPreparedState
try {
return statement.getResultSet();
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
+ throw new SQLWrapperException(ex);
}
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 5a9dca1c695..510eaab9a9a 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -73,6 +73,7 @@ import
org.apache.shardingsphere.infra.route.context.RouteUnit;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.RawExecutionRule;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -554,7 +555,7 @@ public final class ShardingSphereStatement extends
AbstractStatementAdapter {
try {
return statement.getResultSet();
} catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
+ throw new SQLWrapperException(ex);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
index 6ac09c10128..535cc72921f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
@@ -34,8 +34,9 @@ import
org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import
org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
@@ -118,7 +119,7 @@ public final class ImportDatabaseConfigurationHandler
extends UpdatableRALBacken
try {
ProxyContext.getInstance().getContextManager().addDatabase(databaseName);
} catch (SQLException ex) {
- throw new ShardingSphereException(ex.getMessage());
+ throw new SQLWrapperException(ex);
}
}