This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 77020bc9233 Add ShowRulesUsedStorageUnitRowBuilder (#30053)
77020bc9233 is described below
commit 77020bc923357d676c55bfda1c81ac5d03d7eb37
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 7 19:49:09 2024 +0800
Add ShowRulesUsedStorageUnitRowBuilder (#30053)
* Add ShowRulesUsedStorageUnitRowBuilder
* Add ShowRulesUsedStorageUnitRowBuilder
---
.../ShowEncryptRulesUsedStorageUnitRowBuilder.java | 42 +++++++++
...ne.query.rql.ShowRulesUsedStorageUnitRowBuilder | 18 ++++
.../ShowMaskRulesUsedStorageUnitRowBuilder.java | 42 +++++++++
...ne.query.rql.ShowRulesUsedStorageUnitRowBuilder | 18 ++++
...iteSplittingRulesUsedStorageUnitRowBuilder.java | 57 +++++++++++++
...ne.query.rql.ShowRulesUsedStorageUnitRowBuilder | 18 ++++
.../ShowShadowRulesUsedStorageUnitRowBuilder.java | 49 +++++++++++
...ne.query.rql.ShowRulesUsedStorageUnitRowBuilder | 18 ++++
...ShowShardingRulesUsedStorageUnitRowBuilder.java | 51 +++++++++++
...ne.query.rql.ShowRulesUsedStorageUnitRowBuilder | 18 ++++
.../rql/ShowRulesUsedStorageUnitRowBuilder.java | 47 ++++++++++
.../rql/ShowRulesUsedStorageUnitExecutor.java | 99 ++--------------------
12 files changed, 387 insertions(+), 90 deletions(-)
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..78819eeb86d
--- /dev/null
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.distsql.handler.query;
+
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Show encrypt rules used storage unit row builder.
+ */
+public final class ShowEncryptRulesUsedStorageUnitRowBuilder implements
ShowRulesUsedStorageUnitRowBuilder<EncryptRule> {
+
+ @Override
+ public Collection<LocalDataQueryResultRow> getInUsedData(final
ShowRulesUsedStorageUnitStatement sqlStatement, final EncryptRule rule) {
+ return rule.getConfiguration().getTables().stream().map(each -> new
LocalDataQueryResultRow("encrypt",
each.getName())).collect(Collectors.toList());
+ }
+
+ @Override
+ public Class<EncryptRule> getType() {
+ return EncryptRule.class;
+ }
+}
diff --git
a/features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
b/features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
new file mode 100644
index 00000000000..27d56901da2
--- /dev/null
+++
b/features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.encrypt.distsql.handler.query.ShowEncryptRulesUsedStorageUnitRowBuilder
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..807f5630d66
--- /dev/null
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.distsql.handler.query;
+
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.mask.rule.MaskRule;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Show mask rules used storage unit row builder.
+ */
+public final class ShowMaskRulesUsedStorageUnitRowBuilder implements
ShowRulesUsedStorageUnitRowBuilder<MaskRule> {
+
+ @Override
+ public Collection<LocalDataQueryResultRow> getInUsedData(final
ShowRulesUsedStorageUnitStatement sqlStatement, final MaskRule rule) {
+ return rule.getConfiguration().getTables().stream().map(each -> new
LocalDataQueryResultRow("mask", each.getName())).collect(Collectors.toList());
+ }
+
+ @Override
+ public Class<MaskRule> getType() {
+ return MaskRule.class;
+ }
+}
diff --git
a/features/mask/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
b/features/mask/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
new file mode 100644
index 00000000000..87c5b172b25
--- /dev/null
+++
b/features/mask/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.mask.distsql.handler.query.ShowMaskRulesUsedStorageUnitRowBuilder
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..3a6ba3fe4cb
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
+
+import com.cedarsoftware.util.CaseInsensitiveSet;
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+
+/**
+ * Show readwrite-splitting rules used storage unit row builder.
+ */
+public final class ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder
implements ShowRulesUsedStorageUnitRowBuilder<ReadwriteSplittingRule> {
+
+ @Override
+ public Collection<LocalDataQueryResultRow> getInUsedData(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ReadwriteSplittingRule
rule) {
+ if (!sqlStatement.getStorageUnitName().isPresent()) {
+ return Collections.emptyList();
+ }
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ for (ReadwriteSplittingDataSourceRuleConfiguration each :
rule.getConfiguration().getDataSources()) {
+ if
(each.getWriteDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get()))
{
+ result.add(new LocalDataQueryResultRow("readwrite_splitting",
each.getName()));
+ }
+ if (new
CaseInsensitiveSet<>(each.getReadDataSourceNames()).contains(sqlStatement.getStorageUnitName().get()))
{
+ result.add(new LocalDataQueryResultRow("readwrite_splitting",
each.getName()));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public Class<ReadwriteSplittingRule> getType() {
+ return ReadwriteSplittingRule.class;
+ }
+}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
new file mode 100644
index 00000000000..f210c051245
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..dcb643dcaa5
--- /dev/null
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.distsql.handler.query;
+
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+/**
+ * Show shadow rules used storage unit row builder.
+ */
+public final class ShowShadowRulesUsedStorageUnitRowBuilder implements
ShowRulesUsedStorageUnitRowBuilder<ShadowRule> {
+
+ @Override
+ public Collection<LocalDataQueryResultRow> getInUsedData(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ShadowRule rule) {
+ if (!sqlStatement.getStorageUnitName().isPresent()) {
+ return Collections.emptyList();
+ }
+ return rule.getConfiguration().getDataSources().stream()
+ .filter(each ->
each.getShadowDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get())
+ ||
each.getProductionDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get()))
+ .map(each -> new LocalDataQueryResultRow("shadow",
each.getName())).collect(Collectors.toList());
+ }
+
+ @Override
+ public Class<ShadowRule> getType() {
+ return ShadowRule.class;
+ }
+}
diff --git
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
new file mode 100644
index 00000000000..7af069a0252
--- /dev/null
+++
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowRulesUsedStorageUnitRowBuilder
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..2493a99983b
--- /dev/null
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.handler.query;
+
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Show sharding rules used storage unit row builder.
+ */
+public final class ShowShardingRulesUsedStorageUnitRowBuilder implements
ShowRulesUsedStorageUnitRowBuilder<ShardingRule> {
+
+ @Override
+ public Collection<LocalDataQueryResultRow> getInUsedData(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ShardingRule rule) {
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ for (ShardingAutoTableRuleConfiguration each :
rule.getConfiguration().getAutoTables()) {
+ result.add(new LocalDataQueryResultRow("sharding",
each.getLogicTable()));
+ }
+ for (ShardingTableRuleConfiguration each :
rule.getConfiguration().getTables()) {
+ result.add(new LocalDataQueryResultRow("sharding",
each.getLogicTable()));
+ }
+ return result;
+ }
+
+ @Override
+ public Class<ShardingRule> getType() {
+ return ShardingRule.class;
+ }
+}
diff --git
a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
new file mode 100644
index 00000000000..79b6abf85c2
--- /dev/null
+++
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingRulesUsedStorageUnitRowBuilder
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
new file mode 100644
index 00000000000..7a95a6a675d
--- /dev/null
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
+
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
+
+import java.util.Collection;
+
+/**
+ * Show rules used storage unit executor.
+ *
+ * @param <T> type of rule
+ */
+@SingletonSPI
+public interface ShowRulesUsedStorageUnitRowBuilder<T extends
ShardingSphereRule> extends TypedSPI {
+
+ /**
+ * Get in used data.
+ *
+ * @param sqlStatement show rules used storage unit statement
+ * @param rule rule
+ * @return in used data
+ */
+ Collection<LocalDataQueryResultRow>
getInUsedData(ShowRulesUsedStorageUnitStatement sqlStatement, T rule);
+
+ @Override
+ Class<T> getType();
+}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
index 5c19e81e69f..67b1e3c5832 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
@@ -20,29 +20,19 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
-import org.apache.shardingsphere.mask.rule.MaskRule;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
-import java.util.stream.Collectors;
/**
* Show rules used storage unit executor.
@@ -50,16 +40,6 @@ import java.util.stream.Collectors;
@Setter
public final class ShowRulesUsedStorageUnitExecutor implements
DistSQLQueryExecutor<ShowRulesUsedStorageUnitStatement>,
DistSQLExecutorDatabaseAware {
- private static final String SHARDING = "sharding";
-
- private static final String READWRITE_SPLITTING = "readwrite_splitting";
-
- private static final String ENCRYPT = "encrypt";
-
- private static final String SHADOW = "shadow";
-
- private static final String MASK = "mask";
-
private ShardingSphereDatabase database;
@Override
@@ -69,81 +49,20 @@ public final class ShowRulesUsedStorageUnitExecutor
implements DistSQLQueryExecu
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowRulesUsedStorageUnitStatement sqlStatement, final ContextManager
contextManager) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
String resourceName = sqlStatement.getStorageUnitName().orElse(null);
- if
(database.getResourceMetaData().getStorageUnits().containsKey(resourceName)) {
- result.addAll(getShardingData(database));
- result.addAll(getReadwriteSplittingData(database, resourceName));
- result.addAll(getEncryptData(database));
- result.addAll(getShadowData(database, resourceName));
- result.addAll(getMaskData(database));
- }
- return result;
- }
-
- private Collection<LocalDataQueryResultRow> getShardingData(final
ShardingSphereDatabase database) {
- Optional<ShardingRule> rule =
database.getRuleMetaData().findSingleRule(ShardingRule.class);
- if (!rule.isPresent()) {
- return Collections.emptyList();
- }
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- ShardingRuleConfiguration config = rule.get().getConfiguration();
- for (ShardingAutoTableRuleConfiguration each : config.getAutoTables())
{
- result.add(buildRow(SHARDING, each.getLogicTable()));
- }
- for (ShardingTableRuleConfiguration each : config.getTables()) {
- result.add(buildRow(SHARDING, each.getLogicTable()));
- }
- return result;
+ return
database.getResourceMetaData().getStorageUnits().containsKey(resourceName) ?
getRows(sqlStatement) : Collections.emptyList();
}
- private Collection<LocalDataQueryResultRow>
getReadwriteSplittingData(final ShardingSphereDatabase database, final String
resourceName) {
- Optional<ReadwriteSplittingRule> rule =
database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class);
- if (!rule.isPresent()) {
- return Collections.emptyList();
- }
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private Collection<LocalDataQueryResultRow> getRows(final
ShowRulesUsedStorageUnitStatement sqlStatement) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- ReadwriteSplittingRuleConfiguration config =
rule.get().getConfiguration();
- for (ReadwriteSplittingDataSourceRuleConfiguration each :
config.getDataSources()) {
- if (each.getWriteDataSourceName().equalsIgnoreCase(resourceName)) {
- result.add(buildRow(READWRITE_SPLITTING, each.getName()));
- }
- if (each.getReadDataSourceNames().contains(resourceName)) {
- result.add(buildRow(READWRITE_SPLITTING, each.getName()));
- }
+ for (ShowRulesUsedStorageUnitRowBuilder each :
ShardingSphereServiceLoader.getServiceInstances(ShowRulesUsedStorageUnitRowBuilder.class))
{
+ Optional<ShardingSphereRule> rule =
database.getRuleMetaData().findSingleRule(each.getType());
+ rule.ifPresent(optional ->
result.addAll(each.getInUsedData(sqlStatement, optional)));
}
return result;
}
- private Collection<LocalDataQueryResultRow> getEncryptData(final
ShardingSphereDatabase database) {
- return database.getRuleMetaData().findSingleRule(EncryptRule.class)
- .map(optional ->
optional.getConfiguration().getTables().stream().map(each -> buildRow(ENCRYPT,
each.getName())).collect(Collectors.toList())).orElse(Collections.emptyList());
- }
-
- private Collection<LocalDataQueryResultRow> getShadowData(final
ShardingSphereDatabase database, final String resourceName) {
- Optional<ShadowRule> rule =
database.getRuleMetaData().findSingleRule(ShadowRule.class);
- if (!rule.isPresent()) {
- return Collections.emptyList();
- }
- ShadowRuleConfiguration config = rule.get().getConfiguration();
- return config.getDataSources().stream()
- .filter(each ->
each.getShadowDataSourceName().equalsIgnoreCase(resourceName) ||
each.getProductionDataSourceName().equalsIgnoreCase(resourceName))
- .map(each -> buildRow(SHADOW,
each.getName())).collect(Collectors.toList());
- }
-
- private Collection<LocalDataQueryResultRow> getMaskData(final
ShardingSphereDatabase database) {
- Optional<MaskRule> rule =
database.getRuleMetaData().findSingleRule(MaskRule.class);
- if (!rule.isPresent()) {
- return Collections.emptyList();
- }
- MaskRuleConfiguration config = rule.get().getConfiguration();
- return config.getTables().stream().map(each -> buildRow(MASK,
each.getName())).collect(Collectors.toList());
- }
-
- private LocalDataQueryResultRow buildRow(final String type, final String
name) {
- return new LocalDataQueryResultRow(type, name);
- }
-
@Override
public Class<ShowRulesUsedStorageUnitStatement> getType() {
return ShowRulesUsedStorageUnitStatement.class;