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/01/12 04:05:07 UTC
[shardingsphere] branch master updated: Add spring-boot-starter-jdbc and spring-namespace-jdbc examples of mixed rules. (#14691)
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 65c4e25 Add spring-boot-starter-jdbc and spring-namespace-jdbc examples of mixed rules. (#14691)
65c4e25 is described below
commit 65c4e251e0eaf2c6e83971f3b2f8801c78c6d2c9
Author: Guocheng Tang <to...@qq.com>
AuthorDate: Wed Jan 12 12:04:08 2022 +0800
Add spring-boot-starter-jdbc and spring-namespace-jdbc examples of mixed rules. (#14691)
* Add spring-boot-starter-jdbc and spring-namespace-jdbc examples of mixed rules.
* add newline
* redo ci
---
.../template/resources/properties/application.ftl | 3 +-
.../template/resources/properties/db-discovery.ftl | 2 +-
.../template/resources/properties/encrypt.ftl | 2 +-
.../resources/properties/readwrite-splitting.ftl | 2 +-
.../template/resources/properties/shadow.ftl | 2 +-
.../template/resources/properties/sharding.ftl | 2 +-
.../template/resources/xml/application.ftl | 1 -
.../template/resources/xml/db-discovery.ftl | 1 -
.../resources/template/resources/xml/encrypt.ftl | 1 -
.../template/resources/xml/readwrite-splitting.ftl | 2 +-
.../pom.xml | 2 +
.../pom.xml | 29 +++-
...moryLocalMixedSpringBootStarterJdbcExample.java | 34 +++++
...alMixedSpringBootStarterJdbcExampleService.java | 152 +++++++++++++++++++++
.../TestQueryAssistedShardingEncryptAlgorithm.java | 55 ++++++++
.../spring/boot/starter/jdbc/entity/Address.java | 50 +++++++
.../spring/boot/starter/jdbc/entity/Order.java | 80 +++++++++++
.../spring/boot/starter/jdbc/entity/OrderItem.java | 80 +++++++++++
.../starter/jdbc/repository/AddressRepository.java | 103 ++++++++++++++
.../jdbc/repository/OrderItemRepository.java | 113 +++++++++++++++
.../starter/jdbc/repository/OrderRepository.java | 112 +++++++++++++++
...che.shardingsphere.encrypt.spi.EncryptAlgorithm | 18 +++
.../src/main/resources/application.properties | 89 ++++++++++++
.../src/main/resources/logback.xml} | 24 +++-
.../pom.xml | 19 ++-
...MemoryLocalMixedSpringNamespaceJdbcExample.java | 32 +++++
...ocalMixedSpringNamespaceJdbcExampleService.java | 152 +++++++++++++++++++++
.../TestQueryAssistedShardingEncryptAlgorithm.java | 55 ++++++++
.../spring/namespace/jdbc/entity/Address.java | 50 +++++++
.../mixed/spring/namespace/jdbc/entity/Order.java | 80 +++++++++++
.../spring/namespace/jdbc/entity/OrderItem.java | 80 +++++++++++
.../jdbc/repository/AddressRepository.java | 103 ++++++++++++++
.../jdbc/repository/OrderItemRepository.java | 113 +++++++++++++++
.../namespace/jdbc/repository/OrderRepository.java | 112 +++++++++++++++
...che.shardingsphere.encrypt.spi.EncryptAlgorithm | 18 +++
.../src/main/resources/application.xml} | 113 +++++++--------
.../src/main/resources/logback.xml} | 24 +++-
37 files changed, 1815 insertions(+), 95 deletions(-)
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/application.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/application.ftl
index 89b1640..b3d3317 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/application.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/application.ftl
@@ -48,7 +48,8 @@ spring.shardingsphere.datasource.ds-2.jdbc-url=jdbc:mysql://localhost:3306/demo_
spring.shardingsphere.datasource.ds-2.username=root
spring.shardingsphere.datasource.ds-2.password=root
spring.shardingsphere.datasource.ds-2.max-active=16
-
<#list feature?split(",") as item>
<#include "${item}.ftl">
</#list>
+
+spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/db-discovery.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/db-discovery.ftl
index 6a76f9d..4a229a0 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/db-discovery.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/db-discovery.ftl
@@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
spring.shardingsphere.rules.database-discovery.data-sources.rule.data-source-names=ds-0,ds-1,ds-2
spring.shardingsphere.rules.database-discovery.data-sources.rule.discovery-heartbeat-name=mgr-heartbeat
spring.shardingsphere.rules.database-discovery.data-sources.rule.discovery-type-name=mgr
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/encrypt.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/encrypt.ftl
index 9e60abc..087b288 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/encrypt.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/encrypt.ftl
@@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
spring.shardingsphere.rules.encrypt.encryptors.phone-encryptor.type=AES
spring.shardingsphere.rules.encrypt.encryptors.phone-encryptor.props.aes-key-value=123456
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/readwrite-splitting.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/readwrite-splitting.ftl
index c3a8c02..e273c1d 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/readwrite-splitting.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/readwrite-splitting.ftl
@@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=ds-0
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=ds-1,ds-2
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/shadow.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/shadow.ftl
index e26f012..ad72e14 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/shadow.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/shadow.ftl
@@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.source-data-source-name=ds-0
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.shadow-data-source-name=ds-1
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/sharding.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/sharding.ftl
index f312a85..957d079 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/sharding.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/properties/sharding.ftl
@@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl
index b22953a..bde2e11 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl
@@ -121,7 +121,6 @@
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</#if>
-
<#assign ruleRefs="">
<#list feature?split(",") as item>
<#assign ruleRefs += toCamel(item) + "Rule" />
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/db-discovery.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/db-discovery.ftl
index 0854d85..3103088 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/db-discovery.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/db-discovery.ftl
@@ -31,4 +31,3 @@
<prop key="group-name">aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</prop>
</props>
</database-discovery:discovery-type>
-
\ No newline at end of file
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/encrypt.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/encrypt.ftl
index 4817ce6..7b47a89 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/encrypt.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/encrypt.ftl
@@ -30,4 +30,3 @@
<encrypt:column logic-column="phone" cipher-column="phone" plain-column="phone_plain" encrypt-algorithm-ref="phone_encryptor" />
</encrypt:table>
</encrypt:rule>
-
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
index 69c389d..044628b 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
@@ -17,6 +17,6 @@
<readwrite-splitting:load-balance-algorithm id="randomStrategy" type="RANDOM" />
- <readwrite-splitting:rule id="readWriteSplittingRule">
+ <readwrite-splitting:rule id="readwriteSplittingRule">
<readwrite-splitting:data-source-rule id="demo_ds" write-data-source-name="ds_0" read-data-source-names="ds_1, ds_2" load-balance-algorithm-ref="randomStrategy" />
</readwrite-splitting:rule>
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
index 7155095..2f1449f 100644
--- a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
@@ -31,6 +31,8 @@
<modules>
<module>shardingsphere-jdbc-memory-local-mixed-jdbc-example</module>
+ <module>shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example</module>
+ <module>shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example</module>
</modules>
</project>
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml
similarity index 56%
copy from examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
copy to examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml
index 7155095..432f4c2 100644
--- a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/pom.xml
@@ -20,17 +20,34 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <artifactId>shardingsphere-jdbc-memory-local-example</artifactId>
+ <artifactId>shardingsphere-jdbc-memory-local-mixed-example</artifactId>
<groupId>org.apache.shardingsphere.example</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <packaging>pom</packaging>
- <artifactId>shardingsphere-jdbc-memory-local-mixed-example</artifactId>
+ <artifactId>shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-example</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-jdbc-memory-local-mixed-jdbc-example</module>
- </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere.example</groupId>
+ <artifactId>example-raw-jdbc</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <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>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
+ </dependency>
+ </dependencies>
</project>
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/MemoryLocalMixedSpringBootStarterJdbcExample.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/sha [...]
new file mode 100644
index 0000000..9fbe960
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/MemoryLocalMixedSpringBootStarterJdbcExample.java
@@ -0,0 +1,34 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+import java.sql.SQLException;
+
+@SpringBootApplication
+public class MemoryLocalMixedSpringBootStarterJdbcExample {
+
+ public static void main(final String[] args) throws SQLException {
+ try (ConfigurableApplicationContext applicationContext = SpringApplication.run(MemoryLocalMixedSpringBootStarterJdbcExample.class, args)) {
+ MemoryLocalMixedSpringBootStarterJdbcExampleService exampleService = applicationContext.getBean(MemoryLocalMixedSpringBootStarterJdbcExampleService.class);
+ exampleService.run();
+ }
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/MemoryLocalMixedSpringBootStarterJdbcExampleService.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-exam [...]
new file mode 100644
index 0000000..5c13fad
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/MemoryLocalMixedSpringBootStarterJdbcExampleService.java
@@ -0,0 +1,152 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc;
+
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.Address;
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.Order;
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.OrderItem;
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.repository.AddressRepository;
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.repository.OrderItemRepository;
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.repository.OrderRepository;
+
+import org.springframework.stereotype.Service;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public final class MemoryLocalMixedSpringBootStarterJdbcExampleService {
+
+ private final OrderRepository orderRepository;
+
+ private final OrderItemRepository orderItemRepository;
+
+ private final AddressRepository addressRepository;
+
+ public MemoryLocalMixedSpringBootStarterJdbcExampleService(final DataSource dataSource) {
+ orderRepository = new OrderRepository(dataSource);
+ orderItemRepository = new OrderItemRepository(dataSource);
+ addressRepository = new AddressRepository(dataSource);
+ }
+
+ /**
+ * Execute test.
+ *
+ * @throws SQLException
+ */
+ public void run() throws SQLException {
+ try {
+ this.initEnvironment();
+ this.processSuccess();
+ } finally {
+ this.cleanEnvironment();
+ }
+ }
+
+ /**
+ * Initialize the database test environment.
+ * @throws SQLException
+ */
+ private void initEnvironment() throws SQLException {
+ orderRepository.createTableIfNotExists();
+ orderItemRepository.createTableIfNotExists();
+ addressRepository.createTableIfNotExists();
+ orderRepository.truncateTable();
+ orderItemRepository.truncateTable();
+ addressRepository.truncateTable();
+ }
+
+ private void processSuccess() throws SQLException {
+ System.out.println("-------------- Process Success Begin ---------------");
+ List<Long> orderIds = insertData();
+ printData();
+ deleteData(orderIds);
+ printData();
+ System.out.println("-------------- Process Success Finish --------------");
+ }
+
+ private List<Long> insertData() throws SQLException {
+ System.out.println("---------------------------- Insert Data ----------------------------");
+ List<Long> result = new ArrayList<>(10);
+ for (int i = 1; i <= 10; i++) {
+ Order order = new Order();
+ order.setUserId(i);
+ order.setOrderType(i % 2);
+ order.setAddressId(i);
+ order.setStatus("INSERT_TEST");
+ orderRepository.insert(order);
+
+ OrderItem orderItem = new OrderItem();
+ orderItem.setOrderId(order.getOrderId());
+ orderItem.setUserId(i);
+ orderItem.setPhone("13800000001");
+ orderItem.setStatus("INSERT_TEST");
+ orderItemRepository.insert(orderItem);
+
+ Address address = new Address();
+ address.setAddressId((long) i);
+ address.setAddressName("address_test_" + i);
+ addressRepository.insert(address);
+
+ result.add(order.getOrderId());
+ }
+ return result;
+ }
+
+ private void deleteData(final List<Long> orderIds) throws SQLException {
+ System.out.println("---------------------------- Delete Data ----------------------------");
+ long count = 1;
+ for (Long each : orderIds) {
+ orderRepository.delete(each);
+ orderItemRepository.delete(each);
+ addressRepository.delete(count++);
+ }
+ }
+
+ private void printData() throws SQLException {
+ System.out.println("---------------------------- Print Order Data -----------------------");
+ for (Object each : this.selectAll()) {
+ System.out.println(each);
+ }
+ System.out.println("---------------------------- Print OrderItem Data -------------------");
+ for (Object each : orderItemRepository.selectAll()) {
+ System.out.println(each);
+ }
+ System.out.println("---------------------------- Print Address Data -------------------");
+ for (Object each : addressRepository.selectAll()) {
+ System.out.println(each);
+ }
+ }
+
+ private List<Order> selectAll() throws SQLException {
+ List<Order> result = orderRepository.selectAll();
+ return result;
+ }
+
+ /**
+ * Restore the environment.
+ * @throws SQLException
+ */
+ private void cleanEnvironment() throws SQLException {
+ orderRepository.dropTable();
+ orderItemRepository.dropTable();
+ addressRepository.dropTable();
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/TestQueryAssistedShardingEncryptAlgorithm.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardi [...]
new file mode 100644
index 0000000..02187ec
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/TestQueryAssistedShardingEncryptAlgorithm.java
@@ -0,0 +1,55 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.encrypt.spi.QueryAssistedEncryptAlgorithm;
+
+import java.util.Properties;
+
+public final class TestQueryAssistedShardingEncryptAlgorithm implements QueryAssistedEncryptAlgorithm<Object, String> {
+
+ @Getter
+ @Setter
+ private Properties props;
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public String encrypt(final Object plainValue) {
+ return "encryptValue";
+ }
+
+ @Override
+ public Object decrypt(final String cipherValue) {
+ return "decryptValue";
+ }
+
+ @Override
+ public String queryAssistedEncrypt(final Object plainValue) {
+ return "assistedEncryptValue";
+ }
+
+ @Override
+ public String getType() {
+ return "assistedTest";
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/Address.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local- [...]
new file mode 100644
index 0000000..06fd283
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/Address.java
@@ -0,0 +1,50 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.entity;
+
+import java.io.Serializable;
+
+public class Address implements Serializable {
+
+ private static final long serialVersionUID = 4743102234543827855L;
+
+ private Long addressId;
+
+ private String addressName;
+
+ public Long getAddressId() {
+ return addressId;
+ }
+
+ public void setAddressId(Long addressId) {
+ this.addressId = addressId;
+ }
+
+ public String getAddressName() {
+ return addressName;
+ }
+
+ public void setAddressName(String addressName) {
+ this.addressName = addressName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("address_id: %s, address_name: %s", addressId, addressName);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/Order.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-ex [...]
new file mode 100644
index 0000000..eac2093
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/Order.java
@@ -0,0 +1,80 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.entity;
+
+import java.io.Serializable;
+
+public class Order implements Serializable {
+
+ private static final long serialVersionUID = 8306802022239174861L;
+
+ private long orderId;
+
+ private int orderType;
+
+ private int userId;
+
+ private long addressId;
+
+ private String status;
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getOrderType() {
+ return orderType;
+ }
+
+ public void setOrderType(final int orderType) {
+ this.orderType = orderType;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public long getAddressId() {
+ return addressId;
+ }
+
+ public void setAddressId(final long addressId) {
+ this.addressId = addressId;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_id: %s, order_type: %s, user_id: %s, address_id: %s, status: %s", orderId, orderType, userId, addressId, status);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/OrderItem.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-loca [...]
new file mode 100644
index 0000000..984c829
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/entity/OrderItem.java
@@ -0,0 +1,80 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.entity;
+
+import java.io.Serializable;
+
+public class OrderItem implements Serializable {
+
+ private static final long serialVersionUID = 1332162822494069342L;
+
+ private long orderItemId;
+
+ private long orderId;
+
+ private int userId;
+
+ private String phone;
+
+ private String status;
+
+ public long getOrderItemId() {
+ return orderItemId;
+ }
+
+ public void setOrderItemId(final long orderItemId) {
+ this.orderItemId = orderItemId;
+ }
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_item_id:%s, order_id: %s, user_id: %s, phone: %s, status: %s", orderItemId, orderId, userId, phone, status);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/AddressRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc [...]
new file mode 100644
index 0000000..bfad4c4
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/AddressRepository.java
@@ -0,0 +1,103 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.Address;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class AddressRepository {
+
+ private final DataSource dataSource;
+
+ public AddressRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() throws SQLException {
+ String sql = "CREATE TABLE IF NOT EXISTS t_address "
+ + "(address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_address";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_address";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final Address entity) throws SQLException {
+ String sql = "INSERT INTO t_address (address_id, address_name) VALUES (?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, entity.getAddressId());
+ preparedStatement.setString(2, entity.getAddressName());
+ preparedStatement.executeUpdate();
+ }
+ return entity.getAddressId();
+ }
+
+ public void delete(final Long primaryKey) throws SQLException {
+ String sql = "DELETE FROM t_address WHERE address_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, primaryKey);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<Address> selectAll() throws SQLException {
+ String sql = "SELECT * FROM t_address";
+ return getAddress(sql);
+ }
+
+ private List<Address> getAddress(final String sql) throws SQLException {
+ List<Address> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Address address = new Address();
+ address.setAddressId(resultSet.getLong(1));
+ address.setAddressName(resultSet.getString(2));
+ result.add(address);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/OrderItemRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jd [...]
new file mode 100644
index 0000000..490ab7a
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/OrderItemRepository.java
@@ -0,0 +1,113 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.OrderItem;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class OrderItemRepository {
+
+ private final DataSource dataSource;
+
+ public OrderItemRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() 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))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final OrderItem orderItem) throws SQLException {
+ String sql = "INSERT INTO t_order_item (order_id, user_id, phone, status) VALUES (?, ?, ?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setLong(1, orderItem.getOrderId());
+ preparedStatement.setInt(2, orderItem.getUserId());
+ preparedStatement.setString(3, orderItem.getPhone());
+ preparedStatement.setString(4, orderItem.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ }
+ }
+ }
+ return orderItem.getOrderItemId();
+ }
+
+ public void delete(final Long orderItemId) throws SQLException {
+ String sql = "DELETE FROM t_order_item WHERE order_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderItemId);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<OrderItem> selectAll() throws SQLException {
+ String sql = "SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id";
+ return getOrderItems(sql);
+ }
+
+ private List<OrderItem> getOrderItems(final String sql) throws SQLException {
+ List<OrderItem> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ OrderItem orderItem = new OrderItem();
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ orderItem.setOrderId(resultSet.getLong(2));
+ orderItem.setUserId(resultSet.getInt(3));
+ orderItem.setPhone(resultSet.getString(4));
+ orderItem.setStatus(resultSet.getString(5));
+ result.add(orderItem);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/OrderRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-m [...]
new file mode 100644
index 0000000..c011db9
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/boot/starter/jdbc/repository/OrderRepository.java
@@ -0,0 +1,112 @@
+/*
+ * 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.example.mixed.spring.boot.starter.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.boot.starter.jdbc.entity.Order;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class OrderRepository {
+
+ private final DataSource dataSource;
+
+ public OrderRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() 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))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_order";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_order";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final Order order) throws SQLException {
+ String sql = "INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (?, ?, ?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setInt(1, order.getUserId());
+ preparedStatement.setInt(2, order.getOrderType());
+ preparedStatement.setLong(3, order.getAddressId());
+ preparedStatement.setString(4, order.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ order.setOrderId(resultSet.getLong(1));
+ }
+ }
+ }
+ return order.getOrderId();
+ }
+
+ public void delete(final Long orderId) throws SQLException {
+ String sql = "DELETE FROM t_order WHERE order_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderId);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<Order> selectAll() throws SQLException {
+ String sql = "SELECT * FROM t_order";
+ return getOrders(sql);
+ }
+
+ private List<Order> getOrders(final String sql) throws SQLException {
+ List<Order> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Order order = new Order();
+ order.setOrderId(resultSet.getLong(1));
+ order.setOrderType(resultSet.getInt(2));
+ order.setUserId(resultSet.getInt(3));
+ order.setAddressId(resultSet.getLong(4));
+ order.setStatus(resultSet.getString(5));
+ result.add(order);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example [...]
new file mode 100644
index 0000000..1967b41
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm
@@ -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.example.mixed.spring.boot.starter.jdbc.TestQueryAssistedShardingEncryptAlgorithm
\ No newline at end of file
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/application.properties b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/sh [...]
new file mode 100644
index 0000000..e7c15d6
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/application.properties
@@ -0,0 +1,89 @@
+#
+# 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.
+#
+
+spring.shardingsphere.datasource.names=ds-0,ds-1,ds-2
+
+# Notice: If you are using the db-discovery module, please replace the database address with the corresponding database cluster address
+
+spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-0.username=root
+spring.shardingsphere.datasource.ds-0.password=root
+spring.shardingsphere.datasource.ds-0.max-active=16
+
+spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-1.username=root
+spring.shardingsphere.datasource.ds-1.password=root
+spring.shardingsphere.datasource.ds-1.max-active=16
+
+spring.shardingsphere.datasource.ds-2.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-2.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-2.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_2?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-2.username=root
+spring.shardingsphere.datasource.ds-2.password=root
+spring.shardingsphere.datasource.ds-2.max-active=16
+
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
+
+spring.shardingsphere.rules.sharding.binding-tables=t_order,t_order_item
+spring.shardingsphere.rules.sharding.broadcast-tables=t_address
+
+spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=t-order-inline
+
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=t-order-item-inline
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
+spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id % 2}
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-inline.type=INLINE
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-inline.props.algorithm-expression=t_order_$->{order_id % 2}
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-inline.type=INLINE
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-inline.props.algorithm-expression=t_order_item_$->{order_id % 2}
+
+spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
+spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
+spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
+spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=ds-0
+spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=ds-1,ds-2
+spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.load-balancer-name=round_robin
+spring.shardingsphere.rules.encrypt.encryptors.phone-encryptor.type=AES
+spring.shardingsphere.rules.encrypt.encryptors.phone-encryptor.props.aes-key-value=123456
+
+spring.shardingsphere.rules.encrypt.encryptors.string_encryptor.type=assistedTest
+
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.status.cipher-column=status
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.status.assisted-query-column=assisted_query_status
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.status.encryptor-name=string_encryptor
+
+spring.shardingsphere.rules.encrypt.tables.t_order_item.columns.phone.cipher-column=phone
+spring.shardingsphere.rules.encrypt.tables.t_order_item.columns.phone.plain-column=phone_plain
+spring.shardingsphere.rules.encrypt.tables.t_order_item.columns.phone.encryptor-name=phone-encryptor
+
+spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/logback.xml
similarity index 56%
copy from examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
copy to examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/logback.xml
index 69c389d..154abba 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-boot-starter-jdbc-example/src/main/resources/logback.xml
@@ -1,4 +1,5 @@
-<#--
+<?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.
@@ -14,9 +15,20 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
+
+<configuration>
+ <property name="log.context.name" value="shardingsphere-example" />
+ <property name="log.charset" value="UTF-8" />
+ <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
+ <contextName>${log.context.name}</contextName>
- <readwrite-splitting:load-balance-algorithm id="randomStrategy" type="RANDOM" />
-
- <readwrite-splitting:rule id="readWriteSplittingRule">
- <readwrite-splitting:data-source-rule id="demo_ds" write-data-source-name="ds_0" read-data-source-names="ds_1, ds_2" load-balance-algorithm-ref="randomStrategy" />
- </readwrite-splitting:rule>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder charset="${log.charset}">
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ </appender>
+ <root>
+ <level value="INFO" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/pom.xml
similarity index 69%
copy from examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
copy to examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/pom.xml
index 7155095..a15b64c 100644
--- a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/pom.xml
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/pom.xml
@@ -20,17 +20,24 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <artifactId>shardingsphere-jdbc-memory-local-example</artifactId>
+ <artifactId>shardingsphere-jdbc-memory-local-mixed-example</artifactId>
<groupId>org.apache.shardingsphere.example</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <packaging>pom</packaging>
- <artifactId>shardingsphere-jdbc-memory-local-mixed-example</artifactId>
+ <artifactId>shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-jdbc-memory-local-mixed-jdbc-example</module>
- </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-core-spring-namespace</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>5.1.5.RELEASE</version>
+ </dependency>
+ </dependencies>
</project>
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/MemoryLocalMixedSpringNamespaceJdbcExample.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsph [...]
new file mode 100644
index 0000000..a4afdd1
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/MemoryLocalMixedSpringNamespaceJdbcExample.java
@@ -0,0 +1,32 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc;
+
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import java.sql.SQLException;
+
+public class MemoryLocalMixedSpringNamespaceJdbcExample {
+
+ public static void main(final String[] args) throws SQLException {
+ try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml")) {
+ MemoryLocalMixedSpringNamespaceJdbcExampleService exampleService = applicationContext.getBean(MemoryLocalMixedSpringNamespaceJdbcExampleService.class);
+ exampleService.run();
+ }
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/MemoryLocalMixedSpringNamespaceJdbcExampleService.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shar [...]
new file mode 100644
index 0000000..348607b
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/MemoryLocalMixedSpringNamespaceJdbcExampleService.java
@@ -0,0 +1,152 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc;
+
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.Address;
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.Order;
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.OrderItem;
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.repository.AddressRepository;
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.repository.OrderItemRepository;
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.repository.OrderRepository;
+
+import org.springframework.stereotype.Service;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public final class MemoryLocalMixedSpringNamespaceJdbcExampleService {
+
+ private final OrderRepository orderRepository;
+
+ private final OrderItemRepository orderItemRepository;
+
+ private final AddressRepository addressRepository;
+
+ public MemoryLocalMixedSpringNamespaceJdbcExampleService(final DataSource dataSource) {
+ orderRepository = new OrderRepository(dataSource);
+ orderItemRepository = new OrderItemRepository(dataSource);
+ addressRepository = new AddressRepository(dataSource);
+ }
+
+ /**
+ * Execute test.
+ *
+ * @throws SQLException
+ */
+ public void run() throws SQLException {
+ try {
+ this.initEnvironment();
+ this.processSuccess();
+ } finally {
+ this.cleanEnvironment();
+ }
+ }
+
+ /**
+ * Initialize the database test environment.
+ * @throws SQLException
+ */
+ private void initEnvironment() throws SQLException {
+ orderRepository.createTableIfNotExists();
+ orderItemRepository.createTableIfNotExists();
+ addressRepository.createTableIfNotExists();
+ orderRepository.truncateTable();
+ orderItemRepository.truncateTable();
+ addressRepository.truncateTable();
+ }
+
+ private void processSuccess() throws SQLException {
+ System.out.println("-------------- Process Success Begin ---------------");
+ List<Long> orderIds = insertData();
+ printData();
+ deleteData(orderIds);
+ printData();
+ System.out.println("-------------- Process Success Finish --------------");
+ }
+
+ private List<Long> insertData() throws SQLException {
+ System.out.println("---------------------------- Insert Data ----------------------------");
+ List<Long> result = new ArrayList<>(10);
+ for (int i = 1; i <= 10; i++) {
+ Order order = new Order();
+ order.setUserId(i);
+ order.setOrderType(i % 2);
+ order.setAddressId(i);
+ order.setStatus("INSERT_TEST");
+ orderRepository.insert(order);
+
+ OrderItem orderItem = new OrderItem();
+ orderItem.setOrderId(order.getOrderId());
+ orderItem.setUserId(i);
+ orderItem.setPhone("13800000001");
+ orderItem.setStatus("INSERT_TEST");
+ orderItemRepository.insert(orderItem);
+
+ Address address = new Address();
+ address.setAddressId((long) i);
+ address.setAddressName("address_test_" + i);
+ addressRepository.insert(address);
+
+ result.add(order.getOrderId());
+ }
+ return result;
+ }
+
+ private void deleteData(final List<Long> orderIds) throws SQLException {
+ System.out.println("---------------------------- Delete Data ----------------------------");
+ long count = 1;
+ for (Long each : orderIds) {
+ orderRepository.delete(each);
+ orderItemRepository.delete(each);
+ addressRepository.delete(count++);
+ }
+ }
+
+ private void printData() throws SQLException {
+ System.out.println("---------------------------- Print Order Data -----------------------");
+ for (Object each : this.selectAll()) {
+ System.out.println(each);
+ }
+ System.out.println("---------------------------- Print OrderItem Data -------------------");
+ for (Object each : orderItemRepository.selectAll()) {
+ System.out.println(each);
+ }
+ System.out.println("---------------------------- Print Address Data -------------------");
+ for (Object each : addressRepository.selectAll()) {
+ System.out.println(each);
+ }
+ }
+
+ private List<Order> selectAll() throws SQLException {
+ List<Order> result = orderRepository.selectAll();
+ return result;
+ }
+
+ /**
+ * Restore the environment.
+ * @throws SQLException
+ */
+ private void cleanEnvironment() throws SQLException {
+ orderRepository.dropTable();
+ orderItemRepository.dropTable();
+ addressRepository.dropTable();
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/TestQueryAssistedShardingEncryptAlgorithm.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphe [...]
new file mode 100644
index 0000000..352dab8
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/TestQueryAssistedShardingEncryptAlgorithm.java
@@ -0,0 +1,55 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.encrypt.spi.QueryAssistedEncryptAlgorithm;
+
+import java.util.Properties;
+
+public final class TestQueryAssistedShardingEncryptAlgorithm implements QueryAssistedEncryptAlgorithm<Object, String> {
+
+ @Getter
+ @Setter
+ private Properties props;
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public String encrypt(final Object plainValue) {
+ return "encryptValue";
+ }
+
+ @Override
+ public Object decrypt(final String cipherValue) {
+ return "decryptValue";
+ }
+
+ @Override
+ public String queryAssistedEncrypt(final Object plainValue) {
+ return "assistedEncryptValue";
+ }
+
+ @Override
+ public String getType() {
+ return "assistedTest";
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/Address.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-exampl [...]
new file mode 100644
index 0000000..e061ec9
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/Address.java
@@ -0,0 +1,50 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.entity;
+
+import java.io.Serializable;
+
+public class Address implements Serializable {
+
+ private static final long serialVersionUID = 4743102234543827855L;
+
+ private Long addressId;
+
+ private String addressName;
+
+ public Long getAddressId() {
+ return addressId;
+ }
+
+ public void setAddressId(Long addressId) {
+ this.addressId = addressId;
+ }
+
+ public String getAddressName() {
+ return addressName;
+ }
+
+ public void setAddressName(String addressName) {
+ this.addressName = addressName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("address_id: %s, address_name: %s", addressId, addressName);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/Order.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/ [...]
new file mode 100644
index 0000000..cab3528
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/Order.java
@@ -0,0 +1,80 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.entity;
+
+import java.io.Serializable;
+
+public class Order implements Serializable {
+
+ private static final long serialVersionUID = 8306802022239174861L;
+
+ private long orderId;
+
+ private int orderType;
+
+ private int userId;
+
+ private long addressId;
+
+ private String status;
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getOrderType() {
+ return orderType;
+ }
+
+ public void setOrderType(final int orderType) {
+ this.orderType = orderType;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public long getAddressId() {
+ return addressId;
+ }
+
+ public void setAddressId(final long addressId) {
+ this.addressId = addressId;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_id: %s, order_type: %s, user_id: %s, address_id: %s, status: %s", orderId, orderType, userId, addressId, status);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/OrderItem.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-exam [...]
new file mode 100644
index 0000000..482bc87
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/entity/OrderItem.java
@@ -0,0 +1,80 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.entity;
+
+import java.io.Serializable;
+
+public class OrderItem implements Serializable {
+
+ private static final long serialVersionUID = 1332162822494069342L;
+
+ private long orderItemId;
+
+ private long orderId;
+
+ private int userId;
+
+ private String phone;
+
+ private String status;
+
+ public long getOrderItemId() {
+ return orderItemId;
+ }
+
+ public void setOrderItemId(final long orderItemId) {
+ this.orderItemId = orderItemId;
+ }
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_item_id:%s, order_id: %s, user_id: %s, phone: %s, status: %s", orderItemId, orderId, userId, phone, status);
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/AddressRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memor [...]
new file mode 100644
index 0000000..49a7c60
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/AddressRepository.java
@@ -0,0 +1,103 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.Address;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class AddressRepository {
+
+ private final DataSource dataSource;
+
+ public AddressRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() throws SQLException {
+ String sql = "CREATE TABLE IF NOT EXISTS t_address "
+ + "(address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_address";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_address";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final Address entity) throws SQLException {
+ String sql = "INSERT INTO t_address (address_id, address_name) VALUES (?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, entity.getAddressId());
+ preparedStatement.setString(2, entity.getAddressName());
+ preparedStatement.executeUpdate();
+ }
+ return entity.getAddressId();
+ }
+
+ public void delete(final Long primaryKey) throws SQLException {
+ String sql = "DELETE FROM t_address WHERE address_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, primaryKey);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<Address> selectAll() throws SQLException {
+ String sql = "SELECT * FROM t_address";
+ return getAddress(sql);
+ }
+
+ private List<Address> getAddress(final String sql) throws SQLException {
+ List<Address> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Address address = new Address();
+ address.setAddressId(resultSet.getLong(1));
+ address.setAddressName(resultSet.getString(2));
+ result.add(address);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/OrderItemRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-mem [...]
new file mode 100644
index 0000000..1661ccb
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/OrderItemRepository.java
@@ -0,0 +1,113 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.OrderItem;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class OrderItemRepository {
+
+ private final DataSource dataSource;
+
+ public OrderItemRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() 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))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final OrderItem orderItem) throws SQLException {
+ String sql = "INSERT INTO t_order_item (order_id, user_id, phone, status) VALUES (?, ?, ?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setLong(1, orderItem.getOrderId());
+ preparedStatement.setInt(2, orderItem.getUserId());
+ preparedStatement.setString(3, orderItem.getPhone());
+ preparedStatement.setString(4, orderItem.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ }
+ }
+ }
+ return orderItem.getOrderItemId();
+ }
+
+ public void delete(final Long orderItemId) throws SQLException {
+ String sql = "DELETE FROM t_order_item WHERE order_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderItemId);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<OrderItem> selectAll() throws SQLException {
+ String sql = "SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id";
+ return getOrderItems(sql);
+ }
+
+ private List<OrderItem> getOrderItems(final String sql) throws SQLException {
+ List<OrderItem> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ OrderItem orderItem = new OrderItem();
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ orderItem.setOrderId(resultSet.getLong(2));
+ orderItem.setUserId(resultSet.getInt(3));
+ orderItem.setPhone(resultSet.getString(4));
+ orderItem.setStatus(resultSet.getString(5));
+ result.add(orderItem);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/OrderRepository.java b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory- [...]
new file mode 100644
index 0000000..02fdb96
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/java/org/apache/shardingsphere/example/mixed/spring/namespace/jdbc/repository/OrderRepository.java
@@ -0,0 +1,112 @@
+/*
+ * 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.example.mixed.spring.namespace.jdbc.repository;
+
+import org.apache.shardingsphere.example.mixed.spring.namespace.jdbc.entity.Order;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class OrderRepository {
+
+ private final DataSource dataSource;
+
+ public OrderRepository(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createTableIfNotExists() 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))";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void dropTable() throws SQLException {
+ String sql = "DROP TABLE t_order";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public void truncateTable() throws SQLException {
+ String sql = "TRUNCATE TABLE t_order";
+ try (Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ }
+ }
+
+ public Long insert(final Order order) throws SQLException {
+ String sql = "INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (?, ?, ?, ?)";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setInt(1, order.getUserId());
+ preparedStatement.setInt(2, order.getOrderType());
+ preparedStatement.setLong(3, order.getAddressId());
+ preparedStatement.setString(4, order.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ order.setOrderId(resultSet.getLong(1));
+ }
+ }
+ }
+ return order.getOrderId();
+ }
+
+ public void delete(final Long orderId) throws SQLException {
+ String sql = "DELETE FROM t_order WHERE order_id=?";
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderId);
+ preparedStatement.executeUpdate();
+ }
+ }
+
+ public List<Order> selectAll() throws SQLException {
+ String sql = "SELECT * FROM t_order";
+ return getOrders(sql);
+ }
+
+ private List<Order> getOrders(final String sql) throws SQLException {
+ List<Order> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Order order = new Order();
+ order.setOrderId(resultSet.getLong(1));
+ order.setOrderType(resultSet.getInt(2));
+ order.setUserId(resultSet.getInt(3));
+ order.setAddressId(resultSet.getLong(4));
+ order.setStatus(resultSet.getString(5));
+ result.add(order);
+ }
+ }
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/sh [...]
new file mode 100644
index 0000000..85a3d98
--- /dev/null
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm
@@ -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.example.mixed.spring.namespace.jdbc.TestQueryAssistedShardingEncryptAlgorithm
\ No newline at end of file
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/application.xml
similarity index 65%
copy from examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl
copy to examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/application.xml
index b22953a..875bef4 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/application.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/application.xml
@@ -49,33 +49,8 @@
http://shardingsphere.apache.org/schema/shardingsphere/sql-parser
http://shardingsphere.apache.org/schema/shardingsphere/sql-parser/sql-parser.xsd
">
-<#assign package="" />
-<#if feature?split(",")?size gt 1>
- <#assign package="mixed" />
-<#else>
- <#assign package = feature?replace('-', '.') />
-</#if>
<context:annotation-config />
- <context:component-scan base-package="org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}"/>
-<#if framework=="spring-namespace-jpa">
-
- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="MYSQL" />
- </property>
- <property name="packagesToScan" value="org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.entity" />
- <property name="jpaProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
- <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
- <prop key="hibernate.show_sql">false</prop>
- </props>
- </property>
- </bean>
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory" />
- <tx:annotation-driven />
-</#if>
+ <context:component-scan base-package="org.apache.shardingsphere.example.mixed.spring.namespace.jdbc"/>
<!--
Notice: If you are using the db-discovery module, please replace the database address with the corresponding database cluster address
@@ -101,47 +76,63 @@
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
-<#list feature?split(",") as item>
- <#include "${item}.ftl">
-</#list>
-<#if framework=="spring-namespace-mybatis">
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <tx:annotation-driven />
+ <sharding:sharding-algorithm id="databaseAlgorithm" type="INLINE">
+ <props>
+ <prop key="algorithm-expression">ds_${user_id % 2}</prop>
+ </props>
+ </sharding:sharding-algorithm>
+ <sharding:standard-strategy id="databaseStrategy" sharding-column="user_id" algorithm-ref="databaseAlgorithm" />
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource"/>
- <property name="mapperLocations" value="classpath*:mappers/*.xml"/>
- </bean>
+ <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+ <props>
+ <prop key="worker-id">123</prop>
+ </props>
+ </sharding:key-generate-algorithm>
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.repository"/>
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
- </bean>
-</#if>
+ <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id" algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="accountKeyGenerator" column="account_id" algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="itemKeyGenerator" column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+
+ <sharding:rule id="shardingRule">
+ <sharding:table-rules>
+ <sharding:table-rule logic-table="t_order" database-strategy-ref="databaseStrategy" key-generate-strategy-ref="orderKeyGenerator" />
+ <sharding:table-rule logic-table="t_order_item" database-strategy-ref="databaseStrategy" key-generate-strategy-ref="itemKeyGenerator" />
+ <sharding:table-rule logic-table="t_account" database-strategy-ref="databaseStrategy" key-generate-strategy-ref="accountKeyGenerator" />
+ </sharding:table-rules>
+ <sharding:binding-table-rules>
+ <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+ </sharding:binding-table-rules>
+ <sharding:broadcast-table-rules>
+ <sharding:broadcast-table-rule table="t_address"/>
+ </sharding:broadcast-table-rules>
+ </sharding:rule>
+
+ <readwrite-splitting:load-balance-algorithm id="randomStrategy" type="RANDOM" />
+
+ <readwrite-splitting:rule id="readwriteSplittingRule">
+ <readwrite-splitting:data-source-rule id="demo_ds" write-data-source-name="ds_0" read-data-source-names="ds_1, ds_2" load-balance-algorithm-ref="randomStrategy" />
+ </readwrite-splitting:rule>
+
+ <encrypt:encrypt-algorithm id="phone_encryptor" type="AES">
+ <props>
+ <prop key="aes-key-value">123456</prop>
+ </props>
+ </encrypt:encrypt-algorithm>
+ <encrypt:encrypt-algorithm id="string_encryptor" type="assistedTest" />
+
+ <encrypt:rule id="encryptRule">
+ <encrypt:table name="t_order">
+ <encrypt:column logic-column="status" cipher-column="status" assisted-query-column="assisted_query_status" encrypt-algorithm-ref="string_encryptor" />
+ </encrypt:table>
+ <encrypt:table name="t_order_item">
+ <encrypt:column logic-column="phone" cipher-column="phone" plain-column="phone_plain" encrypt-algorithm-ref="phone_encryptor" />
+ </encrypt:table>
+ </encrypt:rule>
-<#assign ruleRefs="">
-<#list feature?split(",") as item>
- <#assign ruleRefs += toCamel(item) + "Rule" />
- <#if item_has_next>
- <#assign ruleRefs += ", " />
- </#if>
-</#list>
- <shardingsphere:data-source id="dataSource" data-source-names="ds_0, ds_1, ds_2" rule-refs="${ruleRefs}">
+ <shardingsphere:data-source id="dataSource" data-source-names="ds_0, ds_1, ds_2" rule-refs="shardingRule, readwriteSplittingRule, encryptRule">
<props>
<prop key="sql-show">true</prop>
</props>
</shardingsphere:data-source>
</beans>
-<#function toCamel(s)>
- <#return s
- ?replace('(^-+)|(-+$)', '', 'r')
- ?replace('\\-+(\\w)?', ' $1', 'r')
- ?replace('([A-Z])', ' $1', 'r')
- ?capitalize
- ?replace(' ' , '')
- ?uncap_first
- >
-</#function>
diff --git a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/logback.xml
similarity index 56%
copy from examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
copy to examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/logback.xml
index 69c389d..154abba 100644
--- a/examples/shardingsphere-sample/shardingsphere-example-engine/src/main/resources/template/resources/xml/readwrite-splitting.ftl
+++ b/examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-memory-example/shardingsphere-jdbc-memory-local-example/shardingsphere-jdbc-memory-local-mixed-example/shardingsphere-jdbc-memory-local-mixed-spring-namespace-jdbc-example/src/main/resources/logback.xml
@@ -1,4 +1,5 @@
-<#--
+<?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.
@@ -14,9 +15,20 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
+
+<configuration>
+ <property name="log.context.name" value="shardingsphere-example" />
+ <property name="log.charset" value="UTF-8" />
+ <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
+ <contextName>${log.context.name}</contextName>
- <readwrite-splitting:load-balance-algorithm id="randomStrategy" type="RANDOM" />
-
- <readwrite-splitting:rule id="readWriteSplittingRule">
- <readwrite-splitting:data-source-rule id="demo_ds" write-data-source-name="ds_0" read-data-source-names="ds_1, ds_2" load-balance-algorithm-ref="randomStrategy" />
- </readwrite-splitting:rule>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder charset="${log.charset}">
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ </appender>
+ <root>
+ <level value="INFO" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>