This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 e9a9afbdaf5 Add DatabaseRuleConfigurationEmptyChecker to make config
api clean (#33666)
e9a9afbdaf5 is described below
commit e9a9afbdaf5b0bd7eec3f06197e3475772de266f
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 14 23:02:54 2024 +0800
Add DatabaseRuleConfigurationEmptyChecker to make config api clean (#33666)
* Add DatabaseRuleConfigurationEmptyChecker to make config api clean
* Add DatabaseRuleConfigurationEmptyChecker to make config api clean
---
.../config/BroadcastRuleConfiguration.java | 5 --
.../BroadcastRuleConfigurationEmptyChecker.java} | 25 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
...roadcastRuleConfigurationEmptyCheckerTest.java} | 17 ++++-
.../encrypt/config/EncryptRuleConfiguration.java | 5 --
.../EncryptRuleConfigurationEmptyChecker.java} | 25 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
.../EncryptRuleConfigurationEmptyCheckerTest.java} | 17 ++++-
.../mask/config/MaskRuleConfiguration.java | 5 --
.../MaskRuleConfigurationEmptyChecker.java} | 25 +++++---
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
.../MaskRuleConfigurationEmptyCheckerTest.java} | 17 ++++-
.../ReadwriteSplittingRuleConfiguration.java | 5 --
...iteSplittingRuleConfigurationEmptyChecker.java} | 25 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
...plittingRuleConfigurationEmptyCheckerTest.java} | 17 ++++-
.../shadow/config/ShadowRuleConfiguration.java | 5 --
.../shadow/config/ShadowRuleConfigurationTest.java | 53 ----------------
.../ShadowRuleConfigurationEmptyChecker.java} | 25 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
.../ShadowRuleConfigurationEmptyCheckerTest.java | 64 +++++++++++++++++++
.../api/config/ShardingRuleConfiguration.java | 5 --
.../ShardingRuleConfigurationEmptyChecker.java} | 26 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
.../ShardingRuleConfigurationEmptyCheckerTest.java | 74 ++++++++++++++++++++++
.../rule/scope/DatabaseRuleConfiguration.java | 7 --
... => DatabaseRuleConfigurationEmptyChecker.java} | 20 ++++--
.../fixture/FixtureDatabaseRuleConfiguration.java | 5 --
.../database/type/DropDatabaseRuleOperator.java | 5 +-
.../single/config/SingleRuleConfiguration.java | 5 --
.../SingleRuleConfigurationEmptyChecker.java | 25 ++++----
...ule.scope.DatabaseRuleConfigurationEmptyChecker | 18 ++++++
.../SingleRuleConfigurationEmptyCheckerTest.java} | 27 +++++---
.../manager/DatabaseRuleConfigurationManager.java | 8 ++-
.../proxy/backend/util/ExportUtils.java | 9 ++-
35 files changed, 449 insertions(+), 228 deletions(-)
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
index 56158c8689e..f181dcdf101 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
@@ -32,9 +32,4 @@ import java.util.Collection;
public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
private final Collection<String> tables;
-
- @Override
- public boolean isEmpty() {
- return tables.isEmpty();
- }
}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyChecker.java
similarity index 60%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyChecker.java
index 56158c8689e..ecfbeeb7e45 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyChecker.java
@@ -15,26 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.broadcast.checker;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
/**
- * Broadcast rule configuration.
+ * Broadcast rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class BroadcastRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<BroadcastRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final BroadcastRuleConfiguration ruleConfig) {
+ return ruleConfig.getTables().isEmpty();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<BroadcastRuleConfiguration> getType() {
+ return BroadcastRuleConfiguration.class;
}
}
diff --git
a/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..37c773e7a03
--- /dev/null
+++
b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.broadcast.checker.BroadcastRuleConfigurationEmptyChecker
diff --git
a/features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyCheckerTest.java
similarity index 56%
rename from
features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java
rename to
features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyCheckerTest.java
index 93500a0f321..af423c98eaf 100644
---
a/features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/checker/BroadcastRuleConfigurationEmptyCheckerTest.java
@@ -15,18 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.broadcast.checker;
+import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class BroadcastRuleConfigurationTest {
+class BroadcastRuleConfigurationEmptyCheckerTest {
+
+ private BroadcastRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (BroadcastRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
BroadcastRuleConfiguration.class);
+ }
@Test
void assertIsEmpty() {
- assertTrue(new
BroadcastRuleConfiguration(Collections.emptyList()).isEmpty());
+ assertTrue(checker.isEmpty(new
BroadcastRuleConfiguration(Collections.emptyList())));
}
}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfiguration.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfiguration.java
index 3b56adb14e8..7d4cdf5e1ab 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfiguration.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfiguration.java
@@ -37,9 +37,4 @@ public final class EncryptRuleConfiguration implements
DatabaseRuleConfiguration
private final Collection<EncryptTableRuleConfiguration> tables;
private final Map<String, AlgorithmConfiguration> encryptors;
-
- @Override
- public boolean isEmpty() {
- return tables.isEmpty();
- }
}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyChecker.java
similarity index 60%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyChecker.java
index 56158c8689e..c898c62f98c 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyChecker.java
@@ -15,26 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.encrypt.checker.config;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
/**
- * Broadcast rule configuration.
+ * Encrypt rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class EncryptRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<EncryptRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final EncryptRuleConfiguration ruleConfig) {
+ return ruleConfig.getTables().isEmpty();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<EncryptRuleConfiguration> getType() {
+ return EncryptRuleConfiguration.class;
}
}
diff --git
a/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..44d17a69279
--- /dev/null
+++
b/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.checker.config.EncryptRuleConfigurationEmptyChecker
diff --git
a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyCheckerTest.java
similarity index 55%
rename from
features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
rename to
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyCheckerTest.java
index 4c89f25657b..406e9b87134 100644
---
a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationEmptyCheckerTest.java
@@ -15,18 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mask.config;
+package org.apache.shardingsphere.encrypt.checker.config;
+import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class MaskRuleConfigurationTest {
+class EncryptRuleConfigurationEmptyCheckerTest {
+
+ private EncryptRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (EncryptRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
EncryptRuleConfiguration.class);
+ }
@Test
void assertIsEmpty() {
- assertTrue(new MaskRuleConfiguration(Collections.emptyList(),
Collections.emptyMap()).isEmpty());
+ assertTrue(checker.isEmpty(new
EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
}
}
diff --git
a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
b/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
index 5668ea90d7e..e0544971d7d 100644
---
a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
+++
b/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
@@ -37,9 +37,4 @@ public final class MaskRuleConfiguration implements
DatabaseRuleConfiguration, E
private final Collection<MaskTableRuleConfiguration> tables;
private final Map<String, AlgorithmConfiguration> maskAlgorithms;
-
- @Override
- public boolean isEmpty() {
- return tables.isEmpty();
- }
}
diff --git
a/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyChecker.java
similarity index 56%
rename from
features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
rename to
features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyChecker.java
index 363652e9113..5f81ce10433 100644
---
a/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyChecker.java
@@ -15,18 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.config;
+package org.apache.shardingsphere.mask.checker;
-import org.junit.jupiter.api.Test;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class EncryptRuleConfigurationTest {
+/**
+ * Mask rule configuration empty checker.
+ */
+public final class MaskRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<MaskRuleConfiguration> {
+
+ @Override
+ public boolean isEmpty(final MaskRuleConfiguration ruleConfig) {
+ return ruleConfig.getTables().isEmpty();
+ }
- @Test
- void assertIsEmpty() {
- assertTrue(new EncryptRuleConfiguration(Collections.emptyList(),
Collections.emptyMap()).isEmpty());
+ @Override
+ public Class<MaskRuleConfiguration> getType() {
+ return MaskRuleConfiguration.class;
}
}
diff --git
a/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..d059f046bf3
--- /dev/null
+++
b/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.checker.MaskRuleConfigurationEmptyChecker
diff --git
a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyCheckerTest.java
similarity index 56%
copy from
features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
copy to
features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyCheckerTest.java
index d6c7feb3d72..4d5a5cd2a18 100644
---
a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationEmptyCheckerTest.java
@@ -15,18 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.readwritesplitting.config;
+package org.apache.shardingsphere.mask.checker;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class ReadwriteSplittingRuleConfigurationTest {
+class MaskRuleConfigurationEmptyCheckerTest {
+
+ private MaskRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (MaskRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
MaskRuleConfiguration.class);
+ }
@Test
void assertIsEmpty() {
- assertTrue(new
ReadwriteSplittingRuleConfiguration(Collections.emptyList(),
Collections.emptyMap()).isEmpty());
+ assertTrue(checker.isEmpty(new
MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
}
}
diff --git
a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfiguration.java
b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfiguration.java
index 6735850183a..625ab947bc3 100644
---
a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfiguration.java
+++
b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfiguration.java
@@ -37,9 +37,4 @@ public final class ReadwriteSplittingRuleConfiguration
implements DatabaseRuleCo
private final
Collection<ReadwriteSplittingDataSourceGroupRuleConfiguration> dataSourceGroups;
private final Map<String, AlgorithmConfiguration> loadBalancers;
-
- @Override
- public boolean isEmpty() {
- return dataSourceGroups.isEmpty();
- }
}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyChecker.java
similarity index 56%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyChecker.java
index 56158c8689e..5990b7a46bc 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyChecker.java
@@ -15,26 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.readwritesplitting.checker;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
/**
- * Broadcast rule configuration.
+ * Readwrite-splitting rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class ReadwriteSplittingRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<ReadwriteSplittingRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final ReadwriteSplittingRuleConfiguration
ruleConfig) {
+ return ruleConfig.getDataSourceGroups().isEmpty();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<ReadwriteSplittingRuleConfiguration> getType() {
+ return ReadwriteSplittingRuleConfiguration.class;
}
}
diff --git
a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..a21a97eaaa2
--- /dev/null
+++
b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.checker.ReadwriteSplittingRuleConfigurationEmptyChecker
diff --git
a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyCheckerTest.java
similarity index 53%
rename from
features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
rename to
features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyCheckerTest.java
index d6c7feb3d72..29815f93408 100644
---
a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/config/ReadwriteSplittingRuleConfigurationTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationEmptyCheckerTest.java
@@ -15,18 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.readwritesplitting.config;
+package org.apache.shardingsphere.readwritesplitting.checker;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class ReadwriteSplittingRuleConfigurationTest {
+class ReadwriteSplittingRuleConfigurationEmptyCheckerTest {
+
+ private ReadwriteSplittingRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (ReadwriteSplittingRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
ReadwriteSplittingRuleConfiguration.class);
+ }
@Test
void assertIsEmpty() {
- assertTrue(new
ReadwriteSplittingRuleConfiguration(Collections.emptyList(),
Collections.emptyMap()).isEmpty());
+ assertTrue(checker.isEmpty(new
ReadwriteSplittingRuleConfiguration(Collections.emptyList(),
Collections.emptyMap())));
}
}
diff --git
a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfiguration.java
b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfiguration.java
index 23e7cc41261..5cc2e659213 100644
---
a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfiguration.java
+++
b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfiguration.java
@@ -44,9 +44,4 @@ public final class ShadowRuleConfiguration implements
DatabaseRuleConfiguration,
private Map<String, AlgorithmConfiguration> shadowAlgorithms = new
LinkedHashMap<>();
private String defaultShadowAlgorithmName;
-
- @Override
- public boolean isEmpty() {
- return dataSources.isEmpty() || tables.isEmpty();
- }
}
diff --git
a/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfigurationTest.java
b/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfigurationTest.java
deleted file mode 100644
index 8327e0f2b40..00000000000
---
a/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/config/ShadowRuleConfigurationTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.config;
-
-import
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
-import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-
-class ShadowRuleConfigurationTest {
-
- @Test
- void assertIsEmptyDataSources() {
- ShadowRuleConfiguration actual = new ShadowRuleConfiguration();
- actual.setTables(Collections.singletonMap("foo_tbl",
mock(ShadowTableConfiguration.class)));
- assertTrue(actual.isEmpty());
- }
-
- @Test
- void assertIsEmptyTables() {
- ShadowRuleConfiguration actual = new ShadowRuleConfiguration();
-
actual.setDataSources(Collections.singleton(mock(ShadowDataSourceConfiguration.class)));
- assertTrue(actual.isEmpty());
- }
-
- @Test
- void assertIsNotEmpty() {
- ShadowRuleConfiguration actual = new ShadowRuleConfiguration();
-
actual.setDataSources(Collections.singleton(mock(ShadowDataSourceConfiguration.class)));
- actual.setTables(Collections.singletonMap("foo_tbl",
mock(ShadowTableConfiguration.class)));
- assertFalse(actual.isEmpty());
- }
-}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyChecker.java
similarity index 59%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyChecker.java
index 56158c8689e..5a28aac84b4 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyChecker.java
@@ -15,26 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.shadow.checker;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
/**
- * Broadcast rule configuration.
+ * Shadow rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class ShadowRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<ShadowRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final ShadowRuleConfiguration ruleConfig) {
+ return ruleConfig.getDataSources().isEmpty() ||
ruleConfig.getTables().isEmpty();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<ShadowRuleConfiguration> getType() {
+ return ShadowRuleConfiguration.class;
}
}
diff --git
a/features/shadow/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/shadow/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..99638031aeb
--- /dev/null
+++
b/features/shadow/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.checker.ShadowRuleConfigurationEmptyChecker
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyCheckerTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyCheckerTest.java
new file mode 100644
index 00000000000..92da725efe3
--- /dev/null
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationEmptyCheckerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.checker;
+
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
+import
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class ShadowRuleConfigurationEmptyCheckerTest {
+
+ private ShadowRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (ShadowRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
ShadowRuleConfiguration.class);
+ }
+
+ @Test
+ void assertIsEmptyDataSources() {
+ ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
+ ruleConfig.setTables(Collections.singletonMap("foo_tbl",
mock(ShadowTableConfiguration.class)));
+ assertTrue(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsEmptyTables() {
+ ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
+
ruleConfig.setDataSources(Collections.singleton(mock(ShadowDataSourceConfiguration.class)));
+ assertTrue(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsNotEmpty() {
+ ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
+
ruleConfig.setDataSources(Collections.singleton(mock(ShadowDataSourceConfiguration.class)));
+ ruleConfig.setTables(Collections.singletonMap("foo_tbl",
mock(ShadowTableConfiguration.class)));
+ assertFalse(checker.isEmpty(ruleConfig));
+ }
+}
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
index 8b6332c545a..edaa3f41d43 100644
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
+++
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
@@ -65,9 +65,4 @@ public final class ShardingRuleConfiguration implements
DatabaseRuleConfiguratio
private Map<String, AlgorithmConfiguration> auditors = new
LinkedHashMap<>();
private ShardingCacheConfiguration shardingCache;
-
- @Override
- public boolean isEmpty() {
- return tables.isEmpty() && autoTables.isEmpty() && null ==
defaultDatabaseShardingStrategy && null == defaultTableShardingStrategy;
- }
}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyChecker.java
similarity index 54%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyChecker.java
index 56158c8689e..f6ea6530e3f 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyChecker.java
@@ -15,26 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.sharding.checker;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
/**
- * Broadcast rule configuration.
+ * Sharding rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class ShardingRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<ShardingRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final ShardingRuleConfiguration ruleConfig) {
+ return ruleConfig.getTables().isEmpty() &&
ruleConfig.getAutoTables().isEmpty()
+ && null == ruleConfig.getDefaultDatabaseShardingStrategy() &&
null == ruleConfig.getDefaultTableShardingStrategy();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<ShardingRuleConfiguration> getType() {
+ return ShardingRuleConfiguration.class;
}
}
diff --git
a/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..9564ad0092a
--- /dev/null
+++
b/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.checker.ShardingRuleConfigurationEmptyChecker
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyCheckerTest.java
new file mode 100644
index 00000000000..e9661eeb03b
--- /dev/null
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationEmptyCheckerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.checker;
+
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class ShardingRuleConfigurationEmptyCheckerTest {
+
+ private ShardingRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (ShardingRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
ShardingRuleConfiguration.class);
+ }
+
+ @Test
+ void assertIsNotEmptyWithTables() {
+ ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+ ruleConfig.getTables().add(mock(ShardingTableRuleConfiguration.class));
+ assertFalse(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsNotEmptyWithAutoTables() {
+ ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+
ruleConfig.getAutoTables().add(mock(ShardingAutoTableRuleConfiguration.class));
+ assertFalse(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsNotEmptyWithGetDefaultDatabaseShardingStrategy() {
+ ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+
ruleConfig.setDefaultDatabaseShardingStrategy(mock(ShardingStrategyConfiguration.class));
+ assertFalse(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsNotEmptyWithGetDefaultTableShardingStrategy() {
+ ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+
ruleConfig.setDefaultTableShardingStrategy(mock(ShardingStrategyConfiguration.class));
+ assertFalse(checker.isEmpty(ruleConfig));
+ }
+
+ @Test
+ void assertIsEmpty() {
+ assertTrue(checker.isEmpty(new ShardingRuleConfiguration()));
+ }
+}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
index 9bee2e04f13..d0daec45618 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
@@ -23,11 +23,4 @@ import
org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
* Database rule configuration.
*/
public interface DatabaseRuleConfiguration extends RuleConfiguration {
-
- /**
- * Is this configuration is empty.
- *
- * @return true or false
- */
- boolean isEmpty();
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfigurationEmptyChecker.java
similarity index 62%
copy from
infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfigurationEmptyChecker.java
index 9bee2e04f13..6f11544d0e2 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfiguration.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/scope/DatabaseRuleConfigurationEmptyChecker.java
@@ -17,17 +17,25 @@
package org.apache.shardingsphere.infra.config.rule.scope;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
/**
- * Database rule configuration.
+ * Database rule configuration empty checker.
+ *
+ * @param <T> type of database rule configuration
*/
-public interface DatabaseRuleConfiguration extends RuleConfiguration {
+@SingletonSPI
+public interface DatabaseRuleConfigurationEmptyChecker<T extends
DatabaseRuleConfiguration> extends TypedSPI {
/**
- * Is this configuration is empty.
+ * Whether rule configuration empty.
*
- * @return true or false
+ * @param ruleConfig rule configuration
+ * @return is empty or not
*/
- boolean isEmpty();
+ boolean isEmpty(T ruleConfig);
+
+ @Override
+ Class<T> getType();
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureDatabaseRuleConfiguration.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureDatabaseRuleConfiguration.java
index a5066c27274..50e7f4df814 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureDatabaseRuleConfiguration.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureDatabaseRuleConfiguration.java
@@ -20,9 +20,4 @@ package org.apache.shardingsphere.infra.rule.builder.fixture;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
public final class FixtureDatabaseRuleConfiguration implements
DatabaseRuleConfiguration {
-
- @Override
- public boolean isEmpty() {
- return false;
- }
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java
index 9cc5e5df5fb..1161a594d3f 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java
@@ -24,8 +24,10 @@ import
org.apache.shardingsphere.distsql.statement.rdl.rule.aware.StaticDataSour
import
org.apache.shardingsphere.distsql.statement.rdl.rule.database.DatabaseRuleDefinitionStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -62,7 +64,8 @@ public final class DropDatabaseRuleOperator implements
DatabaseRuleOperator {
RuleConfiguration toBeDroppedRuleConfig =
executor.buildToBeDroppedRuleConfiguration(sqlStatement);
metaDataManagerPersistService.removeRuleConfigurationItem(database.getName(),
toBeDroppedRuleConfig);
RuleConfiguration toBeAlteredRuleConfig =
executor.buildToBeAlteredRuleConfiguration(sqlStatement);
- if (null != toBeAlteredRuleConfig && ((DatabaseRuleConfiguration)
toBeAlteredRuleConfig).isEmpty()) {
+ if (null != toBeAlteredRuleConfig
+ &&
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
toBeAlteredRuleConfig.getClass()).isEmpty((DatabaseRuleConfiguration)
toBeAlteredRuleConfig)) {
YamlRuleConfiguration yamlRuleConfig = new
YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfiguration(currentRuleConfig);
metaDataManagerPersistService.removeRuleConfiguration(database.getName(),
Objects.requireNonNull(yamlRuleConfig.getClass().getAnnotation(RepositoryTupleEntity.class)).value());
} else {
diff --git
a/kernel/single/api/src/main/java/org/apache/shardingsphere/single/config/SingleRuleConfiguration.java
b/kernel/single/api/src/main/java/org/apache/shardingsphere/single/config/SingleRuleConfiguration.java
index 4151bb502e9..89b5ee2b6e1 100644
---
a/kernel/single/api/src/main/java/org/apache/shardingsphere/single/config/SingleRuleConfiguration.java
+++
b/kernel/single/api/src/main/java/org/apache/shardingsphere/single/config/SingleRuleConfiguration.java
@@ -49,9 +49,4 @@ public final class SingleRuleConfiguration implements
DatabaseRuleConfiguration,
public Optional<String> getDefaultDataSource() {
return Optional.ofNullable(defaultDataSource);
}
-
- @Override
- public boolean isEmpty() {
- return tables.isEmpty() && null == defaultDataSource;
- }
}
diff --git
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyChecker.java
similarity index 59%
copy from
features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
copy to
kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyChecker.java
index 56158c8689e..912f58d3e3f 100644
---
a/features/broadcast/api/src/main/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfiguration.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyChecker.java
@@ -15,26 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.broadcast.config;
+package org.apache.shardingsphere.single.checker;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
/**
- * Broadcast rule configuration.
+ * Single rule configuration empty checker.
*/
-@RequiredArgsConstructor
-@Getter
-public final class BroadcastRuleConfiguration implements
DatabaseRuleConfiguration, DistributedRuleConfiguration {
+public final class SingleRuleConfigurationEmptyChecker implements
DatabaseRuleConfigurationEmptyChecker<SingleRuleConfiguration> {
- private final Collection<String> tables;
+ @Override
+ public boolean isEmpty(final SingleRuleConfiguration ruleConfig) {
+ return ruleConfig.getTables().isEmpty() &&
!ruleConfig.getDefaultDataSource().isPresent();
+ }
@Override
- public boolean isEmpty() {
- return tables.isEmpty();
+ public Class<SingleRuleConfiguration> getType() {
+ return SingleRuleConfiguration.class;
}
}
diff --git
a/kernel/single/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
b/kernel/single/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
new file mode 100644
index 00000000000..4a0c35b255e
--- /dev/null
+++
b/kernel/single/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker
@@ -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.single.checker.SingleRuleConfigurationEmptyChecker
diff --git
a/kernel/single/api/src/test/java/org/apache/shardingsphere/single/config/SingleRuleConfigurationTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyCheckerTest.java
similarity index 54%
rename from
kernel/single/api/src/test/java/org/apache/shardingsphere/single/config/SingleRuleConfigurationTest.java
rename to
kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyCheckerTest.java
index c4a704649f5..a1c087b23a3 100644
---
a/kernel/single/api/src/test/java/org/apache/shardingsphere/single/config/SingleRuleConfigurationTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/SingleRuleConfigurationEmptyCheckerTest.java
@@ -15,31 +15,40 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.single.config;
+package org.apache.shardingsphere.single.checker;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Collections;
+
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class SingleRuleConfigurationTest {
+class SingleRuleConfigurationEmptyCheckerTest {
+
+ private SingleRuleConfigurationEmptyChecker checker;
+
+ @BeforeEach
+ void setUp() {
+ checker = (SingleRuleConfigurationEmptyChecker)
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
SingleRuleConfiguration.class);
+ }
@Test
void assertIsEmpty() {
- assertTrue(new SingleRuleConfiguration().isEmpty());
+ assertTrue(checker.isEmpty(new SingleRuleConfiguration()));
}
@Test
void assertIsNotEmptyWhenContainsTables() {
- SingleRuleConfiguration config = new SingleRuleConfiguration();
- config.getTables().add("foo_tbl");
- assertFalse(config.isEmpty());
+ assertFalse(checker.isEmpty(new
SingleRuleConfiguration(Collections.singleton("foo_tbl"), null)));
}
@Test
void assertIsNotEmptyWhenContainsDefaultDataSource() {
- SingleRuleConfiguration config = new SingleRuleConfiguration();
- config.setDefaultDataSource("foo_ds");
- assertFalse(config.isEmpty());
+ assertFalse(checker.isEmpty(new
SingleRuleConfiguration(Collections.emptyList(), "foo_ds")));
}
}
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java
index 72e3a1f6fb1..f6f66a4d80e 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java
@@ -19,12 +19,14 @@ package org.apache.shardingsphere.mode.metadata.manager;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rule.PartialRuleUpdateSupported;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory;
@@ -95,9 +97,9 @@ public final class DatabaseRuleConfigurationManager {
return;
}
rules.removeIf(each ->
each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass()));
- if (!((DatabaseRuleConfiguration) ruleConfig).isEmpty()) {
- rules.addAll(DatabaseRulesBuilder.build(databaseName,
database.getProtocolType(), database.getRuleMetaData().getRules(),
- ruleConfig, computeNodeInstanceContext,
database.getResourceMetaData()));
+ if
(!TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
ruleConfig.getClass()).isEmpty((DatabaseRuleConfiguration) ruleConfig)) {
+ rules.addAll(DatabaseRulesBuilder.build(
+ databaseName, database.getProtocolType(),
database.getRuleMetaData().getRules(), ruleConfig, computeNodeInstanceContext,
database.getResourceMetaData()));
}
refreshMetadata(databaseName, database, rules);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
index 1bbdeac8adc..433139ca1b5 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
@@ -21,13 +21,15 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
+import org.apache.shardingsphere.infra.exception.generic.FileIOException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.exception.generic.FileIOException;
import java.io.File;
import java.io.IOException;
@@ -106,12 +108,13 @@ public final class ExportUtils {
@SuppressWarnings({"rawtypes", "unchecked"})
private static void appendRuleConfigurations(final
Collection<RuleConfiguration> ruleConfigs, final StringBuilder stringBuilder) {
- if (ruleConfigs.isEmpty() || ruleConfigs.stream().allMatch(each ->
((DatabaseRuleConfiguration) each).isEmpty())) {
+ if (ruleConfigs.isEmpty()
+ || ruleConfigs.stream().allMatch(each ->
TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
each.getClass()).isEmpty((DatabaseRuleConfiguration) each))) {
return;
}
stringBuilder.append("rules:").append(System.lineSeparator());
for (Entry<RuleConfiguration, YamlRuleConfigurationSwapper> entry :
OrderedSPILoader.getServices(YamlRuleConfigurationSwapper.class,
ruleConfigs).entrySet()) {
- if (((DatabaseRuleConfiguration) entry.getKey()).isEmpty()) {
+ if
(TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class,
entry.getKey().getClass()).isEmpty((DatabaseRuleConfiguration) entry.getKey()))
{
continue;
}
stringBuilder.append(YamlEngine.marshal(Collections.singletonList(entry.getValue().swapToYamlConfiguration(entry.getKey()))));