You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/01/30 13:33:21 UTC
[shardingsphere] branch master updated: Add ContextManagerBuilderParameter.isEmpty() (#15213)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 098ddff Add ContextManagerBuilderParameter.isEmpty() (#15213)
098ddff is described below
commit 098ddff7c5a49c3a5be4559ce179f0fc3a06c4d3
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Jan 30 21:32:04 2022 +0800
Add ContextManagerBuilderParameter.isEmpty() (#15213)
---
.../mode/manager/ContextManagerBuilderParameter.java | 10 ++++++++++
.../mode/manager/cluster/ClusterContextManagerBuilder.java | 7 +------
.../manager/standalone/StandaloneContextManagerBuilder.java | 7 +------
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
index 72e0b35..b28e5e9 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
@@ -46,4 +46,14 @@ public final class ContextManagerBuilderParameter {
private final Collection<String> labels;
private final InstanceDefinition instanceDefinition;
+
+ /**
+ * Whether is empty or not.
+ *
+ * @return is empty or not
+ */
+ public boolean isEmpty() {
+ return props.isEmpty() && globalRuleConfigs.isEmpty()
+ && schemaConfigs.entrySet().stream().allMatch(entry -> entry.getValue().getDataSources().isEmpty() && entry.getValue().getRuleConfigurations().isEmpty());
+ }
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 114ff58..548440f 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -88,17 +88,12 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
private void persistConfigurations(final MetaDataPersistService metaDataPersistService, final ContextManagerBuilderParameter parameter) {
boolean isOverwrite = parameter.getModeConfig().isOverwrite();
- if (!isEmptyLocalConfiguration(parameter)) {
+ if (!parameter.isEmpty()) {
metaDataPersistService.persistConfigurations(parameter.getSchemaConfigs(), parameter.getGlobalRuleConfigs(), parameter.getProps(), isOverwrite);
}
metaDataPersistService.persistInstanceLabels(parameter.getInstanceDefinition().getInstanceId().getId(), parameter.getLabels(), isOverwrite);
}
- private boolean isEmptyLocalConfiguration(final ContextManagerBuilderParameter parameter) {
- return parameter.getSchemaConfigs().entrySet().stream().allMatch(entry -> entry.getValue().getDataSources().isEmpty() && entry.getValue().getRuleConfigurations().isEmpty())
- && parameter.getGlobalRuleConfigs().isEmpty() && parameter.getProps().isEmpty();
- }
-
private Map<String, DataSource> getEffectiveDataSources(final MetaDataPersistService metaDataPersistService,
final String schemaName, final Map<String, DataSource> localDataSources) throws SQLException {
Map<String, DataSourceProperties> loadedDataSourcePropsMap = metaDataPersistService.getDataSourceService().load(schemaName);
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index 35b9254..b997288 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -73,16 +73,11 @@ public final class StandaloneContextManagerBuilder implements ContextManagerBuil
}
private void persistConfigurations(final MetaDataPersistService metaDataPersistService, final ContextManagerBuilderParameter parameter) {
- if (!isEmptyLocalConfiguration(parameter)) {
+ if (!parameter.isEmpty()) {
metaDataPersistService.persistConfigurations(parameter.getSchemaConfigs(), parameter.getGlobalRuleConfigs(), parameter.getProps(), parameter.getModeConfig().isOverwrite());
}
}
- private boolean isEmptyLocalConfiguration(final ContextManagerBuilderParameter parameter) {
- return parameter.getSchemaConfigs().entrySet().stream().allMatch(entry -> entry.getValue().getDataSources().isEmpty() && entry.getValue().getRuleConfigurations().isEmpty())
- && parameter.getGlobalRuleConfigs().isEmpty() && parameter.getProps().isEmpty();
- }
-
private Map<String, DataSource> getEffectiveDataSources(final MetaDataPersistService metaDataPersistService,
final String schemaName, final Map<String, DataSource> localDataSources) throws SQLException {
Map<String, DataSourceProperties> loadedDataSourcePropsMap = metaDataPersistService.getDataSourceService().load(schemaName);