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 50076bdeaec Add NewYamlTransactionRuleConfigurationSwapperto adpate 
new metadata structure. (#26245)
50076bdeaec is described below

commit 50076bdeaecc705aa9aa6cb890049be950913052
Author: liguoping <[email protected]>
AuthorDate: Sat Jun 10 16:33:06 2023 +0800

    Add NewYamlTransactionRuleConfigurationSwapperto adpate new metadata 
structure. (#26245)
    
    * Add NewYamlTransactionRuleConfigurationSwapper
    
    * checkstyle
    
    * bug fixed
    
    * spi
    
    * update
    
    * u t
---
 .../NewYamlAuthorityRuleConfigurationSwapper.java  |  1 -
 ...NewYamlTransactionRuleConfigurationSwapper.java | 78 ++++++++++++++++++++++
 ...ig.swapper.rule.NewYamlRuleConfigurationSwapper | 18 +++++
 ...amlTransactionRuleConfigurationSwapperTest.java | 40 +++++++++++
 4 files changed, 136 insertions(+), 1 deletion(-)

diff --git 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
index c95cfd2ab82..d1b2f87bc33 100644
--- 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
+++ 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
@@ -45,7 +45,6 @@ public final class NewYamlAuthorityRuleConfigurationSwapper 
implements NewYamlRu
     @Override
     public Collection<YamlDataNode> swapToDataNodes(final 
AuthorityRuleConfiguration data) {
         return Collections.singletonList(new 
YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()),
 YamlEngine.marshal(swapToYamlConfiguration(data))));
-        
     }
     
     private YamlAuthorityRuleConfiguration swapToYamlConfiguration(final 
AuthorityRuleConfiguration data) {
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
new file mode 100644
index 00000000000..a80e5d63472
--- /dev/null
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
@@ -0,0 +1,78 @@
+/*
+ * 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.transaction.yaml.swapper;
+
+import org.apache.shardingsphere.infra.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import 
org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
+import 
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+import org.apache.shardingsphere.transaction.constant.TransactionOrder;
+import 
org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * TODO Rename YamlTransactionRuleConfigurationSwapper when metadata structure 
adjustment completed. #25485
+ * New YAML Transaction rule configuration swapper.
+ */
+public final class NewYamlTransactionRuleConfigurationSwapper implements 
NewYamlRuleConfigurationSwapper<TransactionRuleConfiguration> {
+
+    @Override
+    public Collection<YamlDataNode> swapToDataNodes(final 
TransactionRuleConfiguration data) {
+        return Collections.singletonList(new 
YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()),
 YamlEngine.marshal(swapToYamlConfiguration(data))));
+    }
+    
+    private YamlTransactionRuleConfiguration swapToYamlConfiguration(final 
TransactionRuleConfiguration data) {
+        YamlTransactionRuleConfiguration result = new 
YamlTransactionRuleConfiguration();
+        result.setDefaultType(data.getDefaultType());
+        result.setProviderType(data.getProviderType());
+        result.setProps(data.getProps());
+        return result;
+    }
+    
+    @Override
+    public TransactionRuleConfiguration swapToObject(final 
Collection<YamlDataNode> dataNodes) {
+        for (YamlDataNode each : dataNodes) {
+            Optional<String> version = 
GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), 
each.getKey());
+            if (!version.isPresent()) {
+                continue;
+            }
+            return YamlEngine.unmarshal(each.getValue(), 
TransactionRuleConfiguration.class);
+        }
+        return new TransactionRuleConfiguration("", "", new Properties());
+    }
+    
+    @Override
+    public Class<TransactionRuleConfiguration> getTypeClass() {
+        return TransactionRuleConfiguration.class;
+    }
+    
+    @Override
+    public String getRuleTagName() {
+        return "TRANSACTION";
+    }
+    
+    @Override
+    public int getOrder() {
+        return TransactionOrder.ORDER;
+    }
+}
diff --git 
a/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper
 
b/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper
new file mode 100644
index 00000000000..71fba71773e
--- /dev/null
+++ 
b/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper
@@ -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.transaction.yaml.swapper.NewYamlTransactionRuleConfigurationSwapper
diff --git 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapperTest.java
 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapperTest.java
new file mode 100644
index 00000000000..0e5f3c06918
--- /dev/null
+++ 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapperTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.transaction.yaml.swapper;
+
+import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import 
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+// TODO Rename YamlTransactionRuleConfigurationSwapperTest when metadata 
structure adjustment completed. #25485
+class NewYamlTransactionRuleConfigurationSwapperTest {
+    
+    private final NewYamlTransactionRuleConfigurationSwapper swapper = new 
NewYamlTransactionRuleConfigurationSwapper();
+    
+    @Test
+    void assertSwapToDataNodes() {
+        Collection<YamlDataNode> actual = swapper.swapToDataNodes(new 
TransactionRuleConfiguration("", "", new Properties()));
+        assertThat(actual.iterator().next().getKey(), 
is("/rules/transaction"));
+    }
+}

Reply via email to