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/04/19 15:32:13 UTC

[shardingsphere] branch master updated: Add mode support for spring namespace (#16932)

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 65c7bf78b9e Add mode support for spring namespace (#16932)
65c7bf78b9e is described below

commit 65c7bf78b9ec31bc74b68c7a6b290a97f0c25be0
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Tue Apr 19 23:32:02 2022 +0800

    Add mode support for spring namespace (#16932)
---
 .../resources/mode/spring-namespace/cluster.ftl    | 17 ++++++++++++++++
 .../mode/spring-namespace/config/cluster-etcd.ftl  | 23 ++++++++++++++++++++++
 .../spring-namespace/config/cluster-zookeeper.ftl  | 23 ++++++++++++++++++++++
 .../spring-namespace/config/standalone-file.ftl    | 22 +++++++++++++++++++++
 .../resources/mode/spring-namespace/standalone.ftl | 17 ++++++++++++++++
 .../jdbc/resources/properties/application.ftl      |  2 +-
 .../template/jdbc/resources/xml/application.ftl    | 15 ++++++++++++++
 7 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/cluster.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/cluster.ftl
new file mode 100644
index 00000000000..3acc5c2f83d
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/cluster.ftl
@@ -0,0 +1,17 @@
+<#--
+  ~ 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.
+  -->
+<shardingsphere:mode type="Cluster" repository-ref="clusterRepository" overwrite="true" />
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-etcd.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-etcd.ftl
new file mode 100644
index 00000000000..d44ea073964
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-etcd.ftl
@@ -0,0 +1,23 @@
+<#--
+  ~ 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.
+  -->
+
+<cluster:repository id="clusterRepository" type="etcd" namespace="generator_demo" server-lists="localhost:2379">
+    <props>
+        <prop key="max-retries">3</prop>
+        <prop key="operation-timeout-milliseconds">1000</prop>
+    </props>
+</cluster:repository>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-zookeeper.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-zookeeper.ftl
new file mode 100644
index 00000000000..85e0a8fbe1a
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/cluster-zookeeper.ftl
@@ -0,0 +1,23 @@
+<#--
+  ~ 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.
+  -->
+
+<cluster:repository id="clusterRepository" type="Zookeeper" namespace="generator_demo" server-lists="localhost:2181">
+    <props>
+        <prop key="max-retries">3</prop>
+        <prop key="operation-timeout-milliseconds">1000</prop>
+    </props>
+</cluster:repository>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/standalone-file.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/standalone-file.ftl
new file mode 100644
index 00000000000..cf452747bab
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/config/standalone-file.ftl
@@ -0,0 +1,22 @@
+<#--
+  ~ 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.
+  -->
+
+<standalone:repository id="standaloneRepository" type="File">
+    <props>
+        <prop key="path">generator_demo</prop>
+    </props>
+</standalone:repository>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/standalone.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/standalone.ftl
new file mode 100644
index 00000000000..32c468f7bb5
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/mode/spring-namespace/standalone.ftl
@@ -0,0 +1,17 @@
+<#--
+  ~ 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.
+  -->
+<shardingsphere:mode type="Standalone" repository-ref="standaloneRepository" overwrite="true" />
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/properties/application.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/properties/application.ftl
index 8671dd50414..f490a0a5ef0 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/properties/application.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/properties/application.ftl
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 <#if mode!="memory">
-    <#include "mode/spring-boot-starter/${mode}.ftl" />
+    <#include "../mode/spring-boot-starter/${mode}.ftl" />
 </#if>
 <#if framework?contains("mybatis")>
 
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 6b71fe5d0a2..1120a64cf6e 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
@@ -28,6 +28,8 @@
        xmlns:shadow="http://shardingsphere.apache.org/schema/shardingsphere/shadow"
        xmlns:database-discovery="http://shardingsphere.apache.org/schema/shardingsphere/database-discovery"
        xmlns:sql-parser="http://shardingsphere.apache.org/schema/shardingsphere/sql-parser"
+       xmlns:standalone="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone"
+       xmlns:cluster="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context
@@ -48,6 +50,10 @@
                            http://shardingsphere.apache.org/schema/shardingsphere/database-discovery/database-discovery.xsd
                            http://shardingsphere.apache.org/schema/shardingsphere/sql-parser 
                            http://shardingsphere.apache.org/schema/shardingsphere/sql-parser/sql-parser.xsd
+                           http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster
+                           http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster/repository.xsd
+                           http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone
+                           http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone/repository.xsd
                            ">
 <#assign package = feature?replace('-', '')?replace(',', '.') />
 
@@ -117,6 +123,10 @@
         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
     </bean>
 </#if>
+    
+<#if mode!="memory">
+    <#include "../mode/spring-namespace/config/${mode}.ftl" />
+</#if>
 <#assign ruleRefs="">
 <#list feature?split(",") as item>
     <#assign ruleRefs += toCamel(item) + "Rule" />
@@ -125,6 +135,11 @@
     </#if>
 </#list>
     <shardingsphere:data-source id="dataSource" data-source-names="ds_0, ds_1, ds_2" rule-refs="${ruleRefs}">
+        <#if mode?contains("cluster")>
+            <#include "../mode/spring-namespace/cluster.ftl" />
+        <#elseif mode?contains("standalone")>
+            <#include "../mode/spring-namespace/standalone.ftl" />
+        </#if>
         <props>
             <prop key="sql-show">true</prop>
         </props>