This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 19d73be6728 Decouple RuleMetaData.configuration of
ShardingBindingTableRuleQueryResultSet (#18548)
19d73be6728 is described below
commit 19d73be6728ec70bf17356b88e5d7584b28e6756
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jun 23 22:36:01 2022 +0800
Decouple RuleMetaData.configuration of
ShardingBindingTableRuleQueryResultSet (#18548)
---
.../query/ShardingBindingTableRuleQueryResultSet.java | 8 ++++----
.../query/ShardingBindingTableRuleQueryResultSetTest.java | 14 +++++++++++---
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java
index d07ffc68b5e..d59cc173ef0 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBindingTableRulesStatement;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Collection;
@@ -37,9 +38,8 @@ public final class ShardingBindingTableRuleQueryResultSet
implements DistSQLResu
@Override
public void init(final ShardingSphereDatabase database, final SQLStatement
sqlStatement) {
- Optional<ShardingRuleConfiguration> shardingRuleConfig =
database.getRuleMetaData().getConfigurations()
- .stream().filter(each -> each instanceof
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration)
each).findFirst();
- data = shardingRuleConfig.map(each ->
each.getBindingTableGroups().iterator()).orElseGet(Collections::emptyIterator);
+ Optional<ShardingRule> rule =
database.getRuleMetaData().findSingleRule(ShardingRule.class);
+ data = rule.map(optional -> ((ShardingRuleConfiguration)
optional.getConfiguration()).getBindingTableGroups().iterator()).orElseGet(Collections::emptyIterator);
}
@Override
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java
index 2c7f386caf0..60f2fc99798 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java
@@ -23,10 +23,12 @@ import
org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.distsql.handler.query.ShardingBindingTableRuleQueryResultSet;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBindingTableRulesStatement;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
+import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -39,15 +41,21 @@ public final class
ShardingBindingTableRuleQueryResultSetTest {
@Test
public void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
-
when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration()));
ShardingBindingTableRuleQueryResultSet resultSet = new
ShardingBindingTableRuleQueryResultSet();
- resultSet.init(database,
mock(ShowShardingBindingTableRulesStatement.class));
+ resultSet.init(mockDatabase(),
mock(ShowShardingBindingTableRulesStatement.class));
Collection<Object> actual = resultSet.getRowData();
assertThat(actual.size(), is(1));
assertTrue(actual.contains("t_order,t_order_item"));
}
+ private ShardingSphereDatabase mockDatabase() {
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+
when(result.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
+ return result;
+ }
+
private RuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(new ShardingTableRuleConfiguration("t_order"));