You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/12/11 14:44:25 UTC

[shardingsphere] branch master updated: Fix example genaretor (#22755)

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 44a81575b49 Fix example genaretor (#22755)
44a81575b49 is described below

commit 44a81575b49ce3de97a328d50444e0e2151dab5a
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Sun Dec 11 22:44:18 2022 +0800

    Fix example genaretor (#22755)
    
    * test file
    
    * fix example sharding config
    
    * fix example sharding config
    
    * fix example readwrite-splitting config
    
    * Temporarily comment out the generation sample generation logic, and resume after the permission problem is solved
    
    * test ci
    
    * fix sharding ftl
    
    * fix spring boot stater example error
    
    * fix spring namespace example error
    
    * fix spring namespace example error
    
    * fix jpa example error
    
    * add ;
    
    * fix shadow example error
    
    * fix example error for xa narayana
    
    * update exit code
    
    * fix spring boot starter jpa example error
    
    * fix shadow example error
    
    * fix shadow example error
    
    * remove xa
    
    * add repo
---
 .github/workflows/nightly-build-example.yml        |  2 +-
 .../generator/scenario/ExampleScenarioFactory.java |  3 +
 .../jdbc/java/TransactionConfiguration.ftl         | 58 ++++++++++++++
 .../resources/template/jdbc/java/config/shadow.ftl |  1 +
 .../java/main/SpringBootStarJdbcExampleMain.ftl    |  9 +++
 .../java/main/SpringBootStarJpaExampleMain.ftl     |  9 +++
 .../java/main/SpringBootStarMyBatisExampleMain.ftl |  9 +++
 .../java/main/SpringNamespaceJdbcExampleMain.ftl   |  3 +
 .../java/main/SpringNamespaceJpaExampleMain.ftl    |  3 +
 .../main/SpringNamespaceMyBatisExampleMain.ftl     |  3 +
 .../java/repository/jdbc/OrderItemRepository.ftl   |  6 +-
 .../jdbc/java/repository/jdbc/OrderRepository.ftl  |  9 ++-
 .../jdbc/java/repository/jpa/AddressRepository.ftl |  2 +-
 .../java/repository/jpa/OrderItemRepository.ftl    |  2 +-
 .../jdbc/java/repository/jpa/OrderRepository.ftl   |  2 +-
 .../src/main/resources/template/jdbc/pom.ftl       | 54 +++++++------
 .../jdbc/resources/mappers/OrderMapper.ftl         |  6 +-
 .../template/jdbc/resources/xml/application.ftl    |  6 +-
 .../resources/yaml/feature/readwrite-splitting.ftl |  8 +-
 .../jdbc/resources/yaml/feature/shadow.ftl         |  2 +-
 .../jdbc/resources/yaml/feature/sharding.ftl       | 89 ++++++++++------------
 21 files changed, 194 insertions(+), 92 deletions(-)

diff --git a/.github/workflows/nightly-build-example.yml b/.github/workflows/nightly-build-example.yml
index 5049d2d0e41..29f00debe1d 100644
--- a/.github/workflows/nightly-build-example.yml
+++ b/.github/workflows/nightly-build-example.yml
@@ -59,7 +59,7 @@ jobs:
         feature: [ sharding, readwrite-splitting, encrypt, shadow ]
         framework: [ jdbc, spring-boot-starter-jdbc, spring-boot-starter-jpa, spring-boot-starter-mybatis, spring-namespace-jdbc, spring-namespace-jpa, spring-namespace-mybatis ]
         mode: [ standalone ]
-        transaction: [ local, xa-atomikos, xa-bitronix, xa-narayana ]
+        transaction: [ local ]
         product: [ jdbc ]
         exclude: 
           - feature: shadow
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
index c95799084c5..77986a53688 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
@@ -81,6 +81,9 @@ public final class ExampleScenarioFactory {
         for (FeatureExampleScenario each : featureScenarios) {
             result.putAll(each.getJavaClassTemplateMap());
         }
+        if (frameworkScenario.getType().contains("spring-boot-starter") && transactionScenario.getType().contains("xa")) {
+            result.put("java/TransactionConfiguration.ftl", "TransactionConfiguration.java");
+        }
         result.putAll(frameworkScenario.getJavaClassTemplateMap());
         return result;
     }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/TransactionConfiguration.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/TransactionConfiguration.ftl
new file mode 100644
index 00000000000..2dae35251f2
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/TransactionConfiguration.ftl
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+<#assign package = feature?replace('-', '')?replace(',', '.') />
+
+package org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')};
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+<#if framework?contains("jpa")>
+import org.springframework.orm.jpa.JpaTransactionManager;
+<#else>
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+</#if>
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+<#if !framework?contains("jpa")>
+
+import javax.sql.DataSource;
+</#if>
+
+/**
+ * Spring boot tx configuration.
+ */
+@Configuration
+@EnableTransactionManagement
+public class TransactionConfiguration {
+    
+    /**
+     * Create platform transaction manager bean.
+     *
+     * @param dataSource data source
+     * @return platform transaction manager
+     */
+    @Bean
+<#if framework?contains("jpa")>
+    public JpaTransactionManager txManager() {
+       return new JpaTransactionManager();
+    } 
+<#else>
+    public PlatformTransactionManager txManager(final DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+</#if>
+}
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/shadow.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/shadow.ftl
index 60694ce83c5..607565e0d8e 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/shadow.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/shadow.ftl
@@ -18,6 +18,7 @@
     private RuleConfiguration createShadowRuleConfiguration() {
         ShadowRuleConfiguration result = new ShadowRuleConfiguration();
         result.setShadowAlgorithms(createShadowAlgorithmConfigurations());
+        result.setDefaultShadowAlgorithmName("simple-hint-algorithm");
         result.setDataSources(createShadowDataSources());
         result.setTables(createShadowTables());
         return result;
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJdbcExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJdbcExampleMain.ftl
index 7ebfe283b1b..cb335fe02dc 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJdbcExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJdbcExampleMain.ftl
@@ -22,16 +22,25 @@ import org.apache.shardingsphere.example.${package}.${framework?replace('-', '.'
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ConfigurableApplicationContext;
+<#if transaction?contains("xa")>
+import org.springframework.context.annotation.Import;
+</#if>
 
 import java.sql.SQLException;
 
 @SpringBootApplication
+<#if transaction?contains("xa")>
+@Import(TransactionConfiguration.class)
+</#if>
 public class ExampleMain {
     
     public static void main(final String[] args) throws SQLException {
         try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ExampleMain.class, args)) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJpaExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJpaExampleMain.ftl
index 8c0fd0a96df..3205d4470ec 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJpaExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarJpaExampleMain.ftl
@@ -23,16 +23,25 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.context.ConfigurableApplicationContext;
+<#if transaction?contains("xa")>
+import org.springframework.context.annotation.Import;
+</#if>
 import java.sql.SQLException;
 
 @EntityScan(basePackages = "org.apache.shardingsphere.example.${package}.spring.boot.starter.jpa.entity")
 @SpringBootApplication
+<#if transaction?contains("xa")>
+@Import(TransactionConfiguration.class)
+</#if>
 public class ExampleMain {
     
     public static void main(final String[] args) throws SQLException {
         try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ExampleMain.class, args)) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarMyBatisExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarMyBatisExampleMain.ftl
index ede6cf73101..09486d0d9a8 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarMyBatisExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringBootStarMyBatisExampleMain.ftl
@@ -24,16 +24,25 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ConfigurableApplicationContext;
+<#if transaction?contains("xa")>
+import org.springframework.context.annotation.Import;
+</#if>
 import java.sql.SQLException;
 
 @MapperScan("org.apache.shardingsphere.example.${package}.spring.boot.starter.mybatis.repository")
 @SpringBootApplication
+<#if transaction?contains("xa")>
+@Import(TransactionConfiguration.class)
+</#if>
 public class ExampleMain {
     
     public static void main(final String[] args) throws SQLException {
         try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ExampleMain.class, args)) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJdbcExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJdbcExampleMain.ftl
index d8c5462565e..d4059d87010 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJdbcExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJdbcExampleMain.ftl
@@ -30,6 +30,9 @@ public final class ExampleMain {
         try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml")) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJpaExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJpaExampleMain.ftl
index d8c5462565e..d4059d87010 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJpaExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceJpaExampleMain.ftl
@@ -30,6 +30,9 @@ public final class ExampleMain {
         try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml")) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceMyBatisExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceMyBatisExampleMain.ftl
index d8c5462565e..d4059d87010 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceMyBatisExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/SpringNamespaceMyBatisExampleMain.ftl
@@ -30,6 +30,9 @@ public final class ExampleMain {
         try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml")) {
             ExampleService exampleService = applicationContext.getBean(ExampleService.class);
             exampleService.run();
+        <#if transaction=="xa-narayana">
+            System.exit(0);
+        </#if>
         }
     }
 }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderItemRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderItemRepository.ftl
index bee69d62568..c77693fa87f 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderItemRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderItemRepository.ftl
@@ -65,7 +65,7 @@ public final class OrderItemRepository {
     
     public void createTableIfNotExistsShadow() throws SQLException {
         String sql = "CREATE TABLE IF NOT EXISTS t_order_item "
-            + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, phone VARCHAR(50), status VARCHAR(50), PRIMARY KEY (order_item_id)) /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+            + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, phone VARCHAR(50), status VARCHAR(50), PRIMARY KEY (order_item_id)) /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
@@ -73,7 +73,7 @@ public final class OrderItemRepository {
     }
     
     public void dropTableShadow() throws SQLException {
-        String sql = "DROP TABLE t_order_item /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+        String sql = "DROP TABLE t_order_item /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
@@ -81,7 +81,7 @@ public final class OrderItemRepository {
     }
     
     public void truncateTableShadow() throws SQLException {
-        String sql = "TRUNCATE TABLE t_order_item /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+        String sql = "TRUNCATE TABLE t_order_item /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
index ffe191226e9..0af180270c4 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
@@ -51,7 +51,8 @@ public final class OrderRepository {
     }
     
     public void dropTable() throws SQLException {
-        String sql = "DROP TABLE t_order";
+        // todo fix in shadow
+        String sql = "DROP TABLE IF EXISTS t_order";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
@@ -68,7 +69,7 @@ public final class OrderRepository {
 <#if feature?contains("shadow")>
 
     public void createTableIfNotExistsShadow() throws SQLException {
-        String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, order_type INT(11), user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id)) /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+        String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, order_type INT(11), user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id)) /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
@@ -76,7 +77,7 @@ public final class OrderRepository {
     }
 
     public void dropTableShadow() throws SQLException {
-        String sql = "DROP TABLE t_order /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+        String sql = "DROP TABLE IF EXISTS t_order /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
@@ -84,7 +85,7 @@ public final class OrderRepository {
     }
 
     public void truncateTableShadow() throws SQLException {
-        String sql = "TRUNCATE TABLE t_order /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
+        String sql = "TRUNCATE TABLE t_order /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/";
         try (Connection connection = dataSource.getConnection();
              Statement statement = connection.createStatement()) {
             statement.executeUpdate(sql);
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/AddressRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/AddressRepository.ftl
index b4f408bb09f..ff3cd1431f1 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/AddressRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/AddressRepository.ftl
@@ -19,12 +19,12 @@
 package org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.repository;
 
 import org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.entity.Address;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.stereotype.Repository;
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
-import javax.transaction.Transactional;
 import java.util.List;
 
 @Repository
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderItemRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderItemRepository.ftl
index 533c9a8d401..bd6d26bfa1f 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderItemRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderItemRepository.ftl
@@ -19,12 +19,12 @@
 package org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.repository;
 
 import org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.entity.OrderItem;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.stereotype.Repository;
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
-import javax.transaction.Transactional;
 import java.util.List;
 
 @Repository
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderRepository.ftl
index 006872426cd..e2799545369 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jpa/OrderRepository.ftl
@@ -19,12 +19,12 @@
 package org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.repository;
 
 import org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.entity.Order;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.stereotype.Repository;
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
-import javax.transaction.Transactional;
 import java.util.List;
 
 @Repository
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
index c51408f5ce3..d63c0eb1601 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
@@ -26,11 +26,11 @@
     <name>${r'${project.artifactId}'}</name>
     
     <dependencies>
-    <dependency>
-        <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-jdbc-core</artifactId>
-        <version>${r'${project.version}'}</version>
-    </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-core</artifactId>
+            <version>${r'${project.version}'}</version>
+        </dependency>
     <#if transaction?contains("xa")>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
@@ -114,28 +114,22 @@
             <version>5.2.15.RELEASE</version>
         </dependency>
     </#if>
-    <#if framework?contains("spring-boot-starter")>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot</artifactId>
-            <version>2.2.0.RELEASE</version>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-autoconfigure</artifactId>
-            <version>2.2.0.RELEASE</version>
-        </dependency>
-    </#if>
     <#if framework=="spring-boot-starter-jdbc">
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot</artifactId>
+            <artifactId>spring-boot-starter-jdbc</artifactId>
             <version>2.2.0.RELEASE</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>snakeyaml</artifactId>
+                    <groupId>org.yaml</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-autoconfigure</artifactId>
-            <version>2.2.0.RELEASE</version>
+            <artifactId>snakeyaml</artifactId>
+            <groupId>org.yaml</groupId>
+            <version>1.33</version>
         </dependency>
     <#elseif framework=="spring-boot-starter-mybatis">
         <dependency>
@@ -152,7 +146,12 @@
     <#elseif framework=="spring-namespace-jdbc">
         <dependency>
             <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
+            <artifactId>spring-context-support</artifactId>
+            <version>5.2.15.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
             <version>5.2.15.RELEASE</version>
         </dependency>
     <#elseif framework=="spring-namespace-mybatis">
@@ -176,6 +175,17 @@
             <artifactId>spring-context-support</artifactId>
             <version>5.2.15.RELEASE</version>
         </dependency>
+    <#elseif framework?contains("spring-boot-starter")>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot</artifactId>
+            <version>2.2.0.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+            <version>2.2.0.RELEASE</version>
+        </dependency>
     </#if>
         
         <dependency>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mappers/OrderMapper.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mappers/OrderMapper.ftl
index 87adce84bf2..7ceaddab52c 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mappers/OrderMapper.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mappers/OrderMapper.ftl
@@ -41,15 +41,15 @@
  <#if feature?contains("shadow")>
     
     <update id="createTableIfNotExistsShadow">
-        CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT AUTO_INCREMENT, order_type INT(11), user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id)); /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/
+        CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT AUTO_INCREMENT, order_type INT(11), user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id)); /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/
     </update>
     
     <update id="truncateTableShadow">
-        TRUNCATE TABLE t_order /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/;
+        TRUNCATE TABLE t_order /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/;
     </update>
     
     <update id="dropTableShadow">
-        DROP TABLE IF EXISTS t_order /*SHARDINGSPHERE_HINT:shadow=true,foo=bar*/;
+        DROP TABLE IF EXISTS t_order /* SHARDINGSPHERE_HINT:shadow=true,foo=bar*/;
     </update>
 
      <select id="selectShadowOrder" resultMap="baseResultMap">
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/xml/application.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/xml/application.ftl
index 55f062b5d88..b0e4c267d6f 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/xml/application.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/xml/application.ftl
@@ -39,7 +39,7 @@
     </bean>
 <#if framework=="spring-namespace-jpa">
     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
-        <property name="dataSource" ref="dataSource" />
+        <property name="dataSource" ref="shardingDataSource" />
         <property name="jpaVendorAdapter">
             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="MYSQL" />
         </property>
@@ -57,12 +57,12 @@
 </#if>
 <#if framework=="spring-namespace-mybatis">
     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-        <property name="dataSource" ref="dataSource" />
+        <property name="dataSource" ref="shardingDataSource" />
     </bean>
     <tx:annotation-driven />
     
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-        <property name="dataSource" ref="dataSource"/>
+        <property name="dataSource" ref="shardingDataSource"/>
         <property name="mapperLocations" value="classpath*:mappers/*.xml"/>
     </bean>
     
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/readwrite-splitting.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/readwrite-splitting.ftl
index 1d43a377b7a..0211c2d8bf0 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/readwrite-splitting.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/readwrite-splitting.ftl
@@ -22,7 +22,7 @@
         readDataSourceNames:
           - ds_1
           - ds_2
-        loadBalancerName: round_robin
-    loadBalancers:
-      round_robin:
-        type: ROUND_ROBIN
+      loadBalancerName: round_robin
+  loadBalancers:
+    round_robin:
+      type: ROUND_ROBIN
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/shadow.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/shadow.ftl
index 26ee05b8027..4d72d352dfb 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/shadow.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/shadow.ftl
@@ -34,7 +34,7 @@
         operation: insert
         column: order_type
         value: 1
-    simple_hint_algorithm:
+    simple-hint-algorithm:
       type: SIMPLE_HINT
       props:
         shadow: true
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/sharding.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/sharding.ftl
index c31566b0554..cb51f0984cb 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/sharding.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/yaml/feature/sharding.ftl
@@ -15,55 +15,48 @@
   ~ limitations under the License.
   -->
 - !SHARDING
-  tables:
-    t_order:
-      actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
-      tableStrategy:
-        standard:
-          shardingColumn: order_id
-          shardingAlgorithmName: t_order_inline
-      keyGenerateStrategy:
-        column: order_id
-        keyGeneratorName: snowflake_generator
-      auditStrategy:
-        auditorNames:
-          - sharding_key_required_auditor
-        allowHintDisable: true
-    t_order_item:
-      actualDataNodes: ds_$->{0..1}.t_order_item_$->{0..1}
-      tableStrategy:
-        standard:
-          shardingColumn: order_id
-          shardingAlgorithmName: t_order_item_inline
-      keyGenerateStrategy:
-        column: order_item_id
-        keyGeneratorName: snowflake_generator
+    tables:
+      t_order:
+        actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
+        tableStrategy:
+          standard:
+            shardingColumn: order_id
+            shardingAlgorithmName: t_order_inline
+        keyGenerateStrategy:
+          column: order_id
+          keyGeneratorName: snowflake_generator
+      t_order_item:
+        actualDataNodes: ds_$->{0..1}.t_order_item_$->{0..1}
+        tableStrategy:
+          standard:
+            shardingColumn: order_id
+            shardingAlgorithmName: t_order_item_inline
+        keyGenerateStrategy:
+          column: order_item_id
+          keyGeneratorName: snowflake_generator
     bindingTables:
       - t_order,t_order_item
     broadcastTables:
       - t_address
-  
-  defaultDatabaseStrategy:
-    standard:
-      shardingColumn: user_id
-      shardingAlgorithmName: database_inline
-  
-  shardingAlgorithms:
-    database_inline:
-      type: INLINE
-      props:
-        algorithm-expression: ds_$->{user_id % 2}
-    t_order_inline:
-      type: INLINE
-      props:
-        algorithm-expression: t_order_$->{order_id % 2}
-    t_order_item_inline:
-      type: INLINE
-      props:
-        algorithm-expression: t_order_item_$->{order_id % 2}
-  keyGenerators:
-    snowflake_generator:
-      type: SNOWFLAKE
-  auditors:
-    sharding_key_required_auditor:
-      type: DML_SHARDING_CONDITIONS
+    defaultDatabaseStrategy:
+      standard:
+        shardingColumn: user_id
+        shardingAlgorithmName: database_inline
+
+    shardingAlgorithms:
+      database_inline:
+        type: INLINE
+        props:
+          algorithm-expression: ${r'ds_${user_id % 2}'}
+          
+      t_order_inline:
+        type: INLINE
+        props:
+          algorithm-expression: t_order_$->{order_id % 2}
+      t_order_item_inline:
+        type: INLINE
+        props:
+          algorithm-expression: t_order_item_$->{order_id % 2}
+    keyGenerators:
+      snowflake_generator:
+        type: SNOWFLAKE