This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 08ec5a26d81 Remove PersistRepositoryConfigurationYamlSwapperEngine
(#19860)
08ec5a26d81 is described below
commit 08ec5a26d8160a59a62b3e986a21f81fb7df9243
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 4 13:18:39 2022 +0800
Remove PersistRepositoryConfigurationYamlSwapperEngine (#19860)
* Remove PersistRepositoryConfigurationYamlSwapperEngine
* Remove PersistRepositoryConfigurationYamlSwapperEngine
---
.../swapper/mode/ModeConfigurationYamlSwapper.java | 12 ++---
...stRepositoryConfigurationYamlSwapperEngine.java | 51 ----------------------
...tRepositoryConfigurationYamlSwapperFactory.java | 5 ++-
...nRuleAlteredActionConfigurationYamlSwapper.java | 14 +++---
...positoryConfigurationYamlSwapperEngineTest.java | 50 ---------------------
5 files changed, 16 insertions(+), 116 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/ModeConfigurationYamlSwapper.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/ModeConfigurationYamlSwapper.java
index 8bda3c85d00..7e5ab4eb263 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/ModeConfigurationYamlSwapper.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/ModeConfigurationYamlSwapper.java
@@ -32,7 +32,8 @@ public final class ModeConfigurationYamlSwapper implements
YamlConfigurationSwap
YamlModeConfiguration result = new YamlModeConfiguration();
result.setType(data.getType());
if (null != data.getRepository()) {
- result.setRepository(new
PersistRepositoryConfigurationYamlSwapperEngine().swapToYamlConfiguration(data.getType(),
data.getRepository()));
+
PersistRepositoryConfigurationYamlSwapper<PersistRepositoryConfiguration>
swapper =
PersistRepositoryConfigurationYamlSwapperFactory.getInstance(data.getType());
+
result.setRepository(swapper.swapToYamlConfiguration(data.getRepository()));
}
result.setOverwrite(data.isOverwrite());
return result;
@@ -40,9 +41,10 @@ public final class ModeConfigurationYamlSwapper implements
YamlConfigurationSwap
@Override
public ModeConfiguration swapToObject(final YamlModeConfiguration
yamlConfig) {
- PersistRepositoryConfiguration repositoryConfig = null ==
yamlConfig.getRepository()
- ? null
- : new
PersistRepositoryConfigurationYamlSwapperEngine().swapToObject(yamlConfig.getType(),
yamlConfig.getRepository());
- return new ModeConfiguration(yamlConfig.getType(), repositoryConfig,
yamlConfig.isOverwrite());
+ if (null == yamlConfig.getRepository()) {
+ return new ModeConfiguration(yamlConfig.getType(), null,
yamlConfig.isOverwrite());
+ }
+
PersistRepositoryConfigurationYamlSwapper<PersistRepositoryConfiguration>
swapper =
PersistRepositoryConfigurationYamlSwapperFactory.getInstance(yamlConfig.getType());
+ return new ModeConfiguration(yamlConfig.getType(),
swapper.swapToObject(yamlConfig.getRepository()), yamlConfig.isOverwrite());
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperEngine.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperEngine.java
deleted file mode 100644
index 513997c30ad..00000000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperEngine.java
+++ /dev/null
@@ -1,51 +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.infra.yaml.config.swapper.mode;
-
-import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import
org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlPersistRepositoryConfiguration;
-
-/**
- * Persist repository configuration YAML swapper engine.
- */
-public final class PersistRepositoryConfigurationYamlSwapperEngine {
-
- /**
- * Swap to YAML configuration.
- *
- * @param type persist repository type
- * @param config persist repository configuration
- * @return YAML persist repository configuration
- */
- @SuppressWarnings("unchecked")
- public YamlPersistRepositoryConfiguration swapToYamlConfiguration(final
String type, final PersistRepositoryConfiguration config) {
- return (YamlPersistRepositoryConfiguration)
PersistRepositoryConfigurationYamlSwapperFactory.getInstance(type).swapToYamlConfiguration(config);
- }
-
- /**
- * Swap to YAML configuration.
- *
- * @param type persist repository type
- * @param yamlConfig YAML persist repository configuration
- * @return persist repository configuration
- */
- @SuppressWarnings("unchecked")
- public PersistRepositoryConfiguration swapToObject(final String type,
final YamlPersistRepositoryConfiguration yamlConfig) {
- return (PersistRepositoryConfiguration)
PersistRepositoryConfigurationYamlSwapperFactory.getInstance(type).swapToObject(yamlConfig);
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperFactory.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperFactory.java
index 5a3e7019574..1555dd47f2f 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperFactory.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/PersistRepositoryConfigurationYamlSwapperFactory.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.infra.yaml.config.swapper.mode;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
@@ -26,7 +27,6 @@ import
org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
* Persist repository configuration YAML swapper factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@SuppressWarnings("rawtypes")
public final class PersistRepositoryConfigurationYamlSwapperFactory {
static {
@@ -39,7 +39,8 @@ public final class
PersistRepositoryConfigurationYamlSwapperFactory {
* @param type swapper type
* @return got instance
*/
- public static PersistRepositoryConfigurationYamlSwapper getInstance(final
String type) {
+ @SuppressWarnings("unchecked")
+ public static
PersistRepositoryConfigurationYamlSwapper<PersistRepositoryConfiguration>
getInstance(final String type) {
return
TypedSPIRegistry.getRegisteredService(PersistRepositoryConfigurationYamlSwapper.class,
type);
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rulealtered/OnRuleAlteredActionConfigurationYamlSwapper.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rulealtered/OnRuleAlteredActionConfigurationYamlSwapper.java
index 86ff6b8466a..501689de0c3 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rulealtered/OnRuleAlteredActionConfigurationYamlSwapper.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rulealtered/OnRuleAlteredActionConfigurationYamlSwapper.java
@@ -81,10 +81,9 @@ public final class
OnRuleAlteredActionConfigurationYamlSwapper implements YamlCo
@Override
public InputConfiguration swapToObject(final YamlInputConfiguration
yamlConfig) {
- if (null == yamlConfig) {
- return null;
- }
- return new InputConfiguration(yamlConfig.getWorkerThread(),
yamlConfig.getBatchSize(), yamlConfig.getShardingSize(),
+ return null == yamlConfig
+ ? null
+ : new InputConfiguration(yamlConfig.getWorkerThread(),
yamlConfig.getBatchSize(), yamlConfig.getShardingSize(),
ALGORITHM_CONFIG_YAML_SWAPPER.swapToObject(yamlConfig.getRateLimiter()));
}
}
@@ -105,10 +104,9 @@ public final class
OnRuleAlteredActionConfigurationYamlSwapper implements YamlCo
@Override
public OutputConfiguration swapToObject(final YamlOutputConfiguration
yamlConfig) {
- if (null == yamlConfig) {
- return null;
- }
- return new OutputConfiguration(yamlConfig.getWorkerThread(),
yamlConfig.getBatchSize(),
ALGORITHM_CONFIG_YAML_SWAPPER.swapToObject(yamlConfig.getRateLimiter()));
+ return null == yamlConfig
+ ? null
+ : new OutputConfiguration(yamlConfig.getWorkerThread(),
yamlConfig.getBatchSize(),
ALGORITHM_CONFIG_YAML_SWAPPER.swapToObject(yamlConfig.getRateLimiter()));
}
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/PersistRepositoryConfigurationYamlSwapperEngineTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/PersistRepositoryConfigurationYamlSwapperEngineTest.java
deleted file mode 100644
index 16bbffb571b..00000000000
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/PersistRepositoryConfigurationYamlSwapperEngineTest.java
+++ /dev/null
@@ -1,50 +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.mode.manager.standalone.yaml;
-
-import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import
org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlPersistRepositoryConfiguration;
-import
org.apache.shardingsphere.infra.yaml.config.swapper.mode.PersistRepositoryConfigurationYamlSwapperEngine;
-import
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryConfiguration;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class PersistRepositoryConfigurationYamlSwapperEngineTest {
-
- @Test
- public void assertSwapToYamlConfiguration() {
- String type = "Standalone";
- StandalonePersistRepositoryConfiguration
standalonePersistRepositoryConfig = new
StandalonePersistRepositoryConfiguration("Standalone", new Properties());
- YamlPersistRepositoryConfiguration yamlPersistRepositoryConfig = new
PersistRepositoryConfigurationYamlSwapperEngine().swapToYamlConfiguration(type,
standalonePersistRepositoryConfig);
-
assertTrue(yamlPersistRepositoryConfig.getType().equalsIgnoreCase("Standalone"));
- }
-
- @Test
- public void assertSwapToObject() {
- String type = "Standalone";
- YamlPersistRepositoryConfiguration yamlPersistRepositoryConfig = new
YamlPersistRepositoryConfiguration();
- yamlPersistRepositoryConfig.setType("Standalone");
- PersistRepositoryConfiguration persistRepositoryConfig = new
PersistRepositoryConfigurationYamlSwapperEngine().swapToObject(type,
yamlPersistRepositoryConfig);
- assertThat(persistRepositoryConfig.getType(), is("Standalone"));
- }
-}