You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/06/25 16:31:30 UTC
[shardingsphere] branch master updated: Add RDLUpdater to decouple
RDLBackendHandler with proxy (#11022)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 d891180 Add RDLUpdater to decouple RDLBackendHandler with proxy (#11022)
d891180 is described below
commit d891180af6ec29c91f4a2c4703e83d8a69dd496b
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jun 26 00:30:51 2021 +0800
Add RDLUpdater to decouple RDLBackendHandler with proxy (#11022)
* Refactor AlterDatabaseDiscoveryRuleBackendHandler
* Refactor RDLBackendHandler
* Add AlterDatabaseDiscoveryRuleStatementUpdater
* Add AlterEncryptRuleStatementUpdater
* Add AlterReadwriteSplittingRuleStatementUpdater
* Add AlterShardingBindingTableRuleStatementUpdater
* Add AlterShardingBroadcastTableRuleStatementUpdater
* Add AlterShardingTableRuleBackendHandler
* Add CreateDatabaseDiscoveryRuleStatementUpdater
* Add CreateDatabaseDiscoveryRuleStatementUpdater
* Add CreateEncryptRuleStatementUpdater
* Add DropEncryptRuleBackendHandler
* Add DropDatabaseDiscoveryRuleStatementUpdater
* Add CreateReadwriteSplittingRuleStatementUpdater
* Add CreateReadwriteSplittingRuleStatementUpdater
* Add CreateReadwriteSplittingRuleStatementUpdater
* Add DropReadwriteSplittingRuleStatementUpdater
* Add CreateShardingBindingTableRuleStatementUpdater
* Add DropShardingBindingTableRuleStatementUpdater
* Add CreateShardingBroadcastTableRuleStatementUpdater
* Add DropShardingBroadcastTableRuleStatementUpdater
* Add CreateShardingTableRuleStatementUpdater
* Add CreateShardingTableRuleStatementUpdater
* Add DropShardingTableRuleStatementUpdater
* Refactor RDLBackendHandler
* For checkstyle
---
.../shardingsphere/infra/distsql/RDLUpdater.java | 51 ++++++++++
.../metadata/resource/ShardingSphereResource.java | 10 ++
.../AlterDatabaseDiscoveryRuleBackendHandler.java | 97 +------------------
.../rdl/impl/AlterEncryptRuleBackendHandler.java | 70 +-------------
.../AlterReadwriteSplittingRuleBackendHandler.java | 86 +----------------
...terShardingBindingTableRulesBackendHandler.java | 61 +-----------
...rShardingBroadcastTableRulesBackendHandler.java | 13 +--
.../impl/AlterShardingTableRuleBackendHandler.java | 107 +--------------------
.../CreateDatabaseDiscoveryRuleBackendHandler.java | 83 +---------------
.../rdl/impl/CreateEncryptRuleBackendHandler.java | 63 +-----------
...CreateReadwriteSplittingRuleBackendHandler.java | 80 +--------------
...ateShardingBindingTableRulesBackendHandler.java | 63 +-----------
...eShardingBroadcastTableRulesBackendHandler.java | 16 +--
.../CreateShardingTableRuleBackendHandler.java | 92 +-----------------
.../DropDatabaseDiscoveryRuleBackendHandler.java | 35 +------
.../rdl/impl/DropEncryptRuleBackendHandler.java | 30 +-----
.../DropReadwriteSplittingRuleBackendHandler.java | 26 +----
...ropShardingBindingTableRulesBackendHandler.java | 9 +-
...pShardingBroadcastTableRulesBackendHandler.java | 9 +-
.../impl/DropShardingTableRuleBackendHandler.java | 53 +---------
.../text/distsql/rdl/impl/RDLBackendHandler.java | 45 +++++----
...lterDatabaseDiscoveryRuleStatementUpdater.java} | 47 ++++-----
.../AlterEncryptRuleStatementUpdater.java} | 22 +++--
...terReadwriteSplittingRuleStatementUpdater.java} | 33 ++++---
...rShardingBindingTableRuleStatementUpdater.java} | 23 +++--
...hardingBroadcastTableRuleStatementUpdater.java} | 23 +++--
.../AlterShardingTableRuleStatementUpdater.java} | 25 ++---
...eateDatabaseDiscoveryRuleStatementUpdater.java} | 30 +++---
.../CreateEncryptRuleStatementUpdater.java} | 22 +++--
...ateReadwriteSplittingRuleStatementUpdater.java} | 32 +++---
...eShardingBindingTableRuleStatementUpdater.java} | 23 +++--
...hardingBroadcastTableRuleStatementUpdater.java} | 23 +++--
.../CreateShardingTableRuleStatementUpdater.java} | 25 ++---
...DropDatabaseDiscoveryRuleStatementUpdater.java} | 23 +++--
.../DropEncryptRuleStatementUpdater.java} | 22 +++--
...ropReadwriteSplittingRuleStatementUpdater.java} | 23 +++--
...pShardingBindingTableRuleStatementUpdater.java} | 23 +++--
...hardingBroadcastTableRuleStatementUpdater.java} | 23 +++--
.../DropShardingTableRuleStatementUpdater.java} | 23 +++--
....apache.shardingsphere.infra.distsql.RDLUpdater | 38 ++++++++
.../distsql/DistSQLBackendHandlerFactoryTest.java | 2 +
...terDatabaseDiscoveryRuleBackendHandlerTest.java | 18 +---
...erReadwriteSplittingRuleBackendHandlerTest.java | 13 +--
.../AlterShardingTableRuleBackendHandlerTest.java | 15 +--
...ateDatabaseDiscoveryRuleBackendHandlerTest.java | 15 +--
...teReadwriteSplittingRuleBackendHandlerTest.java | 16 +--
.../CreateShardingTableRuleBackendHandlerTest.java | 14 ++-
47 files changed, 446 insertions(+), 1249 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/RDLUpdater.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/RDLUpdater.java
new file mode 100644
index 0000000..08f2360
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/RDLUpdater.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.distsql;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+/**
+ * RDL updater.
+ *
+ * @param <T> type of SQL statement
+ * @param <R> type of rule configuration
+ */
+public interface RDLUpdater<T extends SQLStatement, R extends RuleConfiguration> extends TypedSPI {
+
+ /**
+ * Check SQL statement.
+ *
+ * @param schemaName schema name
+ * @param sqlStatement SQL statement
+ * @param currentRuleConfig current rule configuration
+ * @param resource ShardingSphere resource
+ */
+ void checkSQLStatement(String schemaName, T sqlStatement, R currentRuleConfig, ShardingSphereResource resource);
+
+ /**
+ * Update current rule configuration.
+ *
+ * @param schemaName schema name
+ * @param sqlStatement SQL statement
+ * @param currentRuleConfig current rule configuration to be updated
+ */
+ void updateCurrentRuleConfiguration(String schemaName, T sqlStatement, R currentRuleConfig);
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
index c451985..fe62e34 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
@@ -52,6 +52,16 @@ public final class ShardingSphereResource {
}
/**
+ * Get not existed resource name.
+ *
+ * @param resourceNames resource names to be judged
+ * @return not existed resource names
+ */
+ public Collection<String> getNotExistedResources(final Collection<String> resourceNames) {
+ return resourceNames.stream().filter(each -> !dataSources.containsKey(each)).collect(Collectors.toSet());
+ }
+
+ /**
* Close data sources.
*
* @param dataSources data sources to be closed
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
index f2abb53..beabd82 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
@@ -17,117 +17,24 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Preconditions;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
-import org.apache.shardingsphere.dbdiscovery.yaml.converter.DatabaseDiscoveryRuleStatementConverter;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Alter database discovery rule backend handler.
*/
public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHandler<AlterDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
- }
-
public AlterDatabaseDiscoveryRuleBackendHandler(final AlterDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
- checkToBeAlteredRules(schemaName, currentRuleConfig, sqlStatement);
- checkToBeAlteredResources(schemaName, sqlStatement);
- checkToBeAlteredDiscoveryType(sqlStatement);
- }
-
- private void checkCurrentRuleConfiguration(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new DatabaseDiscoveryRuleNotExistedException(schemaName, getToBeAlteredRuleNames(sqlStatement));
- }
- }
-
- private void checkToBeAlteredRules(final String schemaName, final DatabaseDiscoveryRuleConfiguration ruleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> currentRuleNames = ruleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
- Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
- if (!notExistedRuleNames.isEmpty()) {
- throw new DatabaseDiscoveryRuleNotExistedException(schemaName, notExistedRuleNames);
- }
- }
-
- private Collection<String> getToBeAlteredRuleNames(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).collect(Collectors.toList());
- }
-
- private void checkToBeAlteredResources(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> notExistedResources = getNotExistedResources(schemaName, getToBeAlteredResourceNames(sqlStatement));
- if (!notExistedResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistedResources);
- }
- }
-
- private Collection<String> getToBeAlteredResourceNames(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> result = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> result.addAll(each.getDataSources()));
- return result;
- }
-
- private void checkToBeAlteredDiscoveryType(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> notExistedDiscoveryTypes = getToBeAlteredDiscoveryTypeNames(sqlStatement).stream()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!notExistedDiscoveryTypes.isEmpty()) {
- throw new InvalidDatabaseDiscoveryTypesException(notExistedDiscoveryTypes);
- }
- }
-
- private Collection<String> getToBeAlteredDiscoveryTypeNames(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getDiscoveryTypeName).collect(Collectors.toSet());
+ public void checkSQLStatement(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- dropRuleConfiguration(currentRuleConfig, sqlStatement);
- addRuleConfiguration(currentRuleConfig, sqlStatement);
- }
-
- private void dropRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- getToBeAlteredRuleNames(sqlStatement).forEach(each -> dropDataSourceRuleConfiguration(currentRuleConfig, each));
- }
-
- private void dropDataSourceRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String toBeDroppedRuleNames) {
- Optional<DatabaseDiscoveryDataSourceRuleConfiguration> toBeDroppedDataSourceRuleConfig
- = currentRuleConfig.getDataSources().stream().filter(each -> each.getName().equals(toBeDroppedRuleNames)).findAny();
- Preconditions.checkState(toBeDroppedDataSourceRuleConfig.isPresent());
- currentRuleConfig.getDataSources().remove(toBeDroppedDataSourceRuleConfig.get());
- currentRuleConfig.getDiscoveryTypes().remove(toBeDroppedDataSourceRuleConfig.get().getDiscoveryTypeName());
- }
-
- private void addRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Optional<DatabaseDiscoveryRuleConfiguration> toBeAlteredRuleConfig = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(DatabaseDiscoveryRuleStatementConverter.convert(sqlStatement.getRules()))).stream()
- .map(each -> (DatabaseDiscoveryRuleConfiguration) each).findFirst();
- Preconditions.checkState(toBeAlteredRuleConfig.isPresent());
- currentRuleConfig.getDataSources().addAll(toBeAlteredRuleConfig.get().getDataSources());
- currentRuleConfig.getDiscoveryTypes().putAll(toBeAlteredRuleConfig.get().getDiscoveryTypes());
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
index b81f7a6..561b56f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
@@ -18,89 +18,23 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.yaml.converter.EncryptRuleStatementConverter;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Alter encrypt rule backend handler.
*/
public final class AlterEncryptRuleBackendHandler extends RDLBackendHandler<AlterEncryptRuleStatement, EncryptRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
- }
-
public AlterEncryptRuleBackendHandler(final AlterEncryptRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new EncryptRuleNotExistedException(schemaName, getAlteredRuleNames(sqlStatement));
- }
- checkAlteredTables(schemaName, sqlStatement, currentRuleConfig);
- checkEncryptors(sqlStatement);
- }
-
- private void checkAlteredTables(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- Collection<String> existTables = getExistTables(currentRuleConfig);
- Collection<String> notExistTables = getAlteredRuleNames(sqlStatement).stream().filter(each -> !existTables.contains(each)).collect(Collectors.toList());
- if (!notExistTables.isEmpty()) {
- throw new EncryptRuleNotExistedException(schemaName, notExistTables);
- }
- }
-
- private Collection<String> getExistTables(final EncryptRuleConfiguration encryptRuleConfig) {
- return encryptRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
- }
-
- private void checkEncryptors(final AlterEncryptRuleStatement sqlStatement) {
- Collection<String> encryptors = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream()
- .map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
- Collection<String> invalidEncryptors = encryptors.stream().filter(
- each -> !TypedSPIRegistry.findRegisteredService(EncryptAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidEncryptors.isEmpty()) {
- throw new InvalidEncryptorsException(invalidEncryptors);
- }
+ public void checkSQLStatement(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- EncryptRuleConfiguration alteredEncryptRuleConfiguration = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(EncryptRuleStatementConverter.convert(sqlStatement.getRules()))).stream()
- .map(each -> (EncryptRuleConfiguration) each).findFirst().get();
- drop(sqlStatement, currentRuleConfig);
- currentRuleConfig.getTables().addAll(alteredEncryptRuleConfiguration.getTables());
- currentRuleConfig.getEncryptors().putAll(alteredEncryptRuleConfiguration.getEncryptors());
- }
-
- private void drop(final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration encryptRuleConfig) {
- getAlteredRuleNames(sqlStatement).forEach(each -> {
- EncryptTableRuleConfiguration encryptTableRuleConfig = encryptRuleConfig.getTables().stream().filter(tableRule -> tableRule.getName().equals(each)).findAny().get();
- encryptRuleConfig.getTables().remove(encryptTableRuleConfig);
- encryptTableRuleConfig.getColumns().forEach(column -> encryptRuleConfig.getEncryptors().remove(column.getEncryptorName()));
- });
- }
-
- private Collection<String> getAlteredRuleNames(final AlterEncryptRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
index b35c658..9ec3f28 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
@@ -17,106 +17,24 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
-import org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.AlterReadwriteSplittingRuleStatement;
-import org.apache.shardingsphere.readwritesplitting.spi.ReplicaLoadBalanceAlgorithm;
-import org.apache.shardingsphere.readwritesplitting.yaml.converter.ReadwriteSplittingRuleStatementConverter;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-import java.util.Set;
-import java.util.stream.Collectors;
/**
* Alter readwrite-splitting rule backend handler.
*/
public final class AlterReadwriteSplittingRuleBackendHandler extends RDLBackendHandler<AlterReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
- }
-
public AlterReadwriteSplittingRuleBackendHandler(final AlterReadwriteSplittingRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new ReadwriteSplittingRuleNotExistedException(schemaName, getAlteredRuleNames(sqlStatement));
- }
- check(schemaName, sqlStatement, getAlteredRuleNames(sqlStatement), currentRuleConfig);
- }
-
- private void check(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
- final Collection<String> alteredRuleNames, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- checkAlteredRules(schemaName, alteredRuleNames, currentRuleConfig);
- checkResources(sqlStatement, schemaName);
- checkLoadBalancer(sqlStatement);
- }
-
- private void checkAlteredRules(final String schemaName, final Collection<String> alteredRuleNames, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- Set<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
- Collection<String> notExistRuleNames = alteredRuleNames.stream()
- .filter(each -> !existRuleNames.contains(each)).collect(Collectors.toList());
- if (!notExistRuleNames.isEmpty()) {
- throw new ReadwriteSplittingRuleNotExistedException(schemaName, notExistRuleNames);
- }
- }
-
- private void checkResources(final AlterReadwriteSplittingRuleStatement sqlStatement, final String schemaName) {
- Collection<String> resources = new LinkedHashSet<>();
- sqlStatement.getRules().stream().filter(each -> Strings.isNullOrEmpty(each.getAutoAwareResource())).forEach(each -> {
- resources.add(each.getWriteDataSource());
- resources.addAll(each.getReadDataSources());
- });
- Collection<String> notExistResources = getNotExistedResources(schemaName, resources);
- if (!notExistResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistResources);
- }
- }
-
- private void checkLoadBalancer(final AlterReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> invalidLoadBalances = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidLoadBalances.isEmpty()) {
- throw new InvalidLoadBalancersException(invalidLoadBalances);
- }
+ public void checkSQLStatement(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- ReadwriteSplittingRuleConfiguration alterReadwriteSplittingRuleConfig = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singletonList(ReadwriteSplittingRuleStatementConverter.convert(sqlStatement))).stream()
- .map(each -> (ReadwriteSplittingRuleConfiguration) each).findFirst().get();
- drop(sqlStatement, currentRuleConfig);
- currentRuleConfig.getDataSources().addAll(alterReadwriteSplittingRuleConfig.getDataSources());
- currentRuleConfig.getLoadBalancers().putAll(alterReadwriteSplittingRuleConfig.getLoadBalancers());
- }
-
- private void drop(final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration ruleConfig) {
- getAlteredRuleNames(sqlStatement).forEach(each -> {
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = ruleConfig.getDataSources().stream().filter(dataSource -> each.equals(dataSource.getName())).findAny().get();
- ruleConfig.getDataSources().remove(dataSourceRuleConfig);
- ruleConfig.getLoadBalancers().remove(dataSourceRuleConfig.getLoadBalancerName());
- });
- }
-
- private Collection<String> getAlteredRuleNames(final AlterReadwriteSplittingRuleStatement sqlStatement) {
- return sqlStatement.getRules()
- .stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toSet());
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
index 975cf5a..aafce23 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
@@ -17,22 +17,10 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Splitter;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateBindingTablesException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBindingTableRulesStatement;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
/**
* Alter sharding binding table rule backend handler.
*/
@@ -43,55 +31,10 @@ public final class AlterShardingBindingTableRulesBackendHandler extends RDLBacke
}
@Override
- public void check(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new ShardingBindingTableRuleNotExistsException(schemaName);
- }
- Collection<String> invalidBindingTables = new HashSet<>();
- Collection<String> existLogicTables = getLogicTables(currentRuleConfig);
- Collection<String> bindingTables = ShardingRuleStatementConverter.convert(sqlStatement).getBindingTables();
- for (String bindingTable : bindingTables) {
- for (String logicTable : Splitter.on(",").splitToList(bindingTable)) {
- if (!existLogicTables.contains(logicTable.trim())) {
- invalidBindingTables.add(logicTable);
- }
- }
- }
- if (!invalidBindingTables.isEmpty()) {
- throw new ShardingTableRuleNotExistedException(schemaName, invalidBindingTables);
- }
- Collection<String> duplicateBindingTables = bindingTables.stream().filter(distinct()).collect(Collectors.toList());
- if (!duplicateBindingTables.isEmpty()) {
- throw new DuplicateBindingTablesException(duplicateBindingTables);
- }
+ public void checkSQLStatement(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> bindingTableGroups = currentRuleConfig.getBindingTableGroups();
- bindingTableGroups.clear();
- bindingTableGroups.addAll(ShardingRuleStatementConverter.convert(sqlStatement).getBindingTables());
- }
-
- private Collection<String> getLogicTables(final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> result = new HashSet<>();
- result.addAll(currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- result.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- return result;
- }
-
- private Predicate<String> distinct() {
- Collection<String> tables = new HashSet<>();
- return table -> notEquals(table, tables);
- }
-
- private boolean notEquals(final String table, final Collection<String> tables) {
- for (String each : tables) {
- if (table.equals(each) || (table.length() == each.length() && Splitter.on(",").splitToList(each).containsAll(Splitter.on(",").splitToList(table)))) {
- return true;
- }
- }
- tables.add(table);
- return false;
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
index 6c7137a..b55cbfc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
@@ -18,12 +18,9 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement;
-import java.util.Collection;
-
/**
* Alter sharding broadcast table rule backend handler.
*/
@@ -34,16 +31,10 @@ public final class AlterShardingBroadcastTableRulesBackendHandler extends RDLBac
}
@Override
- public void check(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
- }
+ public void checkSQLStatement(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> broadcastTables = currentRuleConfig.getBroadcastTables();
- broadcastTables.clear();
- broadcastTables.addAll(sqlStatement.getTables());
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
index 96b56b7..fe65fe2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
@@ -17,127 +17,24 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidKeyGeneratorsException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidShardingAlgorithmsException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Alter sharding table rule backend handler.
*/
public final class AlterShardingTableRuleBackendHandler extends RDLBackendHandler<AlterShardingTableRuleStatement, ShardingRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
- ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
- }
-
public AlterShardingTableRuleBackendHandler(final AlterShardingTableRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
- if (!notExistResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistResources);
- }
- Collection<String> duplicateTables = getDuplicateTables(sqlStatement);
- if (!duplicateTables.isEmpty()) {
- throw new DuplicateTablesException(duplicateTables);
- }
- Collection<String> alteredTables = getAlteredTables(sqlStatement);
- if (null == currentRuleConfig) {
- throw new ShardingTableRuleNotExistedException(schemaName, alteredTables);
- }
- Collection<String> existTables = getShardingTables(currentRuleConfig);
- Collection<String> notExistTables = alteredTables.stream().filter(each -> !existTables.contains(each)).collect(Collectors.toList());
- if (!notExistTables.isEmpty()) {
- throw new ShardingTableRuleNotExistedException(schemaName, notExistTables);
- }
- Collection<String> invalidTableAlgorithms = sqlStatement.getRules().stream().map(each -> each.getTableStrategy().getName()).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidTableAlgorithms.isEmpty()) {
- throw new InvalidShardingAlgorithmsException(invalidTableAlgorithms);
- }
- Collection<String> invalidKeyGenerators = getKeyGenerators(sqlStatement).stream()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidKeyGenerators.isEmpty()) {
- throw new InvalidKeyGeneratorsException(invalidKeyGenerators);
- }
+ public void checkSQLStatement(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- ShardingRuleConfiguration alteredShardingRuleConfig = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singletonList(ShardingRuleStatementConverter.convert(sqlStatement))).stream().map(each -> (ShardingRuleConfiguration) each).findFirst().get();
- drop(sqlStatement, currentRuleConfig);
- currentRuleConfig.getAutoTables().addAll(alteredShardingRuleConfig.getAutoTables());
- currentRuleConfig.getShardingAlgorithms().putAll(alteredShardingRuleConfig.getShardingAlgorithms());
- currentRuleConfig.getKeyGenerators().putAll(alteredShardingRuleConfig.getKeyGenerators());
- }
-
- private void drop(final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- getAlteredTables(sqlStatement).forEach(each -> {
- ShardingAutoTableRuleConfiguration shardingAutoTableRuleConfig = currentRuleConfig.getAutoTables().stream().filter(tableRule -> each.equals(tableRule.getLogicTable())).findAny().get();
- currentRuleConfig.getAutoTables().remove(shardingAutoTableRuleConfig);
- currentRuleConfig.getShardingAlgorithms().remove(shardingAutoTableRuleConfig.getShardingStrategy().getShardingAlgorithmName());
- if (Objects.nonNull(shardingAutoTableRuleConfig.getKeyGenerateStrategy())) {
- currentRuleConfig.getKeyGenerators().remove(shardingAutoTableRuleConfig.getKeyGenerateStrategy().getKeyGeneratorName());
- }
- });
- }
-
- private Collection<String> getDuplicateTables(final AlterShardingTableRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream()
- .collect(Collectors.toMap(TableRuleSegment::getLogicTable, e -> 1, Integer::sum))
- .entrySet().stream()
- .filter(entry -> entry.getValue() > 1)
- .map(Entry::getKey)
- .collect(Collectors.toList());
- }
-
- private Collection<String> getAlteredTables(final AlterShardingTableRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().map(TableRuleSegment::getLogicTable).collect(Collectors.toList());
- }
-
- private Collection<String> getShardingTables(final ShardingRuleConfiguration shardingRuleConfig) {
- Collection<String> result = new LinkedList<>();
- result.addAll(shardingRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- result.addAll(shardingRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- return result;
- }
-
- private Collection<String> getResources(final AlterShardingTableRuleStatement sqlStatement) {
- Collection<String> result = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> result.addAll(each.getDataSources()));
- return result;
- }
-
- private Collection<String> getKeyGenerators(final AlterShardingTableRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().filter(each -> Objects.nonNull(each.getKeyGenerateStrategy())).map(each -> each.getKeyGenerateStrategy().getName()).collect(Collectors.toSet());
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java
index e141f31..8c383de 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java
@@ -18,102 +18,23 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.converter.DatabaseDiscoveryRuleStatementConverter;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
/**
* Create database discovery rule backend handler.
*/
public final class CreateDatabaseDiscoveryRuleBackendHandler extends RDLBackendHandler<CreateDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
- }
-
public CreateDatabaseDiscoveryRuleBackendHandler(final CreateDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
- checkResources(schemaName, sqlStatement);
- checkDiscoverTypes(sqlStatement);
- }
-
- private void checkDuplicateRuleNames(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (null != currentRuleConfig) {
- Collection<String> existRuleNames = getRuleNames(currentRuleConfig);
- Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).filter(existRuleNames::contains).collect(Collectors.toSet());
- duplicateRuleNames.addAll(getDuplicateRuleNames(sqlStatement));
- if (!duplicateRuleNames.isEmpty()) {
- throw new DuplicateRuleNamesException(schemaName, duplicateRuleNames);
- }
- }
- }
-
- private Collection<String> getDuplicateRuleNames(final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream()
- .collect(Collectors.toMap(DatabaseDiscoveryRuleSegment::getName, e -> 1, Integer::sum))
- .entrySet().stream()
- .filter(entry -> entry.getValue() > 1)
- .map(Entry::getKey)
- .collect(Collectors.toSet());
- }
-
- private void checkResources(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> resources = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> resources.addAll(each.getDataSources()));
- Collection<String> notExistResources = getNotExistedResources(schemaName, resources);
- if (!notExistResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistResources);
- }
- }
-
- private void checkDiscoverTypes(final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> invalidDiscoveryTypes = sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getDiscoveryTypeName).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidDiscoveryTypes.isEmpty()) {
- throw new InvalidDatabaseDiscoveryTypesException(invalidDiscoveryTypes);
- }
+ public void checkSQLStatement(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- YamlDatabaseDiscoveryRuleConfiguration yamlDatabaseDiscoveryRuleConfig = DatabaseDiscoveryRuleStatementConverter.convert(sqlStatement.getRules());
- DatabaseDiscoveryRuleConfiguration createdDatabaseDiscoveryRuleConfig = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(yamlDatabaseDiscoveryRuleConfig))
- .stream().filter(each -> each instanceof DatabaseDiscoveryRuleConfiguration).findAny().map(each -> (DatabaseDiscoveryRuleConfiguration) each).get();
- if (null == currentRuleConfig) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(createdDatabaseDiscoveryRuleConfig);
- } else {
- currentRuleConfig.getDataSources().addAll(createdDatabaseDiscoveryRuleConfig.getDataSources());
- currentRuleConfig.getDiscoveryTypes().putAll(createdDatabaseDiscoveryRuleConfig.getDiscoveryTypes());
- }
- }
-
- private Collection<String> getRuleNames(final DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration) {
- return databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java
index 238e5fc..d813a8d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java
@@ -18,82 +18,23 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.yaml.converter.EncryptRuleStatementConverter;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Create encrypt rule backend handler.
*/
public final class CreateEncryptRuleBackendHandler extends RDLBackendHandler<CreateEncryptRuleStatement, EncryptRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
- }
-
public CreateEncryptRuleBackendHandler(final CreateEncryptRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
- checkEncryptors(sqlStatement);
- // TODO check resource
- }
-
- private void checkDuplicateRuleNames(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- if (null != currentRuleConfig) {
- Collection<String> existRuleNames = getRuleNames(currentRuleConfig);
- Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).filter(existRuleNames::contains).collect(Collectors.toList());
- if (!duplicateRuleNames.isEmpty()) {
- throw new DuplicateRuleNamesException(schemaName, duplicateRuleNames);
- }
- }
- }
-
- private void checkEncryptors(final CreateEncryptRuleStatement sqlStatement) {
- Collection<String> encryptors = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
- Collection<String> invalidEncryptors = encryptors.stream().filter(
- each -> !TypedSPIRegistry.findRegisteredService(EncryptAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
- if (!invalidEncryptors.isEmpty()) {
- throw new InvalidEncryptorsException(invalidEncryptors);
- }
+ public void checkSQLStatement(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- YamlEncryptRuleConfiguration yamlEncryptRuleConfiguration = EncryptRuleStatementConverter.convert(sqlStatement.getRules());
- EncryptRuleConfiguration createdEncryptRuleConfiguration = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(yamlEncryptRuleConfiguration))
- .stream().filter(each -> each instanceof EncryptRuleConfiguration).findAny().map(each -> (EncryptRuleConfiguration) each).get();
- if (null == currentRuleConfig) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(createdEncryptRuleConfiguration);
- } else {
- currentRuleConfig.getTables().addAll(createdEncryptRuleConfiguration.getTables());
- currentRuleConfig.getEncryptors().putAll(createdEncryptRuleConfiguration.getEncryptors());
- }
- }
-
- private Collection<String> getRuleNames(final EncryptRuleConfiguration encryptRuleConfig) {
- return encryptRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java
index d1cc8f6..c780349 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java
@@ -17,100 +17,24 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.CreateReadwriteSplittingRuleStatement;
-import org.apache.shardingsphere.readwritesplitting.spi.ReplicaLoadBalanceAlgorithm;
-import org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.yaml.converter.ReadwriteSplittingRuleStatementConverter;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Create readwrite splitting rule backend handler.
*/
public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackendHandler<CreateReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
- }
-
public CreateReadwriteSplittingRuleBackendHandler(final CreateReadwriteSplittingRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
- checkResources(schemaName, sqlStatement);
- checkLoadBalancers(sqlStatement);
- }
-
- private void checkDuplicateRuleNames(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- if (null != currentRuleConfig) {
- Collection<String> existRuleNames = getRuleNames(currentRuleConfig);
- Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getName).filter(existRuleNames::contains).collect(Collectors.toList());
- if (!duplicateRuleNames.isEmpty()) {
- throw new DuplicateRuleNamesException(schemaName, duplicateRuleNames);
- }
- }
- }
-
- private void checkResources(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
- if (!notExistResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistResources);
- }
- }
-
- private void checkLoadBalancers(final CreateReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> invalidLoadBalances = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent())
- .collect(Collectors.toList());
- if (!invalidLoadBalances.isEmpty()) {
- throw new InvalidLoadBalancersException(invalidLoadBalances);
- }
- }
-
- private Collection<String> getResources(final CreateReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> result = new LinkedHashSet<>();
- sqlStatement.getRules().stream().filter(each -> Strings.isNullOrEmpty(each.getAutoAwareResource())).forEach(each -> {
- result.add(each.getWriteDataSource());
- result.addAll(each.getReadDataSources());
- });
- return result;
- }
-
- private Collection<String> getRuleNames(final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- return currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+ public void checkSQLStatement(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- YamlReadwriteSplittingRuleConfiguration yamlReadwriteSplittingRuleConfig = ReadwriteSplittingRuleStatementConverter.convert(sqlStatement);
- ReadwriteSplittingRuleConfiguration createdReadwriteSplittingRuleConfig = new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(yamlReadwriteSplittingRuleConfig))
- .stream().filter(each -> each instanceof ReadwriteSplittingRuleConfiguration).findAny().map(each -> (ReadwriteSplittingRuleConfiguration) each).get();
- if (null == currentRuleConfig) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(createdReadwriteSplittingRuleConfig);
- } else {
- currentRuleConfig.getDataSources().addAll(createdReadwriteSplittingRuleConfig.getDataSources());
- currentRuleConfig.getLoadBalancers().putAll(createdReadwriteSplittingRuleConfig.getLoadBalancers());
- }
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
index 4a8fc33..52ed613 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
@@ -17,22 +17,9 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Splitter;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateBindingTablesException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBindingTableRulesStatement;
-import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
/**
* Create sharding binding table rule backend handler.
@@ -44,56 +31,10 @@ public final class CreateShardingBindingTableRulesBackendHandler extends RDLBack
}
@Override
- public void check(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new ShardingBindingTableRuleNotExistsException(schemaName);
- }
- Collection<String> invalidBindingTables = new HashSet<>();
- Collection<String> existLogicTables = getLogicTables(currentRuleConfig);
- Collection<String> bindingTables = ShardingRuleStatementConverter.convert(sqlStatement).getBindingTables();
- for (String bindingTable : bindingTables) {
- for (String logicTable : Splitter.on(",").splitToList(bindingTable)) {
- if (!existLogicTables.contains(logicTable.trim())) {
- invalidBindingTables.add(logicTable);
- }
- }
- }
- if (!invalidBindingTables.isEmpty()) {
- throw new ShardingTableRuleNotExistedException(schemaName, invalidBindingTables);
- }
- bindingTables.addAll(currentRuleConfig.getBindingTableGroups());
- Collection<String> duplicateBindingTables = bindingTables.stream().filter(distinct()).collect(Collectors.toList());
- if (!duplicateBindingTables.isEmpty()) {
- throw new DuplicateBindingTablesException(duplicateBindingTables);
- }
- }
-
- private Collection<String> getLogicTables(final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> result = new HashSet<>();
- result.addAll(currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- result.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- return result;
- }
-
- private Predicate<String> distinct() {
- Collection<String> tables = new HashSet<>();
- return table -> notEquals(table, tables);
- }
-
- private boolean notEquals(final String table, final Collection<String> tables) {
- for (String each : tables) {
- if (table.equals(each) || (table.length() == each.length() && Splitter.on(",").splitToList(each)
- .containsAll(Splitter.on(",").splitToList(table)))) {
- return true;
- }
- }
- tables.add(table);
- return false;
+ public void checkSQLStatement(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- YamlShardingRuleConfiguration yamlShardingRuleConfiguration = ShardingRuleStatementConverter.convert(sqlStatement);
- currentRuleConfig.getBindingTableGroups().addAll(yamlShardingRuleConfiguration.getBindingTables());
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java
index 61a03ae..c88ac0b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBroadcastTableRulesStatement;
@@ -33,20 +31,10 @@ public final class CreateShardingBroadcastTableRulesBackendHandler extends RDLBa
}
@Override
- public void check(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
- shardingRuleConfiguration.setBroadcastTables(sqlStatement.getTables());
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(shardingRuleConfiguration);
- } else {
- if (!currentRuleConfig.getBroadcastTables().isEmpty()) {
- throw new ShardingBroadcastTableRuleExistedException(schemaName);
- }
- currentRuleConfig.getBroadcastTables().addAll(sqlStatement.getTables());
- }
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
index 0668a32..b321b92 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
@@ -17,112 +17,24 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidKeyGeneratorsException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidShardingAlgorithmsException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.Set;
-import java.util.stream.Collectors;
/**
* Create sharding table rule backend handler.
*/
public final class CreateShardingTableRuleBackendHandler extends RDLBackendHandler<CreateShardingTableRuleStatement, ShardingRuleConfiguration> {
- static {
- // TODO consider about register once only
- ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
- ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
- }
-
public CreateShardingTableRuleBackendHandler(final CreateShardingTableRuleStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
@Override
- public void check(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
- if (!notExistResources.isEmpty()) {
- throw new ResourceNotExistedException(schemaName, notExistResources);
- }
- Collection<String> existLogicTables = getAllTables(schemaName, currentRuleConfig);
- Set<String> duplicateTableNames = sqlStatement.getRules().stream().collect(Collectors.toMap(TableRuleSegment::getLogicTable, each -> 1, Integer::sum))
- .entrySet().stream().filter(entry -> entry.getValue() > 1).map(Entry::getKey).collect(Collectors.toSet());
- duplicateTableNames.addAll(sqlStatement.getRules().stream().map(TableRuleSegment::getLogicTable).filter(existLogicTables::contains).collect(Collectors.toSet()));
- if (!duplicateTableNames.isEmpty()) {
- throw new DuplicateTablesException(duplicateTableNames);
- }
- Collection<String> invalidTableAlgorithms = sqlStatement.getRules().stream().map(each -> each.getTableStrategy().getName()).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, each, new Properties()).isPresent())
- .collect(Collectors.toList());
- if (!invalidTableAlgorithms.isEmpty()) {
- throw new InvalidShardingAlgorithmsException(invalidTableAlgorithms);
- }
- Collection<String> invalidKeyGenerators = getKeyGenerators(sqlStatement).stream()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new Properties()).isPresent())
- .collect(Collectors.toList());
- if (!invalidKeyGenerators.isEmpty()) {
- throw new InvalidKeyGeneratorsException(invalidKeyGenerators);
- }
+ public void checkSQLStatement(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- ShardingRuleConfiguration shardingRuleConfig = (ShardingRuleConfiguration) new YamlRuleConfigurationSwapperEngine()
- .swapToRuleConfigurations(Collections.singleton(ShardingRuleStatementConverter.convert(sqlStatement))).iterator().next();
- if (null == currentRuleConfig) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(shardingRuleConfig);
- } else {
- currentRuleConfig.getAutoTables().addAll(shardingRuleConfig.getAutoTables());
- currentRuleConfig.getShardingAlgorithms().putAll(shardingRuleConfig.getShardingAlgorithms());
- currentRuleConfig.getKeyGenerators().putAll(shardingRuleConfig.getKeyGenerators());
- }
- }
-
- private Collection<String> getAllTables(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> result = new HashSet<>(ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames());
- if (null != currentRuleConfig) {
- result.addAll(getShardingTables(currentRuleConfig));
- }
- return result;
- }
-
- private Collection<String> getShardingTables(final ShardingRuleConfiguration shardingRuleConfiguration) {
- Collection<String> result = new LinkedList<>();
- result.addAll(shardingRuleConfiguration.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- result.addAll(shardingRuleConfiguration.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
- return result;
- }
-
- private Collection<String> getResources(final CreateShardingTableRuleStatement sqlStatement) {
- Collection<String> result = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> result.addAll(each.getDataSources()));
- return result;
- }
-
- private Collection<String> getKeyGenerators(final CreateShardingTableRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().filter(each -> Objects.nonNull(each.getKeyGenerateStrategy())).map(each -> each.getKeyGenerateStrategy().getName()).collect(Collectors.toSet());
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
index 9ce5789..3a2d2a2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
@@ -18,14 +18,8 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
/**
* Drop database discovery rule backend handler.
@@ -37,35 +31,10 @@ public final class DropDatabaseDiscoveryRuleBackendHandler extends RDLBackendHan
}
@Override
- public void check(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
- checkRuleNames(schemaName, sqlStatement, currentRuleConfig);
- }
-
- private void checkCurrentRuleConfiguration(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new DatabaseDiscoveryRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
- }
- }
-
- private void checkRuleNames(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
- Collection<String> notExistedRuleNames = sqlStatement.getRuleNames().stream().filter(each -> !existRuleNames.contains(each)).collect(Collectors.toList());
- if (!notExistedRuleNames.isEmpty()) {
- throw new DatabaseDiscoveryRuleNotExistedException(schemaName, notExistedRuleNames);
- }
+ public void checkSQLStatement(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- sqlStatement.getRuleNames().forEach(each -> {
- DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = currentRuleConfig.getDataSources()
- .stream().filter(dataSource -> dataSource.getName().equals(each)).findAny().get();
- currentRuleConfig.getDataSources().remove(databaseDiscoveryDataSourceRuleConfig);
- currentRuleConfig.getDiscoveryTypes().remove(databaseDiscoveryDataSourceRuleConfig.getDiscoveryTypeName());
- });
- if (currentRuleConfig.getDataSources().isEmpty()) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
- }
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
index ada2166..05995da 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
@@ -18,14 +18,8 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
/**
* Drop encrypt rule backend handler.
@@ -37,30 +31,10 @@ public final class DropEncryptRuleBackendHandler extends RDLBackendHandler<DropE
}
@Override
- public void check(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new EncryptRuleNotExistedException(schemaName, sqlStatement.getTables());
- }
- check(schemaName, sqlStatement.getTables(), currentRuleConfig);
- }
-
- private void check(final String schemaName, final Collection<String> droppedTables, final EncryptRuleConfiguration currentRuleConfig) {
- Collection<String> encryptTables = currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
- Collection<String> notExistedTables = droppedTables.stream().filter(each -> !encryptTables.contains(each)).collect(Collectors.toList());
- if (!notExistedTables.isEmpty()) {
- throw new EncryptRuleNotExistedException(schemaName, notExistedTables);
- }
+ public void checkSQLStatement(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
- sqlStatement.getTables().forEach(each -> {
- EncryptTableRuleConfiguration encryptTableRuleConfiguration = currentRuleConfig.getTables().stream().filter(tableRule -> tableRule.getName().equals(each)).findAny().get();
- currentRuleConfig.getTables().remove(encryptTableRuleConfiguration);
- encryptTableRuleConfiguration.getColumns().forEach(column -> currentRuleConfig.getEncryptors().remove(column.getEncryptorName()));
- });
- if (currentRuleConfig.getTables().isEmpty()) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
- }
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
index 15215ad..df29a9e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
@@ -18,15 +18,9 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.DropReadwriteSplittingRuleStatement;
-import java.util.Collection;
-import java.util.stream.Collectors;
-
/**
* Drop readwrite splitting rule backend handler.
*/
@@ -37,26 +31,10 @@ public final class DropReadwriteSplittingRuleBackendHandler extends RDLBackendHa
}
@Override
- public void check(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig) {
- throw new ReadwriteSplittingRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
- }
- Collection<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
- Collection<String> notExistedRuleNames = sqlStatement.getRuleNames().stream().filter(each -> !existRuleNames.contains(each)).collect(Collectors.toList());
- if (!notExistedRuleNames.isEmpty()) {
- throw new ReadwriteSplittingRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
- }
+ public void checkSQLStatement(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
- sqlStatement.getRuleNames().forEach(each -> {
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(dataSource -> each.equals(dataSource.getName())).findAny().get();
- currentRuleConfig.getDataSources().remove(dataSourceRuleConfig);
- currentRuleConfig.getLoadBalancers().remove(dataSourceRuleConfig.getLoadBalancerName());
- });
- if (currentRuleConfig.getDataSources().isEmpty()) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
- }
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
index d208ef5..7073241 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBindingTableRulesStatement;
@@ -32,14 +31,10 @@ public final class DropShardingBindingTableRulesBackendHandler extends RDLBacken
}
@Override
- public void check(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig || currentRuleConfig.getBindingTableGroups().isEmpty()) {
- throw new ShardingBindingTableRuleNotExistsException(schemaName);
- }
+ public void checkSQLStatement(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- currentRuleConfig.getBindingTableGroups().clear();
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
index 41e62e8..76f8c47 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBroadcastTableRulesStatement;
@@ -32,14 +31,10 @@ public final class DropShardingBroadcastTableRulesBackendHandler extends RDLBack
}
@Override
- public void check(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- if (null == currentRuleConfig || currentRuleConfig.getBroadcastTables().isEmpty()) {
- throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
- }
+ public void checkSQLStatement(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- currentRuleConfig.getBroadcastTables().clear();
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
index b61ac03..02a537c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
@@ -17,20 +17,10 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-import com.google.common.base.Splitter;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRulesInUsedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingTableRuleStatement;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.stream.Collectors;
-
/**
* Drop sharding table rule backend handler.
*/
@@ -41,49 +31,10 @@ public final class DropShardingTableRuleBackendHandler extends RDLBackendHandler
}
@Override
- public void check(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> tableNames = sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
- if (null == currentRuleConfig) {
- throw new ShardingTableRuleNotExistedException(schemaName, tableNames);
- }
- Collection<String> shardingTableNames = getShardingTables(currentRuleConfig);
- Collection<String> notExistedTableNames = tableNames.stream().filter(each -> !shardingTableNames.contains(each)).collect(Collectors.toList());
- if (!notExistedTableNames.isEmpty()) {
- throw new ShardingTableRuleNotExistedException(schemaName, notExistedTableNames);
- }
- Collection<String> bindingTables = getBindingTables(currentRuleConfig);
- Collection<String> usedTableNames = tableNames.stream().filter(bindingTables::contains).collect(Collectors.toList());
- if (!usedTableNames.isEmpty()) {
- throw new ShardingTableRulesInUsedException(usedTableNames);
- }
+ public void checkSQLStatement(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
@Override
- public void doExecute(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- for (String each : getDroppedTables(sqlStatement)) {
- dropShardingTable(currentRuleConfig, each);
- }
- }
-
- private Collection<String> getDroppedTables(final DropShardingTableRuleStatement sqlStatement) {
- return sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
- }
-
- private Collection<String> getShardingTables(final ShardingRuleConfiguration shardingRuleConfig) {
- Collection<String> result = new LinkedList<>();
- result.addAll(shardingRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- result.addAll(shardingRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- return result;
- }
-
- private void dropShardingTable(final ShardingRuleConfiguration currentRuleConfig, final String tableName) {
- currentRuleConfig.getTables().removeAll(currentRuleConfig.getTables().stream().filter(each -> tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList()));
- currentRuleConfig.getAutoTables().removeAll(currentRuleConfig.getAutoTables().stream().filter(each -> tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList()));
- }
-
- private Collection<String> getBindingTables(final ShardingRuleConfiguration shardingRuleConfig) {
- Collection<String> result = new LinkedHashSet<>();
- shardingRuleConfig.getBindingTableGroups().forEach(each -> result.addAll(Splitter.on(",").splitToList(each)));
- return result;
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java
index 42eb4da..c681cbe 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java
@@ -20,8 +20,11 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsAlteredSQLNotificationEvent;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.scope.SchemaRuleConfiguration;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -32,6 +35,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.Optional;
+import java.util.Properties;
import java.util.stream.Collectors;
/**
@@ -42,46 +46,51 @@ import java.util.stream.Collectors;
*/
public abstract class RDLBackendHandler<T extends SQLStatement, R extends SchemaRuleConfiguration> extends SchemaRequiredBackendHandler<T> {
+ static {
+ ShardingSphereServiceLoader.register(RDLUpdater.class);
+ }
+
public RDLBackendHandler(final T sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Override
protected final ResponseHeader execute(final String schemaName, final T sqlStatement) {
- Class<R> configRuleClass = (Class<R>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
- R currentRuleConfig = findCurrentRuleConfiguration(schemaName, configRuleClass).orElse(null);
- check(schemaName, sqlStatement, currentRuleConfig);
- doExecute(schemaName, sqlStatement, currentRuleConfig);
- postChange(schemaName);
+ R currentRuleConfig = findCurrentRuleConfiguration(schemaName).orElse(null);
+ RDLUpdater rdlUpdater = TypedSPIRegistry.getRegisteredService(RDLUpdater.class, sqlStatement.getClass().getCanonicalName(), new Properties());
+ rdlUpdater.checkSQLStatement(schemaName, sqlStatement, currentRuleConfig, ProxyContext.getInstance().getMetaData(schemaName).getResource());
+ rdlUpdater.updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
+ postRuleConfigurationChange(schemaName);
return new UpdateResponseHeader(sqlStatement);
}
- protected abstract void check(String schemaName, T sqlStatement, R currentRuleConfig);
-
- protected abstract void doExecute(String schemaName, T sqlStatement, R currentRuleConfig);
-
- private void postChange(final String schemaName) {
- ShardingSphereEventBus.getInstance().post(
- new RuleConfigurationsAlteredSQLNotificationEvent(schemaName, ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()));
- }
-
@SuppressWarnings("unchecked")
- private Optional<R> findCurrentRuleConfiguration(final String schemaName, final Class<R> configRuleClass) {
+ private Optional<R> findCurrentRuleConfiguration(final String schemaName) {
+ Class<R> ruleConfigClass = (Class<R>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
for (RuleConfiguration each : ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()) {
- if (configRuleClass.isAssignableFrom(each.getClass())) {
+ if (ruleConfigClass.isAssignableFrom(each.getClass())) {
return Optional.of((R) each);
}
}
return Optional.empty();
}
+ protected abstract void checkSQLStatement(String schemaName, T sqlStatement, R currentRuleConfig);
+
+ protected abstract void updateCurrentRuleConfiguration(String schemaName, T sqlStatement, R currentRuleConfig);
+
+ private void postRuleConfigurationChange(final String schemaName) {
+ ShardingSphereEventBus.getInstance().post(
+ new RuleConfigurationsAlteredSQLNotificationEvent(schemaName, ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()));
+ }
+
protected final Collection<String> getNotExistedResources(final String schemaName, final Collection<String> resourceNames) {
return resourceNames.stream().filter(each -> !isExistedResource(schemaName, each)).collect(Collectors.toSet());
}
private boolean isExistedResource(final String schemaName, final String resourceName) {
ShardingSphereResource resource = ProxyContext.getInstance().getMetaData(schemaName).getResource();
- return null != resource && resource.getDataSources().containsKey(resourceName);
+ return resource.getDataSources().containsKey(resourceName);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdater.java
similarity index 73%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdater.java
index f2abb53..75fb92f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
@@ -24,10 +24,11 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDisc
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.dbdiscovery.yaml.converter.DatabaseDiscoveryRuleStatementConverter;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
@@ -40,24 +41,21 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Alter database discovery rule backend handler.
+ * Alter database discovery rule statement updater.
*/
-public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHandler<AlterDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
+public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RDLUpdater<AlterDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
}
- public AlterDatabaseDiscoveryRuleBackendHandler(final AlterDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
- checkToBeAlteredRules(schemaName, currentRuleConfig, sqlStatement);
- checkToBeAlteredResources(schemaName, sqlStatement);
+ checkToBeAlteredRules(schemaName, sqlStatement, currentRuleConfig);
+ checkToBeAlteredResources(schemaName, sqlStatement, resource);
checkToBeAlteredDiscoveryType(sqlStatement);
}
@@ -67,8 +65,8 @@ public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHa
}
}
- private void checkToBeAlteredRules(final String schemaName, final DatabaseDiscoveryRuleConfiguration ruleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> currentRuleNames = ruleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
+ private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
throw new DatabaseDiscoveryRuleNotExistedException(schemaName, notExistedRuleNames);
@@ -79,8 +77,8 @@ public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHa
return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).collect(Collectors.toList());
}
- private void checkToBeAlteredResources(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> notExistedResources = getNotExistedResources(schemaName, getToBeAlteredResourceNames(sqlStatement));
+ private void checkToBeAlteredResources(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ Collection<String> notExistedResources = resource.getNotExistedResources(getToBeAlteredResourceNames(sqlStatement));
if (!notExistedResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistedResources);
}
@@ -105,16 +103,16 @@ public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHa
}
@Override
- public void doExecute(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- dropRuleConfiguration(currentRuleConfig, sqlStatement);
- addRuleConfiguration(currentRuleConfig, sqlStatement);
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ dropRuleConfiguration(sqlStatement, currentRuleConfig);
+ addRuleConfiguration(sqlStatement, currentRuleConfig);
}
- private void dropRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- getToBeAlteredRuleNames(sqlStatement).forEach(each -> dropDataSourceRuleConfiguration(currentRuleConfig, each));
+ private void dropRuleConfiguration(final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ getToBeAlteredRuleNames(sqlStatement).forEach(each -> dropDataSourceRuleConfiguration(each, currentRuleConfig));
}
- private void dropDataSourceRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String toBeDroppedRuleNames) {
+ private void dropDataSourceRuleConfiguration(final String toBeDroppedRuleNames, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
Optional<DatabaseDiscoveryDataSourceRuleConfiguration> toBeDroppedDataSourceRuleConfig
= currentRuleConfig.getDataSources().stream().filter(each -> each.getName().equals(toBeDroppedRuleNames)).findAny();
Preconditions.checkState(toBeDroppedDataSourceRuleConfig.isPresent());
@@ -122,7 +120,7 @@ public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHa
currentRuleConfig.getDiscoveryTypes().remove(toBeDroppedDataSourceRuleConfig.get().getDiscoveryTypeName());
}
- private void addRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
+ private void addRuleConfiguration(final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
Optional<DatabaseDiscoveryRuleConfiguration> toBeAlteredRuleConfig = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(DatabaseDiscoveryRuleStatementConverter.convert(sqlStatement.getRules()))).stream()
.map(each -> (DatabaseDiscoveryRuleConfiguration) each).findFirst();
@@ -130,4 +128,9 @@ public final class AlterDatabaseDiscoveryRuleBackendHandler extends RDLBackendHa
currentRuleConfig.getDataSources().addAll(toBeAlteredRuleConfig.get().getDataSources());
currentRuleConfig.getDiscoveryTypes().putAll(toBeAlteredRuleConfig.get().getDiscoveryTypes());
}
+
+ @Override
+ public String getType() {
+ return AlterDatabaseDiscoveryRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdater.java
similarity index 86%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdater.java
index b81f7a6..bd00057 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdater.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
@@ -23,10 +23,11 @@ import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegme
import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.yaml.converter.EncryptRuleStatementConverter;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
@@ -37,21 +38,17 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Alter encrypt rule backend handler.
+ * Alter encrypt rule statement updater.
*/
-public final class AlterEncryptRuleBackendHandler extends RDLBackendHandler<AlterEncryptRuleStatement, EncryptRuleConfiguration> {
+public final class AlterEncryptRuleStatementUpdater implements RDLUpdater<AlterEncryptRuleStatement, EncryptRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
}
- public AlterEncryptRuleBackendHandler(final AlterEncryptRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new EncryptRuleNotExistedException(schemaName, getAlteredRuleNames(sqlStatement));
}
@@ -83,7 +80,7 @@ public final class AlterEncryptRuleBackendHandler extends RDLBackendHandler<Alte
}
@Override
- public void doExecute(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
EncryptRuleConfiguration alteredEncryptRuleConfiguration = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(EncryptRuleStatementConverter.convert(sqlStatement.getRules()))).stream()
.map(each -> (EncryptRuleConfiguration) each).findFirst().get();
@@ -103,4 +100,9 @@ public final class AlterEncryptRuleBackendHandler extends RDLBackendHandler<Alte
private Collection<String> getAlteredRuleNames(final AlterEncryptRuleStatement sqlStatement) {
return sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
}
+
+ @Override
+ public String getType() {
+ return AlterEncryptRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterReadwriteSplittingRuleStatementUpdater.java
similarity index 81%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterReadwriteSplittingRuleStatementUpdater.java
index b35c658..0e98c41 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterReadwriteSplittingRuleStatementUpdater.java
@@ -15,13 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Strings;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
import org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
@@ -40,31 +41,28 @@ import java.util.Set;
import java.util.stream.Collectors;
/**
- * Alter readwrite-splitting rule backend handler.
+ * Alter readwrite-splitting rule statement updater.
*/
-public final class AlterReadwriteSplittingRuleBackendHandler extends RDLBackendHandler<AlterReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
+public final class AlterReadwriteSplittingRuleStatementUpdater implements RDLUpdater<AlterReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
}
- public AlterReadwriteSplittingRuleBackendHandler(final AlterReadwriteSplittingRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new ReadwriteSplittingRuleNotExistedException(schemaName, getAlteredRuleNames(sqlStatement));
}
- check(schemaName, sqlStatement, getAlteredRuleNames(sqlStatement), currentRuleConfig);
+ check(schemaName, sqlStatement, getAlteredRuleNames(sqlStatement), currentRuleConfig, resource);
}
private void check(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
- final Collection<String> alteredRuleNames, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ final Collection<String> alteredRuleNames, final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkAlteredRules(schemaName, alteredRuleNames, currentRuleConfig);
- checkResources(sqlStatement, schemaName);
+ checkResources(schemaName, sqlStatement, resource);
checkLoadBalancer(sqlStatement);
}
@@ -77,13 +75,13 @@ public final class AlterReadwriteSplittingRuleBackendHandler extends RDLBackendH
}
}
- private void checkResources(final AlterReadwriteSplittingRuleStatement sqlStatement, final String schemaName) {
+ private void checkResources(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereResource resource) {
Collection<String> resources = new LinkedHashSet<>();
sqlStatement.getRules().stream().filter(each -> Strings.isNullOrEmpty(each.getAutoAwareResource())).forEach(each -> {
resources.add(each.getWriteDataSource());
resources.addAll(each.getReadDataSources());
});
- Collection<String> notExistResources = getNotExistedResources(schemaName, resources);
+ Collection<String> notExistResources = resource.getNotExistedResources(resources);
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
}
@@ -98,7 +96,7 @@ public final class AlterReadwriteSplittingRuleBackendHandler extends RDLBackendH
}
@Override
- public void doExecute(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
ReadwriteSplittingRuleConfiguration alterReadwriteSplittingRuleConfig = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singletonList(ReadwriteSplittingRuleStatementConverter.convert(sqlStatement))).stream()
.map(each -> (ReadwriteSplittingRuleConfiguration) each).findFirst().get();
@@ -119,4 +117,9 @@ public final class AlterReadwriteSplittingRuleBackendHandler extends RDLBackendH
return sqlStatement.getRules()
.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toSet());
}
+
+ @Override
+ public String getType() {
+ return AlterReadwriteSplittingRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBindingTableRuleStatementUpdater.java
similarity index 82%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBindingTableRuleStatementUpdater.java
index 975cf5a..3d82a14 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBindingTableRuleStatementUpdater.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Splitter;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateBindingTablesException;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
@@ -34,16 +35,13 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
- * Alter sharding binding table rule backend handler.
+ * Alter sharding binding table rule statement updater.
*/
-public final class AlterShardingBindingTableRulesBackendHandler extends RDLBackendHandler<AlterShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
-
- public AlterShardingBindingTableRulesBackendHandler(final AlterShardingBindingTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class AlterShardingBindingTableRuleStatementUpdater implements RDLUpdater<AlterShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
@@ -67,7 +65,7 @@ public final class AlterShardingBindingTableRulesBackendHandler extends RDLBacke
}
@Override
- public void doExecute(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> bindingTableGroups = currentRuleConfig.getBindingTableGroups();
bindingTableGroups.clear();
bindingTableGroups.addAll(ShardingRuleStatementConverter.convert(sqlStatement).getBindingTables());
@@ -94,4 +92,9 @@ public final class AlterShardingBindingTableRulesBackendHandler extends RDLBacke
tables.add(table);
return false;
}
+
+ @Override
+ public String getType() {
+ return AlterShardingBindingTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBroadcastTableRuleStatementUpdater.java
similarity index 62%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBroadcastTableRuleStatementUpdater.java
index 6c7137a..38b2c50 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingBroadcastTableRuleStatementUpdater.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement;
@@ -25,25 +26,27 @@ import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterSharding
import java.util.Collection;
/**
- * Alter sharding broadcast table rule backend handler.
+ * Alter sharding broadcast table rule statement updater.
*/
-public final class AlterShardingBroadcastTableRulesBackendHandler extends RDLBackendHandler<AlterShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
-
- public AlterShardingBroadcastTableRulesBackendHandler(final AlterShardingBroadcastTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class AlterShardingBroadcastTableRuleStatementUpdater implements RDLUpdater<AlterShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
}
}
@Override
- public void doExecute(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> broadcastTables = currentRuleConfig.getBroadcastTables();
broadcastTables.clear();
broadcastTables.addAll(sqlStatement.getTables());
}
+
+ @Override
+ public String getType() {
+ return AlterShardingBroadcastTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdater.java
similarity index 88%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdater.java
index 96b56b7..2fee8ab 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdater.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidKeyGeneratorsException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidShardingAlgorithmsException;
@@ -45,9 +46,9 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Alter sharding table rule backend handler.
+ * Alter sharding table rule statement updater.
*/
-public final class AlterShardingTableRuleBackendHandler extends RDLBackendHandler<AlterShardingTableRuleStatement, ShardingRuleConfiguration> {
+public final class AlterShardingTableRuleStatementUpdater implements RDLUpdater<AlterShardingTableRuleStatement, ShardingRuleConfiguration> {
static {
// TODO consider about register once only
@@ -55,13 +56,10 @@ public final class AlterShardingTableRuleBackendHandler extends RDLBackendHandle
ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
}
- public AlterShardingTableRuleBackendHandler(final AlterShardingTableRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
+ public void checkSQLStatement(final String schemaName, final AlterShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ Collection<String> notExistResources = resource.getNotExistedResources(getResources(sqlStatement));
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
}
@@ -91,7 +89,7 @@ public final class AlterShardingTableRuleBackendHandler extends RDLBackendHandle
}
@Override
- public void doExecute(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
ShardingRuleConfiguration alteredShardingRuleConfig = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singletonList(ShardingRuleStatementConverter.convert(sqlStatement))).stream().map(each -> (ShardingRuleConfiguration) each).findFirst().get();
drop(sqlStatement, currentRuleConfig);
@@ -140,4 +138,9 @@ public final class AlterShardingTableRuleBackendHandler extends RDLBackendHandle
private Collection<String> getKeyGenerators(final AlterShardingTableRuleStatement sqlStatement) {
return sqlStatement.getRules().stream().filter(each -> Objects.nonNull(each.getKeyGenerateStrategy())).map(each -> each.getKeyGenerateStrategy().getName()).collect(Collectors.toSet());
}
+
+ @Override
+ public String getType() {
+ return AlterShardingTableRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdater.java
similarity index 83%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdater.java
index e141f31..1c54e80 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdater.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
@@ -24,10 +24,11 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateData
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.yaml.converter.DatabaseDiscoveryRuleStatementConverter;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
@@ -40,25 +41,21 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
-
/**
- * Create database discovery rule backend handler.
+ * Create database discovery rule statement updater.
*/
-public final class CreateDatabaseDiscoveryRuleBackendHandler extends RDLBackendHandler<CreateDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
+public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RDLUpdater<CreateDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
}
- public CreateDatabaseDiscoveryRuleBackendHandler(final CreateDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
- checkResources(schemaName, sqlStatement);
+ checkResources(schemaName, sqlStatement, resource);
checkDiscoverTypes(sqlStatement);
}
@@ -82,10 +79,10 @@ public final class CreateDatabaseDiscoveryRuleBackendHandler extends RDLBackendH
.collect(Collectors.toSet());
}
- private void checkResources(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
+ private void checkResources(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) {
Collection<String> resources = new LinkedHashSet<>();
sqlStatement.getRules().forEach(each -> resources.addAll(each.getDataSources()));
- Collection<String> notExistResources = getNotExistedResources(schemaName, resources);
+ Collection<String> notExistResources = resource.getNotExistedResources(resources);
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
}
@@ -100,7 +97,7 @@ public final class CreateDatabaseDiscoveryRuleBackendHandler extends RDLBackendH
}
@Override
- public void doExecute(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
YamlDatabaseDiscoveryRuleConfiguration yamlDatabaseDiscoveryRuleConfig = DatabaseDiscoveryRuleStatementConverter.convert(sqlStatement.getRules());
DatabaseDiscoveryRuleConfiguration createdDatabaseDiscoveryRuleConfig = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(yamlDatabaseDiscoveryRuleConfig))
@@ -116,4 +113,9 @@ public final class CreateDatabaseDiscoveryRuleBackendHandler extends RDLBackendH
private Collection<String> getRuleNames(final DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration) {
return databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
}
+
+ @Override
+ public String getType() {
+ return CreateDatabaseDiscoveryRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdater.java
similarity index 85%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdater.java
index 238e5fc..b02c247 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdater.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
@@ -24,10 +24,11 @@ import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptR
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.converter.EncryptRuleStatementConverter;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
@@ -39,21 +40,17 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Create encrypt rule backend handler.
+ * Create encrypt rule statement updater.
*/
-public final class CreateEncryptRuleBackendHandler extends RDLBackendHandler<CreateEncryptRuleStatement, EncryptRuleConfiguration> {
+public final class CreateEncryptRuleStatementUpdater implements RDLUpdater<CreateEncryptRuleStatement, EncryptRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
}
- public CreateEncryptRuleBackendHandler(final CreateEncryptRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
checkEncryptors(sqlStatement);
// TODO check resource
@@ -80,7 +77,7 @@ public final class CreateEncryptRuleBackendHandler extends RDLBackendHandler<Cre
}
@Override
- public void doExecute(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
YamlEncryptRuleConfiguration yamlEncryptRuleConfiguration = EncryptRuleStatementConverter.convert(sqlStatement.getRules());
EncryptRuleConfiguration createdEncryptRuleConfiguration = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(yamlEncryptRuleConfiguration))
@@ -96,4 +93,9 @@ public final class CreateEncryptRuleBackendHandler extends RDLBackendHandler<Cre
private Collection<String> getRuleNames(final EncryptRuleConfiguration encryptRuleConfig) {
return encryptRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
}
+
+ @Override
+ public String getType() {
+ return CreateEncryptRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdater.java
similarity index 82%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdater.java
index d1cc8f6..fbc8b6f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdater.java
@@ -15,13 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Strings;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
@@ -41,23 +42,20 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Create readwrite splitting rule backend handler.
+ * Create readwrite-splitting rule statement updater.
*/
-public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackendHandler<CreateReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
+public final class CreateReadwriteSplittingRuleStatementUpdater implements RDLUpdater<CreateReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
static {
// TODO consider about register once only
ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
}
- public CreateReadwriteSplittingRuleBackendHandler(final CreateReadwriteSplittingRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
- checkResources(schemaName, sqlStatement);
+ checkResources(schemaName, sqlStatement, resource);
checkLoadBalancers(sqlStatement);
}
@@ -71,8 +69,8 @@ public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackend
}
}
- private void checkResources(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
+ private void checkResources(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ Collection<String> notExistResources = resource.getNotExistedResources(getResources(sqlStatement));
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
}
@@ -80,8 +78,7 @@ public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackend
private void checkLoadBalancers(final CreateReadwriteSplittingRuleStatement sqlStatement) {
Collection<String> invalidLoadBalances = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).distinct()
- .filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent())
- .collect(Collectors.toList());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!invalidLoadBalances.isEmpty()) {
throw new InvalidLoadBalancersException(invalidLoadBalances);
}
@@ -101,7 +98,7 @@ public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackend
}
@Override
- public void doExecute(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
YamlReadwriteSplittingRuleConfiguration yamlReadwriteSplittingRuleConfig = ReadwriteSplittingRuleStatementConverter.convert(sqlStatement);
ReadwriteSplittingRuleConfiguration createdReadwriteSplittingRuleConfig = new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(yamlReadwriteSplittingRuleConfig))
@@ -113,4 +110,9 @@ public final class CreateReadwriteSplittingRuleBackendHandler extends RDLBackend
currentRuleConfig.getLoadBalancers().putAll(createdReadwriteSplittingRuleConfig.getLoadBalancers());
}
}
+
+ @Override
+ public String getType() {
+ return CreateReadwriteSplittingRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBindingTableRuleStatementUpdater.java
similarity index 82%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBindingTableRuleStatementUpdater.java
index 4a8fc33..72354bf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBindingTableRuleStatementUpdater.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Splitter;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateBindingTablesException;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
@@ -35,16 +36,13 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
- * Create sharding binding table rule backend handler.
+ * Create sharding binding table rule statement updater.
*/
-public final class CreateShardingBindingTableRulesBackendHandler extends RDLBackendHandler<CreateShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
-
- public CreateShardingBindingTableRulesBackendHandler(final CreateShardingBindingTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class CreateShardingBindingTableRuleStatementUpdater implements RDLUpdater<CreateShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
@@ -92,8 +90,13 @@ public final class CreateShardingBindingTableRulesBackendHandler extends RDLBack
}
@Override
- public void doExecute(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
YamlShardingRuleConfiguration yamlShardingRuleConfiguration = ShardingRuleStatementConverter.convert(sqlStatement);
currentRuleConfig.getBindingTableGroups().addAll(yamlShardingRuleConfiguration.getBindingTables());
}
+
+ @Override
+ public String getType() {
+ return CreateShardingBindingTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBroadcastTableRuleStatementUpdater.java
similarity index 67%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBroadcastTableRuleStatementUpdater.java
index 61a03ae..4cf1b06 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingBroadcastTableRuleStatementUpdater.java
@@ -15,29 +15,27 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleExistedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBroadcastTableRulesStatement;
/**
- * Create sharding broadcast table rule backend handler.
+ * Create sharding broadcast table rule statement updater.
*/
-public final class CreateShardingBroadcastTableRulesBackendHandler extends RDLBackendHandler<CreateShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
-
- public CreateShardingBroadcastTableRulesBackendHandler(final CreateShardingBroadcastTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class CreateShardingBroadcastTableRuleStatementUpdater implements RDLUpdater<CreateShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
}
@Override
- public void doExecute(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
if (null == currentRuleConfig) {
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
shardingRuleConfiguration.setBroadcastTables(sqlStatement.getTables());
@@ -49,4 +47,9 @@ public final class CreateShardingBroadcastTableRulesBackendHandler extends RDLBa
currentRuleConfig.getBroadcastTables().addAll(sqlStatement.getTables());
}
}
+
+ @Override
+ public String getType() {
+ return CreateShardingBroadcastTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingTableRuleStatementUpdater.java
similarity index 87%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingTableRuleStatementUpdater.java
index 0668a32..2de0c42 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateShardingTableRuleStatementUpdater.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
import org.apache.shardingsphere.proxy.backend.exception.InvalidKeyGeneratorsException;
@@ -47,9 +48,9 @@ import java.util.Set;
import java.util.stream.Collectors;
/**
- * Create sharding table rule backend handler.
+ * Create sharding table rule statement updater.
*/
-public final class CreateShardingTableRuleBackendHandler extends RDLBackendHandler<CreateShardingTableRuleStatement, ShardingRuleConfiguration> {
+public final class CreateShardingTableRuleStatementUpdater implements RDLUpdater<CreateShardingTableRuleStatement, ShardingRuleConfiguration> {
static {
// TODO consider about register once only
@@ -57,13 +58,10 @@ public final class CreateShardingTableRuleBackendHandler extends RDLBackendHandl
ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
}
- public CreateShardingTableRuleBackendHandler(final CreateShardingTableRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
-
@Override
- public void check(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
- Collection<String> notExistResources = getNotExistedResources(schemaName, getResources(sqlStatement));
+ public void checkSQLStatement(final String schemaName, final CreateShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ Collection<String> notExistResources = resource.getNotExistedResources(getResources(sqlStatement));
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
}
@@ -89,7 +87,7 @@ public final class CreateShardingTableRuleBackendHandler extends RDLBackendHandl
}
@Override
- public void doExecute(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
ShardingRuleConfiguration shardingRuleConfig = (ShardingRuleConfiguration) new YamlRuleConfigurationSwapperEngine()
.swapToRuleConfigurations(Collections.singleton(ShardingRuleStatementConverter.convert(sqlStatement))).iterator().next();
if (null == currentRuleConfig) {
@@ -125,4 +123,9 @@ public final class CreateShardingTableRuleBackendHandler extends RDLBackendHandl
private Collection<String> getKeyGenerators(final CreateShardingTableRuleStatement sqlStatement) {
return sqlStatement.getRules().stream().filter(each -> Objects.nonNull(each.getKeyGenerateStrategy())).map(each -> each.getKeyGenerateStrategy().getName()).collect(Collectors.toSet());
}
+
+ @Override
+ public String getType() {
+ return CreateShardingTableRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropDatabaseDiscoveryRuleStatementUpdater.java
similarity index 78%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropDatabaseDiscoveryRuleStatementUpdater.java
index 9ce5789..342749a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropDatabaseDiscoveryRuleStatementUpdater.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
@@ -28,16 +29,13 @@ import java.util.Collection;
import java.util.stream.Collectors;
/**
- * Drop database discovery rule backend handler.
+ * Drop database discovery rule statement updater.
*/
-public final class DropDatabaseDiscoveryRuleBackendHandler extends RDLBackendHandler<DropDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
-
- public DropDatabaseDiscoveryRuleBackendHandler(final DropDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropDatabaseDiscoveryRuleStatementUpdater implements RDLUpdater<DropDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkRuleNames(schemaName, sqlStatement, currentRuleConfig);
}
@@ -57,7 +55,7 @@ public final class DropDatabaseDiscoveryRuleBackendHandler extends RDLBackendHan
}
@Override
- public void doExecute(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
sqlStatement.getRuleNames().forEach(each -> {
DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = currentRuleConfig.getDataSources()
.stream().filter(dataSource -> dataSource.getName().equals(each)).findAny().get();
@@ -68,4 +66,9 @@ public final class DropDatabaseDiscoveryRuleBackendHandler extends RDLBackendHan
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
}
}
+
+ @Override
+ public String getType() {
+ return DropDatabaseDiscoveryRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropEncryptRuleStatementUpdater.java
similarity index 78%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropEncryptRuleStatementUpdater.java
index ada2166..4b9cdab 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropEncryptRuleStatementUpdater.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
@@ -28,16 +29,12 @@ import java.util.Collection;
import java.util.stream.Collectors;
/**
- * Drop encrypt rule backend handler.
+ * Drop encrypt rule statement updater.
*/
-public final class DropEncryptRuleBackendHandler extends RDLBackendHandler<DropEncryptRuleStatement, EncryptRuleConfiguration> {
-
- public DropEncryptRuleBackendHandler(final DropEncryptRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropEncryptRuleStatementUpdater implements RDLUpdater<DropEncryptRuleStatement, EncryptRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new EncryptRuleNotExistedException(schemaName, sqlStatement.getTables());
}
@@ -53,7 +50,7 @@ public final class DropEncryptRuleBackendHandler extends RDLBackendHandler<DropE
}
@Override
- public void doExecute(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
sqlStatement.getTables().forEach(each -> {
EncryptTableRuleConfiguration encryptTableRuleConfiguration = currentRuleConfig.getTables().stream().filter(tableRule -> tableRule.getName().equals(each)).findAny().get();
currentRuleConfig.getTables().remove(encryptTableRuleConfiguration);
@@ -63,4 +60,9 @@ public final class DropEncryptRuleBackendHandler extends RDLBackendHandler<DropE
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
}
}
+
+ @Override
+ public String getType() {
+ return DropEncryptRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropReadwriteSplittingRuleStatementUpdater.java
similarity index 74%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropReadwriteSplittingRuleStatementUpdater.java
index 15215ad..78ed479 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropReadwriteSplittingRuleStatementUpdater.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
@@ -28,16 +29,13 @@ import java.util.Collection;
import java.util.stream.Collectors;
/**
- * Drop readwrite splitting rule backend handler.
+ * Drop readwrite-splitting rule statement updater.
*/
-public final class DropReadwriteSplittingRuleBackendHandler extends RDLBackendHandler<DropReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
-
- public DropReadwriteSplittingRuleBackendHandler(final DropReadwriteSplittingRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropReadwriteSplittingRuleStatementUpdater implements RDLUpdater<DropReadwriteSplittingRuleStatement, ReadwriteSplittingRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig) {
throw new ReadwriteSplittingRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
}
@@ -49,7 +47,7 @@ public final class DropReadwriteSplittingRuleBackendHandler extends RDLBackendHa
}
@Override
- public void doExecute(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
sqlStatement.getRuleNames().forEach(each -> {
ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(dataSource -> each.equals(dataSource.getName())).findAny().get();
currentRuleConfig.getDataSources().remove(dataSourceRuleConfig);
@@ -59,4 +57,9 @@ public final class DropReadwriteSplittingRuleBackendHandler extends RDLBackendHa
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
}
}
+
+ @Override
+ public String getType() {
+ return DropReadwriteSplittingRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBindingTableRuleStatementUpdater.java
similarity index 61%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBindingTableRuleStatementUpdater.java
index d208ef5..453e49f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBindingTableRuleStatementUpdater.java
@@ -15,31 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBindingTableRulesStatement;
/**
- * Drop sharding binding table rules backend handler.
+ * Drop sharding binding table rule statement updater.
*/
-public final class DropShardingBindingTableRulesBackendHandler extends RDLBackendHandler<DropShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
-
- public DropShardingBindingTableRulesBackendHandler(final DropShardingBindingTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropShardingBindingTableRuleStatementUpdater implements RDLUpdater<DropShardingBindingTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig || currentRuleConfig.getBindingTableGroups().isEmpty()) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
}
@Override
- public void doExecute(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
currentRuleConfig.getBindingTableGroups().clear();
}
+
+ @Override
+ public String getType() {
+ return DropShardingBindingTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBroadcastTableRuleStatementUpdater.java
similarity index 61%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBroadcastTableRuleStatementUpdater.java
index 41e62e8..ae126dd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingBroadcastTableRuleStatementUpdater.java
@@ -15,31 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRuleNotExistsException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBroadcastTableRulesStatement;
/**
- * Drop sharding broadcast table rules backend handler.
+ * Drop sharding broadcast table rule statement updater.
*/
-public final class DropShardingBroadcastTableRulesBackendHandler extends RDLBackendHandler<DropShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
-
- public DropShardingBroadcastTableRulesBackendHandler(final DropShardingBroadcastTableRulesStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropShardingBroadcastTableRuleStatementUpdater implements RDLUpdater<DropShardingBroadcastTableRulesStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
if (null == currentRuleConfig || currentRuleConfig.getBroadcastTables().isEmpty()) {
throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
}
}
@Override
- public void doExecute(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
currentRuleConfig.getBroadcastTables().clear();
}
+
+ @Override
+ public String getType() {
+ return DropShardingBroadcastTableRulesStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingTableRuleStatementUpdater.java
similarity index 83%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingTableRuleStatementUpdater.java
index b61ac03..56c2d84 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/DropShardingTableRuleStatementUpdater.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
import com.google.common.base.Splitter;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.infra.distsql.RDLUpdater;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.exception.ShardingTableRulesInUsedException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -32,16 +33,13 @@ import java.util.LinkedList;
import java.util.stream.Collectors;
/**
- * Drop sharding table rule backend handler.
+ * Drop sharding table rule statement updater.
*/
-public final class DropShardingTableRuleBackendHandler extends RDLBackendHandler<DropShardingTableRuleStatement, ShardingRuleConfiguration> {
-
- public DropShardingTableRuleBackendHandler(final DropShardingTableRuleStatement sqlStatement, final BackendConnection backendConnection) {
- super(sqlStatement, backendConnection);
- }
+public final class DropShardingTableRuleStatementUpdater implements RDLUpdater<DropShardingTableRuleStatement, ShardingRuleConfiguration> {
@Override
- public void check(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void checkSQLStatement(final String schemaName, final DropShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
Collection<String> tableNames = sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
if (null == currentRuleConfig) {
throw new ShardingTableRuleNotExistedException(schemaName, tableNames);
@@ -59,7 +57,7 @@ public final class DropShardingTableRuleBackendHandler extends RDLBackendHandler
}
@Override
- public void doExecute(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ public void updateCurrentRuleConfiguration(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
for (String each : getDroppedTables(sqlStatement)) {
dropShardingTable(currentRuleConfig, each);
}
@@ -86,4 +84,9 @@ public final class DropShardingTableRuleBackendHandler extends RDLBackendHandler
shardingRuleConfig.getBindingTableGroups().forEach(each -> result.addAll(Splitter.on(",").splitToList(each)));
return result;
}
+
+ @Override
+ public String getType() {
+ return DropShardingTableRuleStatement.class.getCanonicalName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.RDLUpdater b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.RDLUpdater
new file mode 100644
index 0000000..80a92f3
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.RDLUpdater
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateShardingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterShardingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropShardingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateShardingBindingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterShardingBindingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropShardingBindingTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateShardingBroadcastTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterShardingBroadcastTableRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropShardingBroadcastTableRuleStatementUpdater
+
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateReadwriteSplittingRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterReadwriteSplittingRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropReadwriteSplittingRuleStatementUpdater
+
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateDatabaseDiscoveryRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterDatabaseDiscoveryRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropDatabaseDiscoveryRuleStatementUpdater
+
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.CreateEncryptRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.AlterEncryptRuleStatementUpdater
+org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater.DropEncryptRuleStatementUpdater
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
index fb25973..585c06c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -64,6 +64,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -282,6 +283,7 @@ public final class DistSQLBackendHandlerFactoryTest {
when(mockedMetaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("schema"));
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
+ when(metaData.getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
when(mockedMetaDataContexts.getMetaData("schema")).thenReturn(metaData);
metaDataContexts.set(ProxyContext.getInstance(), mockedMetaDataContexts);
} else {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
index 8b2e683..a217d38 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import com.google.common.collect.Maps;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
@@ -39,21 +39,17 @@ import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -71,7 +67,7 @@ public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
@Mock
private TransactionContexts transactionContexts;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereMetaData shardingSphereMetaData;
@Mock
@@ -90,7 +86,7 @@ public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
- when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
+ when(metaDataContexts.getMetaData("test")).thenReturn(shardingSphereMetaData);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
}
@@ -102,9 +98,6 @@ public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
Collections.singleton(new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration)), Maps.newHashMap())));
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -142,9 +135,6 @@ public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
Collections.singleton(new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration), Collections.emptyMap())));
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
handler.execute("test", sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
index c8cd190..32a8651 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
@@ -38,22 +38,19 @@ import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -71,7 +68,7 @@ public final class AlterReadwriteSplittingRuleBackendHandlerTest {
@Mock
private TransactionContexts transactionContexts;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereMetaData shardingSphereMetaData;
@Mock
@@ -102,9 +99,6 @@ public final class AlterReadwriteSplittingRuleBackendHandlerTest {
Collections.singleton(new ReadwriteSplittingRuleConfiguration(new LinkedList<>(Collections.singleton(readwriteSplittingDataSourceRuleConfiguration)), new LinkedHashMap<>())));
when(readwriteSplittingDataSourceRuleConfiguration.getName()).thenReturn("pr_ds");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -143,9 +137,6 @@ public final class AlterReadwriteSplittingRuleBackendHandlerTest {
Collections.singleton(new ReadwriteSplittingRuleConfiguration(Collections.singleton(readwriteSplittingDataSourceRuleConfiguration), Collections.emptyMap())));
when(readwriteSplittingDataSourceRuleConfiguration.getName()).thenReturn("pr_ds");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
handler.execute("test", sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
index b5d122f..161d5d6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
-import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -36,6 +34,8 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
+import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
@@ -43,19 +43,16 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -90,6 +87,7 @@ public final class AlterShardingTableRuleBackendHandlerTest {
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
+ when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
}
@Test(expected = ShardingTableRuleNotExistedException.class)
@@ -102,10 +100,7 @@ public final class AlterShardingTableRuleBackendHandlerTest {
TableRuleSegment tableRuleSegment = new TableRuleSegment("t_order", Collections.singleton("ds_0"), "order_id", new AlgorithmSegment("hash_mod", new Properties()), null, null);
when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(tableRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
+ when(shardingSphereResource.getNotExistedResources(any())).thenReturn(Collections.emptyList());
handler.execute("test", sqlStatement);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java
index 760731f..07ce1c0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import com.google.common.collect.Maps;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
@@ -39,20 +39,17 @@ import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -70,7 +67,7 @@ public final class CreateDatabaseDiscoveryRuleBackendHandlerTest {
@Mock
private TransactionContexts transactionContexts;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereMetaData shardingSphereMetaData;
@Mock
@@ -95,9 +92,6 @@ public final class CreateDatabaseDiscoveryRuleBackendHandlerTest {
DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -126,9 +120,6 @@ public final class CreateDatabaseDiscoveryRuleBackendHandlerTest {
DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), "notExistDiscoveryType", new Properties());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
handler.execute("test", sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java
index 98c7a44..c42251a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java
@@ -38,23 +38,20 @@ import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -72,7 +69,7 @@ public final class CreateReadwriteSplittingRuleBackendHandlerTest {
@Mock
private TransactionContexts transactionContexts;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereMetaData shardingSphereMetaData;
@Mock
@@ -97,9 +94,6 @@ public final class CreateReadwriteSplittingRuleBackendHandlerTest {
ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -127,9 +121,6 @@ public final class CreateReadwriteSplittingRuleBackendHandlerTest {
ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -148,9 +139,6 @@ public final class CreateReadwriteSplittingRuleBackendHandlerTest {
"pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "notExistLoadBalancer", new Properties());
when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- Map<String, DataSource> dataSourceMap = mock(Map.class);
- when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
- when(dataSourceMap.containsKey(anyString())).thenReturn(true);
handler.execute("test", sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
index e7d5d92..ff91685 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
@@ -18,10 +18,9 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
-import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -30,6 +29,8 @@ import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesExceptio
import org.apache.shardingsphere.proxy.backend.exception.InvalidShardingAlgorithmsException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
+import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +44,8 @@ import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -76,7 +78,10 @@ public final class CreateShardingTableRuleBackendHandlerTest {
public void setUp() {
ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
- when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
+ when(metaDataContexts.getMetaData("test")).thenReturn(shardingSphereMetaData);
+ ShardingSphereResource shardingSphereResource = mock(ShardingSphereResource.class);
+ when(shardingSphereResource.getNotExistedResources(any())).thenReturn(Collections.emptyList());
+ when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
when(shardingSphereMetaData.getSchema()).thenReturn(shardingSphereSchema);
when(shardingSphereSchema.getAllTableNames()).thenReturn(Collections.singleton("t_order"));
@@ -84,7 +89,6 @@ public final class CreateShardingTableRuleBackendHandlerTest {
@Test
public void assertExecute() {
- TableRuleSegment tableRuleSegment = new TableRuleSegment("t_order_item", Collections.emptyList(), null, new AlgorithmSegment("hash_mod", new Properties()), null, null);
ResponseHeader responseHeader = handler.execute("test", sqlStatement);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);