This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 5492c363d45 Refactor ImportDatabaseConfigurationHandler (#20901)
5492c363d45 is described below
commit 5492c363d45cb443bbcf6765297e15cf53def1c7
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Sep 9 15:41:03 2022 +0800
Refactor ImportDatabaseConfigurationHandler (#20901)
* Refactor ImportDatabaseConfigurationHandler
* Refactor ImportDatabaseConfigurationHandler
---
.../type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java | 2 +-
...NormalReplicationDatabaseDiscoveryProviderAlgorithm.java | 2 +-
.../handler/distsql/ral/UpdatableRALBackendHandler.java | 3 +--
.../ral/updatable/ImportDatabaseConfigurationHandler.java | 13 ++++---------
4 files changed, 7 insertions(+), 13 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
index 2654fc8b83d..b4f62ce012f 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
@@ -88,7 +88,7 @@ public final class MGRMySQLDatabaseDiscoveryProviderAlgorithm
implements Databas
return CompletableFuture.runAsync(() -> {
try {
checkSingleDataSourceEnvironment(databaseName, dataSource);
- } catch (SQLException ex) {
+ } catch (final SQLException ex) {
throw new SQLWrapperException(ex);
}
}, executorService);
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProvi
[...]
index 8149952975a..aaa15b48bae 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
@@ -79,7 +79,7 @@ public final class
MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm impl
return CompletableFuture.supplyAsync(() -> {
try {
return isPrimaryInstance(dataSource);
- } catch (SQLException ex) {
+ } catch (final SQLException ex) {
throw new SQLWrapperException(ex);
}
}, executorService);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java
index 9e84e9a770c..db7aea4b81f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral;
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
-import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -39,5 +38,5 @@ public abstract class UpdatableRALBackendHandler<E extends
RALStatement> extends
return new UpdateResponseHeader(getSqlStatement());
}
- protected abstract void update(ContextManager contextManager) throws
DistSQLException;
+ protected abstract void update(ContextManager contextManager) throws
SQLException;
}
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 ff81ff516ba..d9a46608bca 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
@@ -33,7 +33,6 @@ import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesVali
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.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;
@@ -83,7 +82,7 @@ public final class ImportDatabaseConfigurationHandler extends
UpdatableRALBacken
private final YamlProxyDataSourceConfigurationSwapper
dataSourceConfigSwapper = new YamlProxyDataSourceConfigurationSwapper();
@Override
- protected void update(final ContextManager contextManager) throws
DistSQLException {
+ protected void update(final ContextManager contextManager) throws
SQLException {
File file = new File(getSqlStatement().getFilePath());
YamlProxyDatabaseConfiguration yamlConfig;
try {
@@ -98,7 +97,7 @@ public final class ImportDatabaseConfigurationHandler extends
UpdatableRALBacken
addResources(databaseName, yamlConfig.getDataSources());
try {
addRules(databaseName, yamlConfig.getRules());
- } catch (DistSQLException ex) {
+ } catch (final DistSQLException ex) {
dropDatabase(databaseName);
throw ex;
}
@@ -115,12 +114,8 @@ public final class ImportDatabaseConfigurationHandler
extends UpdatableRALBacken
Preconditions.checkState(!dataSources.isEmpty(), "Data sources
configuration in file `%s` is required.", file.getName());
}
- private void addDatabase(final String databaseName) {
- try {
-
ProxyContext.getInstance().getContextManager().addDatabase(databaseName);
- } catch (SQLException ex) {
- throw new SQLWrapperException(ex);
- }
+ private void addDatabase(final String databaseName) throws SQLException {
+
ProxyContext.getInstance().getContextManager().addDatabase(databaseName);
}
private void dropDatabase(final String databaseName) {