You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2021/10/22 07:22:29 UTC

[shardingsphere] branch master updated: Migrate the readwrite-splitting example. (#13218)

This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 3f67299  Migrate the readwrite-splitting example. (#13218)
3f67299 is described below

commit 3f6729997d64628ca65fa84ee7aa9cf22fedaee4
Author: yx9o <ya...@163.com>
AuthorDate: Fri Oct 22 15:21:15 2021 +0800

    Migrate the readwrite-splitting example. (#13218)
    
    * Migrate the readwrite-splitting example.
    
    * Update
    
    * Update pom.xml
---
 .../jdbc/EncryptRawJavaConfigurationExample.java   |  4 +--
 .../jdbc/EncryptRawYamlConfigurationExample.java   |  2 +-
 .../jdbc/config/EncryptDatabasesConfiguration.java |  2 +-
 .../mybatis/EncryptSpringBootMybatisExample.java   |  2 +-
 .../EncryptSpringNamespaceMybatisExample.java      |  2 +-
 .../single-feature-example/pom.xml                 |  3 +-
 .../ReadwriteSplittingSpringBootJpaExample.java}   | 14 ++++-----
 .../application-readwrite-splitting.properties     |  0
 .../src/main/resources/application.properties      |  6 +---
 .../src/main/resources/logback.xml                 | 36 ++++++++++++++++++++++
 .../src/main/resources/application.properties      |  1 -
 11 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawJavaConfigurationExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawJavaConfigurationExample.java
similarity index 91%
rename from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawJavaConfigurationExample.java
rename to examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawJavaConfigurationExample.java
index 2665172..4728f9d 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawJavaConfigurationExample.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawJavaConfigurationExample.java
@@ -19,13 +19,13 @@
  * Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.raw.jdbc;
+package org.apache.shardingsphere.example.encrypt.raw.jdbc;
 
 import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
 import org.apache.shardingsphere.example.core.api.service.ExampleService;
 import org.apache.shardingsphere.example.core.jdbc.repository.UserRepositoryImpl;
 import org.apache.shardingsphere.example.core.jdbc.service.UserServiceImpl;
-import org.apache.shardingsphere.example.encrypt.table.raw.jdbc.config.EncryptDatabasesConfiguration;
+import org.apache.shardingsphere.example.encrypt.raw.jdbc.config.EncryptDatabasesConfiguration;
 
 import javax.sql.DataSource;
 import java.sql.SQLException;
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawYamlConfigurationExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawYamlConfigurationExample.java
similarity index 96%
rename from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawYamlConfigurationExample.java
rename to examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawYamlConfigurationExample.java
index 5886aaa..5d53434 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/EncryptRawYamlConfigurationExample.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/EncryptRawYamlConfigurationExample.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.raw.jdbc;
+package org.apache.shardingsphere.example.encrypt.raw.jdbc;
 
 import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
 import org.apache.shardingsphere.example.core.api.service.ExampleService;
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
similarity index 97%
rename from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java
rename to examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
index a0a6790..3ef5309 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/raw/jdbc/config/EncryptDatabasesConfiguration.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.raw.jdbc.config;
+package org.apache.shardingsphere.example.encrypt.raw.jdbc.config;
 
 import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
similarity index 96%
copy from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
copy to examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
index 8b3689d..51d4872 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.spring.boot.mybatis;
+package org.apache.shardingsphere.example.encrypt.spring.boot.mybatis;
 
 import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
 import org.apache.shardingsphere.example.core.api.service.ExampleService;
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java
similarity index 95%
rename from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java
rename to examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java
index b2611da..71c1917 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/namespace/mybatis/EncryptSpringNamespaceMybatisExample.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.spring.namespace.mybatis;
+package org.apache.shardingsphere.example.encrypt.spring.namespace.mybatis;
 
 import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
 import org.apache.shardingsphere.example.core.api.service.ExampleService;
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/single-feature-example/pom.xml
index ea259a0..4500cc3 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/pom.xml
@@ -36,5 +36,6 @@
         <module>shadow-example</module>
         <module>sharding-example</module>
         <module>transaction-example</module>
+        <module>readwrite-splitting-example</module>
     </modules>
-</project>
\ No newline at end of file
+</project>
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/readwrite/splitting/spring/boot/jpa/ReadwriteSplittingSpringBootJpa [...]
similarity index 78%
rename from examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
rename to examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/readwrite/splitting/spring/boot/jpa/ReadwriteSplittingSpringBootJpaExample.java
index 8b3689d..298e466 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/spring/boot/mybatis/EncryptSpringBootMybatisExample.java
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/readwrite/splitting/spring/boot/jpa/ReadwriteSplittingSpringBootJpaExample.java
@@ -15,27 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.example.encrypt.table.spring.boot.mybatis;
+package org.apache.shardingsphere.example.readwrite.splitting.spring.boot.jpa;
 
 import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
 import org.apache.shardingsphere.example.core.api.service.ExampleService;
-import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
 
 import java.sql.SQLException;
 
-@ComponentScan("org.apache.shardingsphere.example.core.mybatis")
-@MapperScan(basePackages = "org.apache.shardingsphere.example.core.mybatis.repository")
+@ComponentScan("org.apache.shardingsphere.example.core.jpa")
+@EntityScan(basePackages = "org.apache.shardingsphere.example.core.jpa.entity")
 @SpringBootApplication(exclude = JtaAutoConfiguration.class)
-public class EncryptSpringBootMybatisExample {
+public class ReadwriteSplittingSpringBootJpaExample {
     
     public static void main(final String[] args) throws SQLException {
-        try (ConfigurableApplicationContext applicationContext = SpringApplication.run(EncryptSpringBootMybatisExample.class, args)) {
-            ExampleExecuteTemplate.run(applicationContext.getBean("encrypt", ExampleService.class));
+        try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ReadwriteSplittingSpringBootJpaExample.class, args)) {
+            ExampleExecuteTemplate.run(applicationContext.getBean(ExampleService.class));
         }
     }
 }
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-readwrite-splitting.properties b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/application-readwrite-splitting.properties
similarity index 100%
rename from examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-readwrite-splitting.properties
rename to examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/application-readwrite-splitting.properties
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/application.properties
similarity index 81%
copy from examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties
copy to examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/application.properties
index 88c8929..360b114 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/application.properties
@@ -19,8 +19,4 @@ spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
 spring.jpa.properties.hibernate.show_sql=false
 
-spring.profiles.active=sharding-databases
-#spring.profiles.active=sharding-tables
-#spring.profiles.active=sharding-databases-tables
-#spring.profiles.active=readwrite-splitting
-#spring.profiles.active=sharding-auto-tables
+spring.profiles.active=readwrite-splitting
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/logback.xml b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/logback.xml
new file mode 100644
index 0000000..e49439e
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/readwrite-splitting-example/readwrite-splitting-spring-boot-jpa-example/src/main/resources/logback.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<configuration>
+    <property name="log.context.name" value="readwrite-splitting-spring-boot-jpa-example" />
+    <property name="log.charset" value="UTF-8" />
+    <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
+    <contextName>${log.context.name}</contextName>
+    
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder charset="${log.charset}">
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+    </appender>
+    <logger name="org.springframework" level="WARN" />
+    <logger name="com.zaxxer.hikari" level="WARN" />
+    <root>
+        <level value="INFO" />
+        <appender-ref ref="STDOUT" />
+    </root>
+</configuration>
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties b/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties
index 88c8929..7378abe 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application.properties
@@ -22,5 +22,4 @@ spring.jpa.properties.hibernate.show_sql=false
 spring.profiles.active=sharding-databases
 #spring.profiles.active=sharding-tables
 #spring.profiles.active=sharding-databases-tables
-#spring.profiles.active=readwrite-splitting
 #spring.profiles.active=sharding-auto-tables