You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2024/01/21 06:40:04 UTC
(shardingsphere) branch master updated: Add DatabaseRuleAwareRQLExecutor (#29794)
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 db35e1bc44d Add DatabaseRuleAwareRQLExecutor (#29794)
db35e1bc44d is described below
commit db35e1bc44d8bd76e358a95d4b4899282d37e43d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jan 21 14:39:57 2024 +0800
Add DatabaseRuleAwareRQLExecutor (#29794)
* Add DatabaseRuleAwareRQLExecutor
* Add DatabaseRuleAwareRQLExecutor
* Add DatabaseRuleAwareRQLExecutor
* Add DatabaseRuleAwareRQLExecutor
---
.../query/ShowBroadcastTableRuleExecutor.java | 18 ++++++----
.../query/ShowBroadcastTableRuleExecutorTest.java | 34 +-----------------
.../handler/query/ShowEncryptRuleExecutor.java | 18 ++++++----
.../handler/query/ShowEncryptRuleExecutorTest.java | 35 ++----------------
.../handler/query/ShowMaskRuleExecutor.java | 18 ++++++----
.../handler/query/ShowMaskRuleExecutorTest.java | 40 ++-------------------
.../query/ShowReadwriteSplittingRuleExecutor.java | 18 ++++++----
.../ShowReadwriteSplittingRuleExecutorTest.java | 41 ++--------------------
.../query/ShowDefaultShadowAlgorithmExecutor.java | 18 ++++++----
.../query/ShowShadowAlgorithmsExecutor.java | 18 ++++++----
.../handler/query/ShowShadowRuleExecutor.java | 18 ++++++----
.../query/ShowShadowTableRulesExecutor.java | 18 ++++++----
.../ShowDefaultShadowAlgorithmExecutorTest.java | 27 ++------------
.../query/ShowShadowAlgorithmsExecutorTest.java | 28 ++-------------
.../distsql/query/ShowShadowRuleExecutorTest.java | 30 ++--------------
.../query/ShowShadowTableRulesExecutorTest.java | 26 ++------------
.../query/ShowDefaultShardingStrategyExecutor.java | 18 ++++++----
.../query/ShowShardingAlgorithmExecutor.java | 18 ++++++----
.../query/ShowShardingAuditorsExecutor.java | 18 ++++++----
.../query/ShowShardingKeyGeneratorExecutor.java | 18 ++++++----
.../query/ShowShardingTableNodesExecutor.java | 18 ++++++----
.../ShowShardingTableReferenceRuleExecutor.java | 18 ++++++----
.../query/ShowShardingTableRuleExecutor.java | 18 ++++++----
...howShardingTableRulesUsedAlgorithmExecutor.java | 18 ++++++----
.../ShowShardingTableRulesUsedAuditorExecutor.java | 18 ++++++----
...ShardingTableRulesUsedKeyGeneratorExecutor.java | 18 ++++++----
.../ShowUnusedShardingAlgorithmsExecutor.java | 18 ++++++----
.../query/ShowUnusedShardingAuditorsExecutor.java | 18 ++++++----
.../ShowUnusedShardingKeyGeneratorExecutor.java | 18 ++++++----
.../ShowDefaultShardingStrategyExecutorTest.java | 26 ++------------
.../query/ShowShardingAlgorithmExecutorTest.java | 39 ++------------------
.../query/ShowShardingAuditorsExecutorTest.java | 20 +----------
.../ShowShardingKeyGeneratorExecutorTest.java | 22 +-----------
.../query/ShowShardingTableNodesExecutorTest.java | 38 ++++++--------------
...ShowShardingTableReferenceRuleExecutorTest.java | 31 ++++------------
.../query/ShowShardingTableRuleExecutorTest.java | 40 ++-------------------
...hardingTableRulesUsedAlgorithmExecutorTest.java | 19 +---------
...wShardingTableRulesUsedAuditorExecutorTest.java | 18 +---------
...dingTableRulesUsedKeyGeneratorExecutorTest.java | 19 +---------
.../ShowUnusedShardingAlgorithmsExecutorTest.java | 28 ++-------------
.../ShowUnusedShardingAuditorsExecutorTest.java | 27 ++------------
...ShowUnusedShardingKeyGeneratorExecutorTest.java | 28 ++-------------
.../DatabaseRuleAwareRQLExecutor.java} | 36 +++++++++----------
.../ShowDefaultSingleTableStorageUnitExecutor.java | 20 ++++++-----
.../handler/query/ShowSingleTableExecutor.java | 18 ++++++----
.../query/ShowUnloadedSingleTableExecutor.java | 19 ++++++----
...wDefaultSingleTableStorageUnitExecutorTest.java | 24 ++-----------
.../handler/query/ShowSingleTableExecutorTest.java | 41 ++++------------------
.../handler/distsql/rql/RQLBackendHandler.java | 23 ++++++++++--
49 files changed, 374 insertions(+), 801 deletions(-)
diff --git a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutor.java b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutor.java
index f823d9ad65e..e74ed1d9216 100644
--- a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutor.java
+++ b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutor.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.broadcast.distsql.handler.query;
+import lombok.Setter;
import org.apache.shardingsphere.broadcast.distsql.statement.ShowBroadcastTableRulesStatement;
import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import java.util.Collection;
import java.util.Collections;
@@ -30,11 +30,10 @@ import java.util.stream.Collectors;
/**
* Show broadcast table rule executor.
*/
-public final class ShowBroadcastTableRuleExecutor extends RuleAwareRQLExecutor<ShowBroadcastTableRulesStatement, BroadcastRule> {
+@Setter
+public final class ShowBroadcastTableRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowBroadcastTableRulesStatement, BroadcastRule> {
- public ShowBroadcastTableRuleExecutor() {
- super(BroadcastRule.class);
- }
+ private BroadcastRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -42,10 +41,15 @@ public final class ShowBroadcastTableRuleExecutor extends RuleAwareRQLExecutor<S
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowBroadcastTableRulesStatement sqlStatement, final BroadcastRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowBroadcastTableRulesStatement sqlStatement) {
return rule.getConfiguration().getTables().stream().map(LocalDataQueryResultRow::new).collect(Collectors.toList());
}
+ @Override
+ public Class<BroadcastRule> getRuleClass() {
+ return BroadcastRule.class;
+ }
+
@Override
public Class<ShowBroadcastTableRulesStatement> getType() {
return ShowBroadcastTableRulesStatement.class;
diff --git a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutorTest.java b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutorTest.java
index fe8d21b6c0c..70eb33aa456 100644
--- a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutorTest.java
+++ b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/query/ShowBroadcastTableRuleExecutorTest.java
@@ -20,21 +20,15 @@ package org.apache.shardingsphere.broadcast.distsql.handler.query;
import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
import org.apache.shardingsphere.broadcast.distsql.statement.ShowBroadcastTableRulesStatement;
import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,7 +37,7 @@ class ShowBroadcastTableRuleExecutorTest {
@Test
void assertGetRowData() {
ShowBroadcastTableRuleExecutor executor = new ShowBroadcastTableRuleExecutor();
- executor.setDatabase(mockDatabase());
+ executor.setRule(mockBroadcastRule());
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowBroadcastTableRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -51,32 +45,6 @@ class ShowBroadcastTableRuleExecutorTest {
assertThat(row.getCell(1), is("t_address"));
}
- @Test
- void assertGetRowDataWithoutBroadcastRule() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getRuleMetaData().findSingleRule(BroadcastRule.class)).thenReturn(Optional.empty());
- ShowBroadcastTableRuleExecutor executor = new ShowBroadcastTableRuleExecutor();
- executor.setDatabase(database);
- Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowBroadcastTableRulesStatement.class));
- assertTrue(actual.isEmpty());
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowBroadcastTableRulesStatement> executor = new ShowBroadcastTableRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(1));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("broadcast_table"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
- RuleMetaData ruleMetaData = new RuleMetaData(Collections.singleton(mockBroadcastRule()));
- when(result.getRuleMetaData()).thenReturn(ruleMetaData);
- return result;
- }
-
private BroadcastRule mockBroadcastRule() {
BroadcastRule result = mock(BroadcastRule.class);
BroadcastRuleConfiguration config = mock(BroadcastRuleConfiguration.class);
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
index 7f80aeba782..c9eaa69d354 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.encrypt.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
@@ -26,7 +27,6 @@ import org.apache.shardingsphere.encrypt.distsql.statement.ShowEncryptRulesState
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import java.util.Arrays;
@@ -38,11 +38,10 @@ import java.util.stream.Collectors;
/**
* Show encrypt rule executor.
*/
-public final class ShowEncryptRuleExecutor extends RuleAwareRQLExecutor<ShowEncryptRulesStatement, EncryptRule> {
+@Setter
+public final class ShowEncryptRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowEncryptRulesStatement, EncryptRule> {
- public ShowEncryptRuleExecutor() {
- super(EncryptRule.class);
- }
+ private EncryptRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -51,7 +50,7 @@ public final class ShowEncryptRuleExecutor extends RuleAwareRQLExecutor<ShowEncr
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowEncryptRulesStatement sqlStatement, final EncryptRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowEncryptRulesStatement sqlStatement) {
EncryptRuleConfiguration ruleConfig = (EncryptRuleConfiguration) rule.getConfiguration();
return buildData(ruleConfig, sqlStatement);
}
@@ -88,6 +87,11 @@ public final class ShowEncryptRuleExecutor extends RuleAwareRQLExecutor<ShowEncr
return null == obj ? "" : obj;
}
+ @Override
+ public Class<EncryptRule> getRuleClass() {
+ return EncryptRule.class;
+ }
+
@Override
public Class<ShowEncryptRulesStatement> getType() {
return ShowEncryptRulesStatement.class;
diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
index b6130c6d80f..c8bfc4def37 100644
--- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
+++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.encrypt.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
@@ -27,8 +26,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.junit.jupiter.api.Test;
import java.util.Collection;
@@ -38,7 +35,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,7 +43,9 @@ class ShowEncryptRuleExecutorTest {
@Test
void assertGetRowData() {
ShowEncryptRuleExecutor executor = new ShowEncryptRuleExecutor();
- executor.setDatabase(mockDatabase());
+ EncryptRule rule = mock(EncryptRule.class);
+ when(rule.getConfiguration()).thenReturn(getRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowEncryptRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -65,33 +63,6 @@ class ShowEncryptRuleExecutorTest {
assertThat(row.getCell(11), is(""));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowEncryptRulesStatement> executor = new ShowEncryptRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(11));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("table"));
- assertThat(iterator.next(), is("logic_column"));
- assertThat(iterator.next(), is("cipher_column"));
- assertThat(iterator.next(), is("assisted_query_column"));
- assertThat(iterator.next(), is("like_query_column"));
- assertThat(iterator.next(), is("encryptor_type"));
- assertThat(iterator.next(), is("encryptor_props"));
- assertThat(iterator.next(), is("assisted_query_type"));
- assertThat(iterator.next(), is("assisted_query_props"));
- assertThat(iterator.next(), is("like_query_type"));
- assertThat(iterator.next(), is("like_query_props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- EncryptRule rule = mock(EncryptRule.class);
- when(rule.getConfiguration()).thenReturn(getRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private RuleConfiguration getRuleConfiguration() {
EncryptColumnRuleConfiguration encryptColumnRuleConfig = new EncryptColumnRuleConfiguration("user_id", new EncryptColumnItemRuleConfiguration("user_cipher", "test"));
encryptColumnRuleConfig.setAssistedQuery(new EncryptColumnItemRuleConfiguration("user_assisted", "foo_assist_query_encryptor"));
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
index f776496cd31..51f7f012891 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.mask.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.distsql.statement.ShowMaskRulesStatement;
@@ -35,11 +35,10 @@ import java.util.stream.Collectors;
/**
* Show mask rule executor.
*/
-public final class ShowMaskRuleExecutor extends RuleAwareRQLExecutor<ShowMaskRulesStatement, MaskRule> {
+@Setter
+public final class ShowMaskRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowMaskRulesStatement, MaskRule> {
- public ShowMaskRuleExecutor() {
- super(MaskRule.class);
- }
+ private MaskRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -47,7 +46,7 @@ public final class ShowMaskRuleExecutor extends RuleAwareRQLExecutor<ShowMaskRul
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowMaskRulesStatement sqlStatement, final MaskRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowMaskRulesStatement sqlStatement) {
return rule.getConfiguration().getTables().stream().filter(each -> null == sqlStatement.getTableName() || each.getName().equals(sqlStatement.getTableName()))
.map(each -> buildColumnData(each, rule.getConfiguration().getMaskAlgorithms())).flatMap(Collection::stream).collect(Collectors.toList());
}
@@ -62,6 +61,11 @@ public final class ShowMaskRuleExecutor extends RuleAwareRQLExecutor<ShowMaskRul
return result;
}
+ @Override
+ public Class<MaskRule> getRuleClass() {
+ return MaskRule.class;
+ }
+
@Override
public Class<ShowMaskRulesStatement> getType() {
return ShowMaskRulesStatement.class;
diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
index 005f9dd89d4..93dae8d5147 100644
--- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.mask.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
@@ -32,13 +29,10 @@ import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,7 +41,9 @@ class ShowMaskRuleExecutorTest {
@Test
void assertGetRowData() {
ShowMaskRuleExecutor executor = new ShowMaskRuleExecutor();
- executor.setDatabase(mockDatabase());
+ MaskRule rule = mock(MaskRule.class);
+ when(rule.getConfiguration()).thenReturn(getRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowMaskRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -58,36 +54,6 @@ class ShowMaskRuleExecutorTest {
assertThat(row.getCell(4), is(""));
}
- @Test
- void assertGetRowDataWithoutMaskRule() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getRuleMetaData().findSingleRule(MaskRule.class)).thenReturn(Optional.empty());
- ShowMaskRuleExecutor executor = new ShowMaskRuleExecutor();
- executor.setDatabase(database);
- Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowMaskRulesStatement.class));
- assertTrue(actual.isEmpty());
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowMaskRulesStatement> executor = new ShowMaskRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(4));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("table"));
- assertThat(iterator.next(), is("column"));
- assertThat(iterator.next(), is("algorithm_type"));
- assertThat(iterator.next(), is("algorithm_props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- MaskRule rule = mock(MaskRule.class);
- when(rule.getConfiguration()).thenReturn(getRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private MaskRuleConfiguration getRuleConfiguration() {
MaskColumnRuleConfiguration maskColumnRuleConfig = new MaskColumnRuleConfiguration("user_id", "t_mask_user_id_md5");
MaskTableRuleConfiguration maskTableRuleConfig = new MaskTableRuleConfiguration("t_mask", Collections.singleton(maskColumnRuleConfig));
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
index 243b49e9be2..aba147f221e 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import com.google.common.base.Joiner;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
@@ -40,11 +40,10 @@ import java.util.Optional;
/**
* Show readwrite-splitting rule executor.
*/
-public final class ShowReadwriteSplittingRuleExecutor extends RuleAwareRQLExecutor<ShowReadwriteSplittingRulesStatement, ReadwriteSplittingRule> {
+@Setter
+public final class ShowReadwriteSplittingRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowReadwriteSplittingRulesStatement, ReadwriteSplittingRule> {
- public ShowReadwriteSplittingRuleExecutor() {
- super(ReadwriteSplittingRule.class);
- }
+ private ReadwriteSplittingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -52,7 +51,7 @@ public final class ShowReadwriteSplittingRuleExecutor extends RuleAwareRQLExecut
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowReadwriteSplittingRulesStatement sqlStatement, final ReadwriteSplittingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowReadwriteSplittingRulesStatement sqlStatement) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Map<String, Map<String, String>> exportableDataSourceMap = getExportableDataSourceMap(rule);
ReadwriteSplittingRuleConfiguration ruleConfig = rule.getConfiguration();
@@ -96,6 +95,11 @@ public final class ShowReadwriteSplittingRuleExecutor extends RuleAwareRQLExecut
return null == exportDataSources ? Joiner.on(",").join(dataSourceRuleConfig.getReadDataSourceNames()) : exportDataSources.get(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES);
}
+ @Override
+ public Class<ReadwriteSplittingRule> getRuleClass() {
+ return ReadwriteSplittingRule.class;
+ }
+
@Override
public Class<ShowReadwriteSplittingRulesStatement> getType() {
return ShowReadwriteSplittingRulesStatement.class;
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
index 30fcd755e5a..221c19ddee8 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -40,32 +37,18 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class ShowReadwriteSplittingRuleExecutorTest {
- @Test
- void assertGetEmptyRule() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList()));
- ShowReadwriteSplittingRuleExecutor executor = new ShowReadwriteSplittingRuleExecutor();
- executor.setDatabase(database);
- Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowReadwriteSplittingRulesStatement.class));
- assertTrue(actual.isEmpty());
- }
-
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
when(rule.getExportData()).thenReturn(createExportedData());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowReadwriteSplittingRuleExecutor executor = new ShowReadwriteSplittingRuleExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowReadwriteSplittingRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -80,13 +63,11 @@ class ShowReadwriteSplittingRuleExecutorTest {
@Test
void assertGetRowDataWithSpecifiedRuleName() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
when(rule.getExportData()).thenReturn(createExportedData());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowReadwriteSplittingRuleExecutor executor = new ShowReadwriteSplittingRuleExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowReadwriteSplittingRulesStatement("readwrite_ds", null));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -115,13 +96,11 @@ class ShowReadwriteSplittingRuleExecutorTest {
@Test
void assertGetRowDataWithoutLoadBalancer() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfigurationWithoutLoadBalancer());
when(rule.getExportData()).thenReturn(createExportedData());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowReadwriteSplittingRuleExecutor executor = new ShowReadwriteSplittingRuleExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowReadwriteSplittingRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -139,18 +118,4 @@ class ShowReadwriteSplittingRuleExecutorTest {
new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "write_ds", Arrays.asList("read_ds_0", "read_ds_1"), null);
return new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceRuleConfig), null);
}
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowReadwriteSplittingRulesStatement> executor = new ShowReadwriteSplittingRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(6));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("write_storage_unit_name"));
- assertThat(iterator.next(), is("read_storage_unit_names"));
- assertThat(iterator.next(), is("transactional_read_query_strategy"));
- assertThat(iterator.next(), is("load_balancer_type"));
- assertThat(iterator.next(), is("load_balancer_props"));
- }
}
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
index 7fb4473134e..392bb261800 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.shadow.distsql.statement.ShowDefaultShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
@@ -35,11 +35,10 @@ import java.util.stream.Collectors;
/**
* Show default shadow algorithm executor.
*/
-public final class ShowDefaultShadowAlgorithmExecutor extends RuleAwareRQLExecutor<ShowDefaultShadowAlgorithmStatement, ShadowRule> {
+@Setter
+public final class ShowDefaultShadowAlgorithmExecutor implements DatabaseRuleAwareRQLExecutor<ShowDefaultShadowAlgorithmStatement, ShadowRule> {
- public ShowDefaultShadowAlgorithmExecutor() {
- super(ShadowRule.class);
- }
+ private ShadowRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -47,7 +46,7 @@ public final class ShowDefaultShadowAlgorithmExecutor extends RuleAwareRQLExecut
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDefaultShadowAlgorithmStatement sqlStatement, final ShadowRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowDefaultShadowAlgorithmStatement sqlStatement) {
String defaultAlgorithm = rule.getConfiguration().getDefaultShadowAlgorithmName();
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
@@ -61,6 +60,11 @@ public final class ShowDefaultShadowAlgorithmExecutor extends RuleAwareRQLExecut
return null == props ? "" : PropertiesConverter.convert(props);
}
+ @Override
+ public Class<ShadowRule> getRuleClass() {
+ return ShadowRule.class;
+ }
+
@Override
public Class<ShowDefaultShadowAlgorithmStatement> getType() {
return ShowDefaultShadowAlgorithmStatement.class;
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
index 69609153db8..9a92fe23fb4 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.shadow.distsql.statement.ShowShadowAlgorithmsStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
@@ -32,11 +32,10 @@ import java.util.stream.Collectors;
/**
* Show shadow algorithms executor.
*/
-public final class ShowShadowAlgorithmsExecutor extends RuleAwareRQLExecutor<ShowShadowAlgorithmsStatement, ShadowRule> {
+@Setter
+public final class ShowShadowAlgorithmsExecutor implements DatabaseRuleAwareRQLExecutor<ShowShadowAlgorithmsStatement, ShadowRule> {
- public ShowShadowAlgorithmsExecutor() {
- super(ShadowRule.class);
- }
+ private ShadowRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -44,7 +43,7 @@ public final class ShowShadowAlgorithmsExecutor extends RuleAwareRQLExecutor<Sho
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShadowAlgorithmsStatement sqlStatement, final ShadowRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShadowAlgorithmsStatement sqlStatement) {
String defaultAlgorithm = rule.getConfiguration().getDefaultShadowAlgorithmName();
return rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(),
@@ -56,6 +55,11 @@ public final class ShowShadowAlgorithmsExecutor extends RuleAwareRQLExecutor<Sho
return null == props ? "" : PropertiesConverter.convert(props);
}
+ @Override
+ public Class<ShadowRule> getRuleClass() {
+ return ShadowRule.class;
+ }
+
@Override
public Class<ShowShadowAlgorithmsStatement> getType() {
return ShowShadowAlgorithmsStatement.class;
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutor.java
index d6e905289a8..b669fb56ceb 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutor.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
@@ -38,11 +38,10 @@ import java.util.stream.Collectors;
/**
* Show shadow rule executor.
*/
-public final class ShowShadowRuleExecutor extends RuleAwareRQLExecutor<ShowShadowRulesStatement, ShadowRule> {
+@Setter
+public final class ShowShadowRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowShadowRulesStatement, ShadowRule> {
- public ShowShadowRuleExecutor() {
- super(ShadowRule.class);
- }
+ private ShadowRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -50,7 +49,7 @@ public final class ShowShadowRuleExecutor extends RuleAwareRQLExecutor<ShowShado
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShadowRulesStatement sqlStatement, final ShadowRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShadowRulesStatement sqlStatement) {
Map<String, Map<String, ShadowTableConfiguration>> dataSourceTableMap = convertToDataSourceTableMap(rule.getConfiguration().getTables());
Collection<ShadowDataSourceConfiguration> specifiedConfigs = isSpecified(sqlStatement)
? rule.getConfiguration().getDataSources().stream().filter(each -> each.getName().equalsIgnoreCase(sqlStatement.getRuleName())).collect(Collectors.toList())
@@ -82,6 +81,11 @@ public final class ShowShadowRuleExecutor extends RuleAwareRQLExecutor<ShowShado
return result;
}
+ @Override
+ public Class<ShadowRule> getRuleClass() {
+ return ShadowRule.class;
+ }
+
@Override
public Class<ShowShadowRulesStatement> getType() {
return ShowShadowRulesStatement.class;
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutor.java
index c5c1b2e2a19..dc753ad5b89 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutor.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.distsql.statement.ShowShadowTableRulesStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
@@ -34,15 +34,14 @@ import java.util.stream.Collectors;
/**
* Show shadow table rules executor.
*/
-public final class ShowShadowTableRulesExecutor extends RuleAwareRQLExecutor<ShowShadowTableRulesStatement, ShadowRule> {
+@Setter
+public final class ShowShadowTableRulesExecutor implements DatabaseRuleAwareRQLExecutor<ShowShadowTableRulesStatement, ShadowRule> {
private static final String SHADOW_TABLE = "shadow_table";
private static final String SHADOW_ALGORITHM_NAME = "shadow_algorithm_name";
- public ShowShadowTableRulesExecutor() {
- super(ShadowRule.class);
- }
+ private ShadowRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -50,7 +49,7 @@ public final class ShowShadowTableRulesExecutor extends RuleAwareRQLExecutor<Sho
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShadowTableRulesStatement sqlStatement, final ShadowRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShadowTableRulesStatement sqlStatement) {
return buildData(rule.getConfiguration(), sqlStatement).stream()
.map(each -> new LocalDataQueryResultRow(each.get(SHADOW_TABLE), each.get(SHADOW_ALGORITHM_NAME))).collect(Collectors.toList());
}
@@ -85,6 +84,11 @@ public final class ShowShadowTableRulesExecutor extends RuleAwareRQLExecutor<Sho
return null == shadowTables ? "" : String.join(",", shadowTables);
}
+ @Override
+ public Class<ShadowRule> getRuleClass() {
+ return ShadowRule.class;
+ }
+
@Override
public Class<ShowShadowTableRulesStatement> getType() {
return ShowShadowTableRulesStatement.class;
diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java
index 3f2d770a2ee..48c17b5f3fc 100644
--- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java
+++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.shadow.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.query.ShowDefaultShadowAlgorithmExecutor;
@@ -37,7 +34,6 @@ import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,7 +42,9 @@ class ShowDefaultShadowAlgorithmExecutorTest {
@Test
void assertGetRowData() {
ShowDefaultShadowAlgorithmExecutor executor = new ShowDefaultShadowAlgorithmExecutor();
- executor.setDatabase(mockDatabase());
+ ShadowRule rule = mock(ShadowRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowDefaultShadowAlgorithmStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,25 +54,6 @@ class ShowDefaultShadowAlgorithmExecutorTest {
assertThat(row.getCell(3), is("{\"foo\":\"bar\"}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowDefaultShadowAlgorithmStatement> executor = new ShowDefaultShadowAlgorithmExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("shadow_algorithm_name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShadowRule rule = mock(ShadowRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShadowRuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.emptyList(), Collections.singleton("shadowAlgorithmName")));
diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java
index 86a738d9332..18e7ed6760f 100644
--- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java
+++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.shadow.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowAlgorithmsExecutor;
@@ -37,7 +34,6 @@ import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,7 +42,9 @@ class ShowShadowAlgorithmsExecutorTest {
@Test
void assertGetRowData() {
ShowShadowAlgorithmsExecutor executor = new ShowShadowAlgorithmsExecutor();
- executor.setDatabase(mockDatabase());
+ ShadowRule rule = mock(ShadowRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShadowAlgorithmsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -57,26 +55,6 @@ class ShowShadowAlgorithmsExecutorTest {
assertThat(row.getCell(4), is("false"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShadowAlgorithmsStatement> executor = new ShowShadowAlgorithmsExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(4));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("shadow_algorithm_name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- assertThat(iterator.next(), is("is_default"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShadowRule rule = mock(ShadowRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShadowRuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.emptyList(), Collections.singleton("shadowAlgorithmName")));
diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
index 96502b81121..c1558129bbe 100644
--- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
+++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.shadow.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
@@ -37,7 +34,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,7 +42,9 @@ class ShowShadowRuleExecutorTest {
@Test
void assertGetRowData() {
ShowShadowRuleExecutor executor = new ShowShadowRuleExecutor();
- executor.setDatabase(mockDatabase());
+ ShadowRule rule = mock(ShadowRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShadowRulesStatement.class));
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -66,28 +64,6 @@ class ShowShadowRuleExecutorTest {
assertThat(row.getCell(6), is(""));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShadowRulesStatement> executor = new ShowShadowRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(6));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("shadow_table"));
- assertThat(iterator.next(), is("rule_name"));
- assertThat(iterator.next(), is("source_name"));
- assertThat(iterator.next(), is("shadow_name"));
- assertThat(iterator.next(), is("algorithm_type"));
- assertThat(iterator.next(), is("algorithm_props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShadowRule rule = mock(ShadowRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShadowRuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getDataSources().add(new ShadowDataSourceConfiguration("shadow_rule", "source", "shadow"));
diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowTableRulesExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowTableRulesExecutorTest.java
index af8b9be23b5..c1afe67424d 100644
--- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowTableRulesExecutorTest.java
+++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowTableRulesExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.shadow.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowTableRulesExecutor;
@@ -38,7 +35,6 @@ import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,7 +43,9 @@ class ShowShadowTableRulesExecutorTest {
@Test
void assertGetRowData() {
ShowShadowTableRulesExecutor executor = new ShowShadowTableRulesExecutor();
- executor.setDatabase(mockDatabase());
+ ShadowRule rule = mock(ShadowRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShadowTableRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,24 +54,6 @@ class ShowShadowTableRulesExecutorTest {
assertThat(row.getCell(2), is("shadowAlgorithmName_1,shadowAlgorithmName_2"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShadowTableRulesStatement> executor = new ShowShadowTableRulesExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("shadow_table"));
- assertThat(iterator.next(), is("shadow_algorithm_name"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShadowRule rule = mock(ShadowRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShadowRuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.emptyList(), Arrays.asList("shadowAlgorithmName_1", "shadowAlgorithmName_2")));
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
index 8b71ea66eed..8452807a7eb 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.enums.ShardingStrategyType;
@@ -35,11 +35,10 @@ import java.util.LinkedList;
/**
* Show default sharding strategy executor.
*/
-public final class ShowDefaultShardingStrategyExecutor extends RuleAwareRQLExecutor<ShowDefaultShardingStrategyStatement, ShardingRule> {
+@Setter
+public final class ShowDefaultShardingStrategyExecutor implements DatabaseRuleAwareRQLExecutor<ShowDefaultShardingStrategyStatement, ShardingRule> {
- public ShowDefaultShardingStrategyExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -47,7 +46,7 @@ public final class ShowDefaultShardingStrategyExecutor extends RuleAwareRQLExecu
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDefaultShardingStrategyStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowDefaultShardingStrategyStatement sqlStatement) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
result.add(buildDataItem("TABLE", rule.getConfiguration(), rule.getConfiguration().getDefaultTableShardingStrategy()));
result.add(buildDataItem("DATABASE", rule.getConfiguration(), rule.getConfiguration().getDefaultDatabaseShardingStrategy()));
@@ -69,6 +68,11 @@ public final class ShowDefaultShardingStrategyExecutor extends RuleAwareRQLExecu
return new LocalDataQueryResultRow(defaultType, strategyType.toString(), shardingColumn, algorithmName, algorithmConfig.getType(), algorithmConfig.getProps().toString());
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowDefaultShardingStrategyStatement> getType() {
return ShowDefaultShardingStrategyStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAlgorithmExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAlgorithmExecutor.java
index 80cec1f0464..0947e736f74 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAlgorithmExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAlgorithmExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -32,11 +32,10 @@ import java.util.stream.Collectors;
/**
* Show sharding algorithm executor.
*/
-public final class ShowShardingAlgorithmExecutor extends RuleAwareRQLExecutor<ShowShardingAlgorithmsStatement, ShardingRule> {
+@Setter
+public final class ShowShardingAlgorithmExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingAlgorithmsStatement, ShardingRule> {
- public ShowShardingAlgorithmExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -44,7 +43,7 @@ public final class ShowShardingAlgorithmExecutor extends RuleAwareRQLExecutor<Sh
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingAlgorithmsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAlgorithmsStatement sqlStatement) {
return rule.getConfiguration().getShardingAlgorithms().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), buildProps(entry.getValue().getProps()))).collect(Collectors.toList());
}
@@ -53,6 +52,11 @@ public final class ShowShardingAlgorithmExecutor extends RuleAwareRQLExecutor<Sh
return null == props ? "" : PropertiesConverter.convert(props);
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingAlgorithmsStatement> getType() {
return ShowShardingAlgorithmsStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutor.java
index 7976c9e0bac..88979301480 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -31,11 +31,10 @@ import java.util.stream.Collectors;
/**
* Show sharding auditors executor.
*/
-public final class ShowShardingAuditorsExecutor extends RuleAwareRQLExecutor<ShowShardingAuditorsStatement, ShardingRule> {
+@Setter
+public final class ShowShardingAuditorsExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingAuditorsStatement, ShardingRule> {
- public ShowShardingAuditorsExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -43,11 +42,16 @@ public final class ShowShardingAuditorsExecutor extends RuleAwareRQLExecutor<Sho
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingAuditorsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAuditorsStatement sqlStatement) {
return rule.getConfiguration().getAuditors().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingAuditorsStatement> getType() {
return ShowShardingAuditorsStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingKeyGeneratorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingKeyGeneratorExecutor.java
index 64d994eafe5..ff0d63dbc30 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingKeyGeneratorExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingKeyGeneratorExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingKeyGeneratorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -31,11 +31,10 @@ import java.util.stream.Collectors;
/**
* Show sharding key generator executor.
*/
-public final class ShowShardingKeyGeneratorExecutor extends RuleAwareRQLExecutor<ShowShardingKeyGeneratorsStatement, ShardingRule> {
+@Setter
+public final class ShowShardingKeyGeneratorExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingKeyGeneratorsStatement, ShardingRule> {
- public ShowShardingKeyGeneratorExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -43,11 +42,16 @@ public final class ShowShardingKeyGeneratorExecutor extends RuleAwareRQLExecutor
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingKeyGeneratorsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingKeyGeneratorsStatement sqlStatement) {
return rule.getConfiguration().getKeyGenerators().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingKeyGeneratorsStatement> getType() {
return ShowShardingKeyGeneratorsStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutor.java
index 645e43e290b..6141ec76730 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableNodesStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -33,11 +33,10 @@ import java.util.stream.Collectors;
/**
* Show sharding table nodes executor.
*/
-public final class ShowShardingTableNodesExecutor extends RuleAwareRQLExecutor<ShowShardingTableNodesStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableNodesExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableNodesStatement, ShardingRule> {
- public ShowShardingTableNodesExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -45,7 +44,7 @@ public final class ShowShardingTableNodesExecutor extends RuleAwareRQLExecutor<S
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableNodesStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableNodesStatement sqlStatement) {
String tableName = sqlStatement.getTableName();
return null == tableName
? rule.getTableRules().entrySet().stream().map(entry -> new LocalDataQueryResultRow(entry.getKey(), getTableNodes(entry.getValue()))).collect(Collectors.toList())
@@ -56,6 +55,11 @@ public final class ShowShardingTableNodesExecutor extends RuleAwareRQLExecutor<S
return tableRule.getActualDataNodes().stream().map(DataNode::format).collect(Collectors.joining(", "));
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableNodesStatement> getType() {
return ShowShardingTableNodesStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableReferenceRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableReferenceRuleExecutor.java
index e0d81b44bab..a708eb26c50 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableReferenceRuleExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableReferenceRuleExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableReferenceRulesStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -30,11 +30,10 @@ import java.util.stream.Collectors;
/**
* Show sharding table reference rules executor.
*/
-public final class ShowShardingTableReferenceRuleExecutor extends RuleAwareRQLExecutor<ShowShardingTableReferenceRulesStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableReferenceRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableReferenceRulesStatement, ShardingRule> {
- public ShowShardingTableReferenceRuleExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -42,11 +41,16 @@ public final class ShowShardingTableReferenceRuleExecutor extends RuleAwareRQLEx
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableReferenceRulesStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableReferenceRulesStatement sqlStatement) {
return rule.getConfiguration().getBindingTableGroups().stream().filter(each -> null == sqlStatement.getRuleName() || each.getName().equalsIgnoreCase(sqlStatement.getRuleName()))
.map(each -> new LocalDataQueryResultRow(each.getName(), each.getReference())).collect(Collectors.toList());
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableReferenceRulesStatement> getType() {
return ShowShardingTableReferenceRulesStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
index 9b6fe94407a..17b1fb6e4e7 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -43,11 +43,10 @@ import java.util.stream.Collectors;
/**
* Show sharding table rules executor.
*/
-public final class ShowShardingTableRuleExecutor extends RuleAwareRQLExecutor<ShowShardingTableRulesStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableRuleExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableRulesStatement, ShardingRule> {
- public ShowShardingTableRuleExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -57,7 +56,7 @@ public final class ShowShardingTableRuleExecutor extends RuleAwareRQLExecutor<Sh
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableRulesStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableRulesStatement sqlStatement) {
String tableName = sqlStatement.getTableName();
Collection<ShardingTableRuleConfiguration> tables;
Collection<ShardingAutoTableRuleConfiguration> autoTables;
@@ -185,6 +184,11 @@ public final class ShowShardingTableRuleExecutor extends RuleAwareRQLExecutor<Sh
return null == shardingAuditStrategyConfig ? Optional.ofNullable(ruleConfig.getDefaultAuditStrategy()) : Optional.of(shardingAuditStrategyConfig);
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableRulesStatement> getType() {
return ShowShardingTableRulesStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAlgorithmExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAlgorithmExecutor.java
index 2c9dea09830..f3ca2ab01d6 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAlgorithmExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAlgorithmExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableRulesUsedAlgorithmStatement;
@@ -33,11 +33,10 @@ import java.util.LinkedList;
/**
* Show sharding table rules used algorithm executor.
*/
-public final class ShowShardingTableRulesUsedAlgorithmExecutor extends RuleAwareRQLExecutor<ShowShardingTableRulesUsedAlgorithmStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableRulesUsedAlgorithmExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableRulesUsedAlgorithmStatement, ShardingRule> {
- public ShowShardingTableRulesUsedAlgorithmExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -45,7 +44,7 @@ public final class ShowShardingTableRulesUsedAlgorithmExecutor extends RuleAware
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableRulesUsedAlgorithmStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableRulesUsedAlgorithmStatement sqlStatement) {
if (!sqlStatement.getShardingAlgorithmName().isPresent()) {
return Collections.emptyList();
}
@@ -93,6 +92,11 @@ public final class ShowShardingTableRulesUsedAlgorithmExecutor extends RuleAware
return null == tableRuleConfig.getTableShardingStrategy() && matchDefaultTableShardingStrategy;
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableRulesUsedAlgorithmStatement> getType() {
return ShowShardingTableRulesUsedAlgorithmStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
index d376a561d25..f919688eb37 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableRulesUsedAuditorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -31,11 +31,10 @@ import java.util.LinkedList;
/**
* Show sharding table rules used auditor executor.
*/
-public final class ShowShardingTableRulesUsedAuditorExecutor extends RuleAwareRQLExecutor<ShowShardingTableRulesUsedAuditorStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableRulesUsedAuditorExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableRulesUsedAuditorStatement, ShardingRule> {
- public ShowShardingTableRulesUsedAuditorExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -43,7 +42,7 @@ public final class ShowShardingTableRulesUsedAuditorExecutor extends RuleAwareRQ
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableRulesUsedAuditorStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableRulesUsedAuditorStatement sqlStatement) {
if (!sqlStatement.getAuditorName().isPresent()) {
return Collections.emptyList();
}
@@ -61,6 +60,11 @@ public final class ShowShardingTableRulesUsedAuditorExecutor extends RuleAwareRQ
return result;
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableRulesUsedAuditorStatement> getType() {
return ShowShardingTableRulesUsedAuditorStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutor.java
index 2a952b10fe3..4fbd0bce378 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableRulesUsedKeyGeneratorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -31,11 +31,10 @@ import java.util.LinkedList;
/**
* Show sharding table rules used key generator executor.
*/
-public final class ShowShardingTableRulesUsedKeyGeneratorExecutor extends RuleAwareRQLExecutor<ShowShardingTableRulesUsedKeyGeneratorStatement, ShardingRule> {
+@Setter
+public final class ShowShardingTableRulesUsedKeyGeneratorExecutor implements DatabaseRuleAwareRQLExecutor<ShowShardingTableRulesUsedKeyGeneratorStatement, ShardingRule> {
- public ShowShardingTableRulesUsedKeyGeneratorExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -43,7 +42,7 @@ public final class ShowShardingTableRulesUsedKeyGeneratorExecutor extends RuleAw
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowShardingTableRulesUsedKeyGeneratorStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowShardingTableRulesUsedKeyGeneratorStatement sqlStatement) {
if (!sqlStatement.getKeyGeneratorName().isPresent()) {
return Collections.emptyList();
}
@@ -61,6 +60,11 @@ public final class ShowShardingTableRulesUsedKeyGeneratorExecutor extends RuleAw
return result;
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowShardingTableRulesUsedKeyGeneratorStatement> getType() {
return ShowShardingTableRulesUsedKeyGeneratorStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
index 36478d44e7e..bf2b0cc7974 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
@@ -38,11 +38,10 @@ import java.util.Properties;
/**
* Show unused sharding algorithms executor.
*/
-public final class ShowUnusedShardingAlgorithmsExecutor extends RuleAwareRQLExecutor<ShowUnusedShardingAlgorithmsStatement, ShardingRule> {
+@Setter
+public final class ShowUnusedShardingAlgorithmsExecutor implements DatabaseRuleAwareRQLExecutor<ShowUnusedShardingAlgorithmsStatement, ShardingRule> {
- public ShowUnusedShardingAlgorithmsExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -50,7 +49,7 @@ public final class ShowUnusedShardingAlgorithmsExecutor extends RuleAwareRQLExec
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowUnusedShardingAlgorithmsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingAlgorithmsStatement sqlStatement) {
ShardingRuleConfiguration shardingRuleConfig = rule.getConfiguration();
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<String> inUsedAlgorithms = getUsedShardingAlgorithms(shardingRuleConfig);
@@ -88,6 +87,11 @@ public final class ShowUnusedShardingAlgorithmsExecutor extends RuleAwareRQLExec
return null == props ? "" : PropertiesConverter.convert(props);
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowUnusedShardingAlgorithmsStatement> getType() {
return ShowUnusedShardingAlgorithmsStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
index cdf2bf6b9e9..92415b2d801 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
@@ -34,11 +34,10 @@ import java.util.stream.Collectors;
/**
* Show unused sharding auditors executor.
*/
-public final class ShowUnusedShardingAuditorsExecutor extends RuleAwareRQLExecutor<ShowUnusedShardingAuditorsStatement, ShardingRule> {
+@Setter
+public final class ShowUnusedShardingAuditorsExecutor implements DatabaseRuleAwareRQLExecutor<ShowUnusedShardingAuditorsStatement, ShardingRule> {
- public ShowUnusedShardingAuditorsExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -46,7 +45,7 @@ public final class ShowUnusedShardingAuditorsExecutor extends RuleAwareRQLExecut
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowUnusedShardingAuditorsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingAuditorsStatement sqlStatement) {
ShardingRuleConfiguration shardingRuleConfig = rule.getConfiguration();
Collection<String> inUsedAuditors = getUsedAuditors(shardingRuleConfig);
return shardingRuleConfig.getAuditors().entrySet().stream().filter(entry -> !inUsedAuditors.contains(entry.getKey()))
@@ -64,6 +63,11 @@ public final class ShowUnusedShardingAuditorsExecutor extends RuleAwareRQLExecut
return result;
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowUnusedShardingAuditorsStatement> getType() {
return ShowUnusedShardingAuditorsStatement.class;
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
index 203f4948181..c75ddd24e89 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
@@ -36,11 +36,10 @@ import java.util.stream.Collectors;
/**
* Show unused sharding key generator executor.
*/
-public final class ShowUnusedShardingKeyGeneratorExecutor extends RuleAwareRQLExecutor<ShowUnusedShardingKeyGeneratorsStatement, ShardingRule> {
+@Setter
+public final class ShowUnusedShardingKeyGeneratorExecutor implements DatabaseRuleAwareRQLExecutor<ShowUnusedShardingKeyGeneratorsStatement, ShardingRule> {
- public ShowUnusedShardingKeyGeneratorExecutor() {
- super(ShardingRule.class);
- }
+ private ShardingRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -48,7 +47,7 @@ public final class ShowUnusedShardingKeyGeneratorExecutor extends RuleAwareRQLEx
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowUnusedShardingKeyGeneratorsStatement sqlStatement, final ShardingRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingKeyGeneratorsStatement sqlStatement) {
Collection<String> inUsedKeyGenerators = getUsedKeyGenerators(rule.getConfiguration());
return rule.getConfiguration().getKeyGenerators().entrySet().stream().filter(entry -> !inUsedKeyGenerators.contains(entry.getKey()))
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), buildProps(entry.getValue().getProps()))).collect(Collectors.toList());
@@ -69,6 +68,11 @@ public final class ShowUnusedShardingKeyGeneratorExecutor extends RuleAwareRQLEx
return null == props ? "" : PropertiesConverter.convert(props);
}
+ @Override
+ public Class<ShardingRule> getRuleClass() {
+ return ShardingRule.class;
+ }
+
@Override
public Class<ShowUnusedShardingKeyGeneratorsStatement> getType() {
return ShowUnusedShardingKeyGeneratorsStatement.class;
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
index d0905c4da9c..3d3e0529ff7 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ComplexShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration;
@@ -35,12 +32,10 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -48,12 +43,10 @@ class ShowDefaultShardingStrategyExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule1 = mock(ShardingRule.class);
when(rule1.getConfiguration()).thenReturn(createRuleConfiguration1());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule1)));
ShowDefaultShardingStrategyExecutor executor = new ShowDefaultShardingStrategyExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule1);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowDefaultShardingStrategyStatement.class));
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -73,9 +66,8 @@ class ShowDefaultShardingStrategyExecutorTest {
assertThat(row.getCell(6), is("{algorithm-expression=ds_${user_id % 2}}"));
ShardingRule rule2 = mock(ShardingRule.class);
when(rule2.getConfiguration()).thenReturn(createRuleConfiguration2());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule2)));
executor = new ShowDefaultShardingStrategyExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule2);
actual = executor.getRows(mock(ShowDefaultShardingStrategyStatement.class));
assertThat(actual.size(), is(2));
iterator = actual.iterator();
@@ -95,20 +87,6 @@ class ShowDefaultShardingStrategyExecutorTest {
assertThat(row.getCell(6), is("{algorithm-expression=ds_${user_id % 2}}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowDefaultShardingStrategyStatement> executor = new ShowDefaultShardingStrategyExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(6));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("sharding_column"));
- assertThat(iterator.next(), is("sharding_algorithm_name"));
- assertThat(iterator.next(), is("sharding_algorithm_type"));
- assertThat(iterator.next(), is("sharding_algorithm_props"));
- }
-
private ShardingRuleConfiguration createRuleConfiguration1() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java
index ad765e84e4c..cc0cf3f603d 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingAlgorithmExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAlgorithmsStatement;
@@ -31,13 +28,10 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,7 +40,9 @@ class ShowShardingAlgorithmExecutorTest {
@Test
void assertGetRowData() {
ShowShardingAlgorithmExecutor executor = new ShowShardingAlgorithmExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingAlgorithmsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,38 +52,9 @@ class ShowShardingAlgorithmExecutorTest {
assertThat(row.getCell(3), is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}"));
}
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
return result;
}
-
- @Test
- void assertGetRowDataWithoutShardingRule() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList()));
- ShowShardingAlgorithmExecutor executor = new ShowShardingAlgorithmExecutor();
- executor.setDatabase(database);
- Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingAlgorithmsStatement.class));
- assertTrue(actual.isEmpty());
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingAlgorithmsStatement> executor = new ShowShardingAlgorithmExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAuditorsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAuditorsExecutorTest.java
index d943a0b87a6..4fc23ac7757 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAuditorsExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAuditorsExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingAuditorsExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
@@ -31,12 +28,10 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -44,12 +39,10 @@ class ShowShardingAuditorsExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowShardingAuditorsExecutor executor = new ShowShardingAuditorsExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingAuditorsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -59,17 +52,6 @@ class ShowShardingAuditorsExecutorTest {
assertThat(row.getCell(3).toString(), is("{\"key\":\"value\"}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingAuditorsStatement> executor = new ShowShardingAuditorsExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", PropertiesBuilder.build(new Property("key", "value"))));
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingKeyGeneratorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingKeyGeneratorExecutorTest.java
index 8deb489a93f..5d9cd07decb 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingKeyGeneratorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingKeyGeneratorExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingKeyGeneratorExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingKeyGeneratorsStatement;
@@ -31,13 +28,10 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -45,12 +39,10 @@ class ShowShardingKeyGeneratorExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowShardingKeyGeneratorExecutor executor = new ShowShardingKeyGeneratorExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingKeyGeneratorsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -60,18 +52,6 @@ class ShowShardingKeyGeneratorExecutorTest {
assertThat(row.getCell(3), is("{\"key\":\"value\"}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingKeyGeneratorsStatement> executor = new ShowShardingKeyGeneratorExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- assertFalse(iterator.hasNext());
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getKeyGenerators().put("snowflake", new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("key", "value"))));
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
index 05c645bff4e..35345acb866 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
@@ -19,11 +19,8 @@ package org.apache.shardingsphere.sharding.distsql.query;
import lombok.SneakyThrows;
import org.apache.groovy.util.Maps;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -39,26 +36,21 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class ShowShardingTableNodesExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule shardingRule = createShardingRule();
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(shardingRule)));
- assertOrder(database);
- assertOrderItem(database);
- assertAll(database);
+ ShardingRule rule = createShardingRule();
+ assertOrder(rule);
+ assertOrderItem(rule);
+ assertAll(rule);
}
@SneakyThrows(IOException.class)
@@ -71,9 +63,9 @@ class ShowShardingTableNodesExecutorTest {
return new ShardingRule(shardingRuleConfig, Maps.of("ds_1", new MockedDataSource(), "ds_2", new MockedDataSource(), "ds_3", new MockedDataSource()), mock(InstanceContext.class));
}
- private void assertOrder(final ShardingSphereDatabase database) {
+ private void assertOrder(final ShardingRule rule) {
ShowShardingTableNodesExecutor executor = new ShowShardingTableNodesExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowShardingTableNodesStatement("t_order", null));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -82,9 +74,9 @@ class ShowShardingTableNodesExecutorTest {
assertThat(row.getCell(2), is("ds_1.t_order_0, ds_2.t_order_1, ds_1.t_order_2, ds_2.t_order_3, ds_1.t_order_4, ds_2.t_order_5"));
}
- private void assertOrderItem(final ShardingSphereDatabase database) {
+ private void assertOrderItem(final ShardingRule rule) {
ShowShardingTableNodesExecutor executor = new ShowShardingTableNodesExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowShardingTableNodesStatement("t_order_item", null));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -93,9 +85,9 @@ class ShowShardingTableNodesExecutorTest {
assertThat(row.getCell(2), is("ds_2.t_order_item_0, ds_3.t_order_item_1, ds_2.t_order_item_2, ds_3.t_order_item_3, ds_2.t_order_item_4, ds_3.t_order_item_5"));
}
- private void assertAll(final ShardingSphereDatabase database) {
+ private void assertAll(final ShardingRule rule) {
ShowShardingTableNodesExecutor executor = new ShowShardingTableNodesExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowShardingTableNodesStatement(null, null));
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -106,14 +98,4 @@ class ShowShardingTableNodesExecutorTest {
assertThat(row.getCell(1), is("t_order_item"));
assertThat(row.getCell(2), is("ds_2.t_order_item_0, ds_3.t_order_item_1, ds_2.t_order_item_2, ds_3.t_order_item_3, ds_2.t_order_item_4, ds_3.t_order_item_5"));
}
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableNodesStatement> executor = new ShowShardingTableNodesExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("nodes"));
- }
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableReferenceRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableReferenceRuleExecutorTest.java
index a94cb62c40b..c97a4b3e8be 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableReferenceRuleExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableReferenceRuleExecutorTest.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -30,12 +27,10 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -44,7 +39,9 @@ class ShowShardingTableReferenceRuleExecutorTest {
@Test
void assertGetRowData() {
ShowShardingTableReferenceRuleExecutor executor = new ShowShardingTableReferenceRuleExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingTableReferenceRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,7 +53,9 @@ class ShowShardingTableReferenceRuleExecutorTest {
@Test
void assertGetRowDataWithSpecifiedRuleName() {
ShowShardingTableReferenceRuleExecutor executor = new ShowShardingTableReferenceRuleExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowShardingTableReferenceRulesStatement("foo", null));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -65,24 +64,6 @@ class ShowShardingTableReferenceRuleExecutorTest {
assertThat(row.getCell(2), is("t_order,t_order_item"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableReferenceRulesStatement> executor = new ShowShardingTableReferenceRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("sharding_table_reference"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(new ShardingTableRuleConfiguration("t_order", null));
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
index 1de3fd1c61d..7056c58b006 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
@@ -42,7 +39,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,7 +47,9 @@ class ShowShardingTableRuleExecutorTest {
@Test
void assertGetRowData() {
ShowShardingTableRuleExecutor executor = new ShowShardingTableRuleExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingTableRulesStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -74,38 +72,6 @@ class ShowShardingTableRuleExecutorTest {
assertThat(row.getCell(16), is("true"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableRulesStatement> executor = new ShowShardingTableRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(16));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("table"));
- assertThat(iterator.next(), is("actual_data_nodes"));
- assertThat(iterator.next(), is("actual_data_sources"));
- assertThat(iterator.next(), is("database_strategy_type"));
- assertThat(iterator.next(), is("database_sharding_column"));
- assertThat(iterator.next(), is("database_sharding_algorithm_type"));
- assertThat(iterator.next(), is("database_sharding_algorithm_props"));
- assertThat(iterator.next(), is("table_strategy_type"));
- assertThat(iterator.next(), is("table_sharding_column"));
- assertThat(iterator.next(), is("table_sharding_algorithm_type"));
- assertThat(iterator.next(), is("table_sharding_algorithm_props"));
- assertThat(iterator.next(), is("key_generate_column"));
- assertThat(iterator.next(), is("key_generator_type"));
- assertThat(iterator.next(), is("key_generator_props"));
- assertThat(iterator.next(), is("auditor_types"));
- assertThat(iterator.next(), is("allow_hint_disable"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
index 0f65b111692..04c101498f5 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
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;
@@ -36,14 +33,12 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,12 +46,10 @@ class ShowShardingTableRulesUsedAlgorithmExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowShardingTableRulesUsedAlgorithmExecutor executor = new ShowShardingTableRulesUsedAlgorithmExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
ShowShardingTableRulesUsedAlgorithmStatement statement = mock(ShowShardingTableRulesUsedAlgorithmStatement.class);
when(statement.getShardingAlgorithmName()).thenReturn(Optional.of("t_order_inline"));
Collection<LocalDataQueryResultRow> actual = executor.getRows(statement);
@@ -74,16 +67,6 @@ class ShowShardingTableRulesUsedAlgorithmExecutorTest {
assertThat(row.getCell(2), is("t_order_auto"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableRulesUsedAlgorithmStatement> executor = new ShowShardingTableRulesUsedAlgorithmExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("name"));
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
index 71b6589b6ab..e9902e88d39 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
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;
@@ -43,7 +40,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,12 +47,10 @@ class ShowShardingTableRulesUsedAuditorExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowShardingTableRulesUsedAuditorExecutor executor = new ShowShardingTableRulesUsedAuditorExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
ShowShardingTableRulesUsedAuditorStatement statement = mock(ShowShardingTableRulesUsedAuditorStatement.class);
when(statement.getAuditorName()).thenReturn(Optional.of("shardingKeyAudit"));
Collection<LocalDataQueryResultRow> actual = executor.getRows(statement);
@@ -70,16 +64,6 @@ class ShowShardingTableRulesUsedAuditorExecutorTest {
assertThat(row.getCell(2), is("t_order_auto"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableRulesUsedAuditorStatement> executor = new ShowShardingTableRulesUsedAuditorExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("name"));
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
index bac59b5bc53..5b25b56c3f1 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
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;
@@ -36,14 +33,12 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,12 +46,10 @@ class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
@Test
void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
ShowShardingTableRulesUsedKeyGeneratorExecutor executor = new ShowShardingTableRulesUsedKeyGeneratorExecutor();
- executor.setDatabase(database);
+ executor.setRule(rule);
ShowShardingTableRulesUsedKeyGeneratorStatement statement = mock(ShowShardingTableRulesUsedKeyGeneratorStatement.class);
when(statement.getKeyGeneratorName()).thenReturn(Optional.of("snowflake"));
Collection<LocalDataQueryResultRow> actual = executor.getRows(statement);
@@ -70,16 +63,6 @@ class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
assertThat(row.getCell(2), is("t_order_auto"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowShardingTableRulesUsedKeyGeneratorStatement> executor = new ShowShardingTableRulesUsedKeyGeneratorExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("name"));
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java
index 4287bd213ca..2667b5a7df9 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
@@ -33,12 +30,10 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,7 +42,9 @@ class ShowUnusedShardingAlgorithmsExecutorTest {
@Test
void assertGetRowData() {
ShowUnusedShardingAlgorithmsExecutor executor = new ShowUnusedShardingAlgorithmsExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowUnusedShardingAlgorithmsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -57,25 +54,6 @@ class ShowUnusedShardingAlgorithmsExecutorTest {
assertThat(row.getCell(3), is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowUnusedShardingAlgorithmsStatement> executor = new ShowUnusedShardingAlgorithmsExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getShardingAlgorithms().put("database_inline", createShardingInlineAlgorithmConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
index d290aac9c3a..b952763662a 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
@@ -39,7 +36,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -48,7 +44,9 @@ class ShowUnusedShardingAuditorsExecutorTest {
@Test
void assertGetRowData() {
ShowUnusedShardingAuditorsExecutor executor = new ShowUnusedShardingAuditorsExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowUnusedShardingAuditorsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -58,25 +56,6 @@ class ShowUnusedShardingAuditorsExecutorTest {
assertThat(row.getCell(3), is("{\"key\":\"value\"}"));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowUnusedShardingAuditorsStatement> executor = new ShowUnusedShardingAuditorsExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
index 325f494a62d..fce306a8719 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
@@ -31,13 +28,11 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,7 +41,9 @@ class ShowUnusedShardingKeyGeneratorExecutorTest {
@Test
void assertGetRowData() {
ShowUnusedShardingKeyGeneratorExecutor executor = new ShowUnusedShardingKeyGeneratorExecutor();
- executor.setDatabase(mockDatabase());
+ ShardingRule rule = mock(ShardingRule.class);
+ when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowUnusedShardingKeyGeneratorsStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,25 +53,6 @@ class ShowUnusedShardingKeyGeneratorExecutorTest {
assertThat(row.getCell(3), is(""));
}
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowUnusedShardingKeyGeneratorsStatement> executor = new ShowUnusedShardingKeyGeneratorExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getKeyGenerators().put("snowflake_key_generator", createSnowflakeKeyGeneratorConfiguration());
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/rule/RuleAwareRQLExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/aware/DatabaseRuleAwareRQLExecutor.java
similarity index 51%
rename from infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/rule/RuleAwareRQLExecutor.java
rename to infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/aware/DatabaseRuleAwareRQLExecutor.java
index 93285442754..04659170be3 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/rule/RuleAwareRQLExecutor.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/aware/DatabaseRuleAwareRQLExecutor.java
@@ -15,37 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.handler.type.rql.rule;
+package org.apache.shardingsphere.distsql.handler.type.rql.aware;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseAwareRQLExecutor;
import org.apache.shardingsphere.distsql.statement.rql.RQLStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import java.util.Collection;
-import java.util.Collections;
-
/**
- * Rule aware RQL executor.
+ * Database rule aware RQL executor.
*
- * @param <T> type of RQL statement
+ * @param <T> type of SQL statement
* @param <R> type of ShardingSphere rule
*/
-@RequiredArgsConstructor
-@Setter
-public abstract class RuleAwareRQLExecutor<T extends RQLStatement, R extends ShardingSphereRule> implements DatabaseAwareRQLExecutor<T> {
+public interface DatabaseRuleAwareRQLExecutor<T extends RQLStatement, R extends ShardingSphereRule> extends DatabaseAwareRQLExecutor<T> {
- private final Class<R> ruleClass;
+ /**
+ * Set ShardingSphere rule.
+ *
+ * @param rule rule
+ */
+ void setRule(R rule);
- private ShardingSphereDatabase database;
+ /**
+ * Get rule class.
+ *
+ * @return rule class
+ */
+ Class<R> getRuleClass();
@Override
- public Collection<LocalDataQueryResultRow> getRows(final T sqlStatement) {
- return database.getRuleMetaData().findSingleRule(ruleClass).map(optional -> getRows(database, sqlStatement, optional)).orElse(Collections.emptyList());
+ default void setDatabase(ShardingSphereDatabase database) {
}
-
- protected abstract Collection<LocalDataQueryResultRow> getRows(ShardingSphereDatabase database, T sqlStatement, R rule);
}
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutor.java
index ce9d3232722..f94c3f33cd2 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutor.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.single.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.single.distsql.statement.rql.ShowDefaultSingleTableStorageUnitStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
@@ -29,19 +29,18 @@ import java.util.Collections;
/**
* Show default single table storage unit executor.
*/
-public final class ShowDefaultSingleTableStorageUnitExecutor extends RuleAwareRQLExecutor<ShowDefaultSingleTableStorageUnitStatement, SingleRule> {
+@Setter
+public final class ShowDefaultSingleTableStorageUnitExecutor implements DatabaseRuleAwareRQLExecutor<ShowDefaultSingleTableStorageUnitStatement, SingleRule> {
- public ShowDefaultSingleTableStorageUnitExecutor() {
- super(SingleRule.class);
- }
+ private SingleRule rule;
@Override
public Collection<String> getColumnNames() {
- return Collections.singletonList("storage_unit_name");
+ return Collections.singleton("storage_unit_name");
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDefaultSingleTableStorageUnitStatement sqlStatement, final SingleRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowDefaultSingleTableStorageUnitStatement sqlStatement) {
return Collections.singleton(new LocalDataQueryResultRow(rule.getConfiguration().getDefaultDataSource().orElse("RANDOM")));
}
@@ -49,4 +48,9 @@ public final class ShowDefaultSingleTableStorageUnitExecutor extends RuleAwareRQ
public Class<ShowDefaultSingleTableStorageUnitStatement> getType() {
return ShowDefaultSingleTableStorageUnitStatement.class;
}
+
+ @Override
+ public Class<SingleRule> getRuleClass() {
+ return SingleRule.class;
+ }
}
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
index e818a8941bc..2514f275995 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.single.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTableStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
@@ -36,11 +36,10 @@ import java.util.stream.Collectors;
/**
* Show single table executor.
*/
-public final class ShowSingleTableExecutor extends RuleAwareRQLExecutor<ShowSingleTableStatement, SingleRule> {
+@Setter
+public final class ShowSingleTableExecutor implements DatabaseRuleAwareRQLExecutor<ShowSingleTableStatement, SingleRule> {
- public ShowSingleTableExecutor() {
- super(SingleRule.class);
- }
+ private SingleRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -48,7 +47,7 @@ public final class ShowSingleTableExecutor extends RuleAwareRQLExecutor<ShowSing
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowSingleTableStatement sqlStatement, final SingleRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowSingleTableStatement sqlStatement) {
Collection<DataNode> resultDataNodes = getPattern(sqlStatement)
.map(optional -> getDataNodesWithLikePattern(rule.getSingleTableDataNodes(), optional)).orElseGet(() -> getDataNodes(rule.getSingleTableDataNodes(), sqlStatement));
Collection<DataNode> sortedDataNodes = resultDataNodes.stream().sorted(Comparator.comparing(DataNode::getTableName)).collect(Collectors.toList());
@@ -70,6 +69,11 @@ public final class ShowSingleTableExecutor extends RuleAwareRQLExecutor<ShowSing
.map(entry -> entry.getValue().iterator().next()).collect(Collectors.toList());
}
+ @Override
+ public Class<SingleRule> getRuleClass() {
+ return SingleRule.class;
+ }
+
@Override
public Class<ShowSingleTableStatement> getType() {
return ShowSingleTableStatement.class;
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
index d65bdca6365..fe8f69d586e 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.single.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -38,11 +39,12 @@ import java.util.stream.Collectors;
/**
* Show unloaded single table executor.
*/
-public final class ShowUnloadedSingleTableExecutor extends RuleAwareRQLExecutor<ShowUnloadedSingleTableStatement, SingleRule> {
+@Setter
+public final class ShowUnloadedSingleTableExecutor implements DatabaseRuleAwareRQLExecutor<ShowUnloadedSingleTableStatement, SingleRule> {
- public ShowUnloadedSingleTableExecutor() {
- super(SingleRule.class);
- }
+ private ShardingSphereDatabase database;
+
+ private SingleRule rule;
@Override
public Collection<String> getColumnNames() {
@@ -50,7 +52,7 @@ public final class ShowUnloadedSingleTableExecutor extends RuleAwareRQLExecutor<
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowUnloadedSingleTableStatement sqlStatement, final SingleRule rule) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowUnloadedSingleTableStatement sqlStatement) {
Map<String, Collection<DataNode>> actualDataNodes = getActualDataNodes(database);
for (String each : rule.getLogicTableMapper().getTableNames()) {
actualDataNodes.remove(each.toLowerCase());
@@ -68,6 +70,11 @@ public final class ShowUnloadedSingleTableExecutor extends RuleAwareRQLExecutor<
return SingleTableDataNodeLoader.load(database.getName(), aggregateDataSourceMap, excludedTables);
}
+ @Override
+ public Class<SingleRule> getRuleClass() {
+ return SingleRule.class;
+ }
+
@Override
public Class<ShowUnloadedSingleTableStatement> getType() {
return ShowUnloadedSingleTableStatement.class;
diff --git a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutorTest.java b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutorTest.java
index eaa798c39b8..4df5b61ca97 100644
--- a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutorTest.java
+++ b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowDefaultSingleTableStorageUnitExecutorTest.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.single.distsql.handler.query;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.distsql.statement.rql.ShowDefaultSingleTableStorageUnitStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
@@ -40,28 +37,13 @@ class ShowDefaultSingleTableStorageUnitExecutorTest {
@Test
void assertGetRowData() {
ShowDefaultSingleTableStorageUnitExecutor executor = new ShowDefaultSingleTableStorageUnitExecutor();
- executor.setDatabase(mockDatabase());
+ SingleRule rule = mock(SingleRule.class);
+ when(rule.getConfiguration()).thenReturn(new SingleRuleConfiguration(Collections.emptyList(), "foo_ds"));
+ executor.setRule(rule);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowDefaultSingleTableStorageUnitStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
String defaultSingleTableStorageUnit = (String) rowData.next().getCell(1);
assertThat(defaultSingleTableStorageUnit, is("foo_ds"));
}
-
- @Test
- void assertGetColumns() {
- RQLExecutor<ShowDefaultSingleTableStorageUnitStatement> executor = new ShowDefaultSingleTableStorageUnitExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(1));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("storage_unit_name"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
- SingleRule singleRule = mock(SingleRule.class);
- when(singleRule.getConfiguration()).thenReturn(new SingleRuleConfiguration(Collections.emptyList(), "foo_ds"));
- when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(singleRule)));
- return result;
- }
}
diff --git a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java
index 8ada3f3970d..bd58a2d5940 100644
--- a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java
+++ b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java
@@ -19,23 +19,14 @@ package org.apache.shardingsphere.single.distsql.handler.query;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTableStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -43,26 +34,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@ExtendWith(MockitoExtension.class)
-@MockitoSettings(strictness = Strictness.LENIENT)
class ShowSingleTableExecutorTest {
- @Mock
- private ShardingSphereDatabase database;
-
- @BeforeEach
- void before() {
- Map<String, Collection<DataNode>> singleTableDataNodeMap = new HashMap<>();
- singleTableDataNodeMap.put("t_order", Collections.singleton(new DataNode("ds_1", "t_order")));
- singleTableDataNodeMap.put("t_order_item", Collections.singleton(new DataNode("ds_2", "t_order_item")));
- RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(Collections.singleton(mockSingleRule(singleTableDataNodeMap))));
- when(database.getRuleMetaData()).thenReturn(ruleMetaData);
- }
-
@Test
void assertGetRowData() {
ShowSingleTableExecutor executor = new ShowSingleTableExecutor();
- executor.setDatabase(database);
+ executor.setRule(mockSingleRule());
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowSingleTableStatement.class));
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -77,7 +54,7 @@ class ShowSingleTableExecutorTest {
@Test
void assertGetSingleTableWithLikeLiteral() {
ShowSingleTableExecutor executor = new ShowSingleTableExecutor();
- executor.setDatabase(database);
+ executor.setRule(mockSingleRule());
ShowSingleTableStatement statement = new ShowSingleTableStatement(null, "%item", null);
Collection<LocalDataQueryResultRow> actual = executor.getRows(statement);
assertThat(actual.size(), is(1));
@@ -87,17 +64,11 @@ class ShowSingleTableExecutorTest {
assertThat(row.getCell(2), is("ds_2"));
}
- @Test
- void assertGetColumns() {
- Collection<String> columns = new ShowSingleTableExecutor().getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("table_name"));
- assertThat(iterator.next(), is("storage_unit_name"));
- }
-
- private SingleRule mockSingleRule(final Map<String, Collection<DataNode>> singleTableDataNodeMap) {
+ private SingleRule mockSingleRule() {
SingleRule result = mock(SingleRule.class);
+ Map<String, Collection<DataNode>> singleTableDataNodeMap = new HashMap<>();
+ singleTableDataNodeMap.put("t_order", Collections.singleton(new DataNode("ds_1", "t_order")));
+ singleTableDataNodeMap.put("t_order_item", Collections.singleton(new DataNode("ds_2", "t_order_item")));
when(result.getSingleTableDataNodes()).thenReturn(singleTableDataNodeMap);
return result;
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
index 39d516ae01e..5f60337cd12 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
@@ -20,10 +20,13 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecutor;
import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseAwareRQLExecutor;
+import org.apache.shardingsphere.distsql.handler.type.rql.aware.DatabaseRuleAwareRQLExecutor;
import org.apache.shardingsphere.distsql.statement.rql.RQLStatement;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler;
@@ -39,7 +42,9 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.stream.Collectors;
/**
@@ -62,12 +67,26 @@ public final class RQLBackendHandler implements DistSQLBackendHandler {
RQLExecutor executor = TypedSPILoader.getService(RQLExecutor.class, sqlStatement.getClass());
queryHeaders = createQueryHeader(executor.getColumnNames());
if (executor instanceof DatabaseAwareRQLExecutor) {
- ((DatabaseAwareRQLExecutor<?>) executor).setDatabase(ProxyContext.getInstance().getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement, connectionSession)));
+ setUpDatabaseAwareExecutor((DatabaseAwareRQLExecutor) executor);
}
- mergedResult = createMergedResult(executor.getRows(sqlStatement));
+ mergedResult = null == mergedResult ? createMergedResult(executor.getRows(sqlStatement)) : mergedResult;
return new QueryResponseHeader(queryHeaders);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private void setUpDatabaseAwareExecutor(final DatabaseAwareRQLExecutor executor) {
+ ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement, connectionSession));
+ ((DatabaseAwareRQLExecutor<?>) executor).setDatabase(database);
+ if (executor instanceof DatabaseRuleAwareRQLExecutor) {
+ Optional<ShardingSphereRule> rule = database.getRuleMetaData().findSingleRule(((DatabaseRuleAwareRQLExecutor) executor).getRuleClass());
+ if (rule.isPresent()) {
+ ((DatabaseRuleAwareRQLExecutor) executor).setRule(rule.get());
+ } else {
+ mergedResult = createMergedResult(Collections.emptyList());
+ }
+ }
+ }
+
private List<QueryHeader> createQueryHeader(final Collection<String> columnNames) {
return columnNames.stream().map(each -> new QueryHeader("", "", each, each, Types.CHAR, "CHAR", 255, 0, false, false, false, false)).collect(Collectors.toList());
}