You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/05/25 03:02:03 UTC
[shardingsphere] branch master updated: fixed #10421 (#10444)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 2cc4ac3 fixed #10421 (#10444)
2cc4ac3 is described below
commit 2cc4ac3491f1eb1dfd2320d66a2daf386b08aba6
Author: totalo <48...@qq.com>
AuthorDate: Tue May 25 10:59:52 2021 +0800
fixed #10421 (#10444)
---
.../impl/CreateShardingTableRuleBackendHandler.java | 13 +------------
.../CreateShardingTableRuleBackendHandlerTest.java | 21 ++++++---------------
2 files changed, 7 insertions(+), 27 deletions(-)
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 352d26f..377f8ba 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
@@ -30,18 +30,14 @@ import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
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 java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
/**
* Create sharding table rule backend handler.
@@ -85,14 +81,7 @@ public final class CreateShardingTableRuleBackendHandler extends SchemaRequiredB
}
private Collection<String> getLogicTables(final String schemaName) {
- Optional<ShardingRuleConfiguration> shardingRuleConfiguration = getShardingRuleConfiguration(schemaName);
- Collection<String> result = new LinkedList<>();
- if (!shardingRuleConfiguration.isPresent()) {
- return result;
- }
- result.addAll(shardingRuleConfiguration.get().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- result.addAll(shardingRuleConfiguration.get().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
- return result;
+ return ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
}
private Optional<ShardingRuleConfiguration> getShardingRuleConfiguration(final String schemaName) {
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 163b0c4..dba326f 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
@@ -19,18 +19,15 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
import org.apache.shardingsphere.distsql.parser.segment.TableRuleSegment;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingTableRuleStatement;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
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;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-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.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
@@ -38,9 +35,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import static org.junit.Assert.assertNotNull;
@@ -68,6 +63,9 @@ public final class CreateShardingTableRuleBackendHandlerTest {
@Mock
private ShardingSphereRuleMetaData ruleMetaData;
+
+ @Mock
+ private ShardingSphereSchema shardingSphereSchema;
private CreateShardingTableRuleBackendHandler handler = new CreateShardingTableRuleBackendHandler(sqlStatement, backendConnection);
@@ -77,6 +75,8 @@ public final class CreateShardingTableRuleBackendHandlerTest {
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
+ when(shardingSphereMetaData.getSchema()).thenReturn(shardingSphereSchema);
+ when(shardingSphereSchema.getAllTableNames()).thenReturn(Collections.singletonList("t_order"));
}
@Test
@@ -90,7 +90,6 @@ public final class CreateShardingTableRuleBackendHandlerTest {
public void assertExecuteWithDuplicateTablesInRDL() {
TableRuleSegment tableRuleSegment = new TableRuleSegment();
tableRuleSegment.setLogicTable("t_order");
- when(ruleMetaData.getConfigurations()).thenReturn(new ArrayList<>());
when(sqlStatement.getTables()).thenReturn(Arrays.asList(tableRuleSegment, tableRuleSegment));
handler.execute("test", sqlStatement);
}
@@ -99,15 +98,7 @@ public final class CreateShardingTableRuleBackendHandlerTest {
public void assertExecuteWithDuplicateTables() {
TableRuleSegment tableRuleSegment = new TableRuleSegment();
tableRuleSegment.setLogicTable("t_order");
- when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
when(sqlStatement.getTables()).thenReturn(Collections.singletonList(tableRuleSegment));
handler.execute("test", sqlStatement);
}
-
- private Collection<RuleConfiguration> buildShardingConfigurations() {
- ShardingRuleConfiguration configuration = new ShardingRuleConfiguration();
- configuration.getTables().add(new ShardingTableRuleConfiguration("t_order"));
- configuration.getAutoTables().add(new ShardingAutoTableRuleConfiguration("t_order"));
- return new ArrayList<>(Collections.singletonList(configuration));
- }
}