From 9daecd60ded75a12e6a6799f69378f1d1e3c8547 Mon Sep 17 00:00:00 2001 From: totalo Date: Sat, 23 Sep 2023 10:45:00 -0500 Subject: [PATCH] Remove proxy example (#28350) --- examples/README.md | 22 +-- examples/README_ZH.md | 62 -------- examples/pom.xml | 1 - examples/shardingsphere-proxy-example/pom.xml | 67 -------- .../pom.xml | 37 ----- .../ProxySpringBootStarterExample.java | 59 ------- .../spring/boot/mybatis/entity/Address.java | 45 ------ .../spring/boot/mybatis/entity/Order.java | 70 --------- .../spring/boot/mybatis/entity/OrderItem.java | 70 --------- .../mybatis/repository/AddressRepository.java | 40 ----- .../repository/OrderItemRepository.java | 41 ----- .../mybatis/repository/OrderRepository.java | 41 ----- .../boot/mybatis/service/OrderService.java | 109 ------------- .../META-INF/mappers/AddressMapper.xml | 50 ------ .../META-INF/mappers/OrderItemMapper.xml | 55 ------- .../META-INF/mappers/OrderMapper.xml | 55 ------- .../resources/META-INF/mybatis-config.xml | 28 ---- .../src/main/resources/application.properties | 24 --- .../conf/config-readwrite-splitting.yaml | 63 -------- .../main/resources/conf/config-sharding.yaml | 97 ------------ .../src/main/resources/conf/server.yaml | 50 ------ .../src/main/resources/logback.xml | 35 ----- .../pom.xml | 41 ----- .../proxy/distsql/DistSQLExecutor.java | 28 ---- .../proxy/distsql/DistSQLFeatureExample.java | 59 ------- .../config/DataSourceConfiguration.java | 63 -------- .../distsql/factory/DataSourceFactory.java | 39 ----- .../feature/AbstractFeatureExecutor.java | 47 ------ .../proxy/distsql/feature/FeatureType.java | 57 ------- .../feature/encrypt/EncryptExecutor.java | 92 ----------- .../ReadWriteSplittingExecutor.java | 87 ---------- .../feature/resource/ResourceExecutor.java | 95 ----------- .../feature/shadow/ShadowExecutor.java | 117 -------------- .../feature/sharding/ShardingExecutor.java | 126 --------------- .../example/proxy/distsql/util/FileUtils.java | 29 ---- .../resources/client/datasource-config.yaml | 21 --- .../src/main/resources/logback.xml | 34 ---- .../main/resources/server/config-schema.yaml | 75 --------- .../src/main/resources/server/server.yaml | 62 -------- .../shardingsphere-proxy-hint-example/pom.xml | 41 ----- .../hint/ModuloHintShardingAlgorithm.java | 45 ------ .../example/proxy/hint/ProxyHintExample.java | 59 ------- .../hint/config/DataSourceConfiguration.java | 63 -------- .../example/proxy/hint/entity/Address.java | 45 ------ .../example/proxy/hint/entity/Order.java | 70 --------- .../example/proxy/hint/entity/OrderItem.java | 70 --------- .../hint/factory/YamlDataSourceFactory.java | 39 ----- .../hint/repository/AddressRepository.java | 103 ------------ .../hint/repository/OrderItemRepository.java | 114 -------------- .../hint/repository/OrderRepository.java | 111 ------------- .../proxy/hint/service/OrderService.java | 148 ------------------ ...rdingsphere.sharding.spi.ShardingAlgorithm | 18 --- .../META-INF/sql-hint-data-source.yaml | 21 --- .../conf/config-sql-hint-data-source.yaml | 56 ------- .../src/main/resources/conf/server.yaml | 48 ------ .../src/main/resources/logback.xml | 34 ---- 56 files changed, 4 insertions(+), 3274 deletions(-) delete mode 100644 examples/README_ZH.md delete mode 100644 examples/shardingsphere-proxy-example/pom.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/pom.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/ProxySpringBootStarterExample.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Address.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Order.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/OrderItem.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/AddressRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderItemRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/service/OrderService.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/AddressMapper.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderItemMapper.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/application.properties delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-readwrite-splitting.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-sharding.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/logback.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/pom.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLFeatureExample.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/config/DataSourceConfiguration.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/factory/DataSourceFactory.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/AbstractFeatureExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/FeatureType.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/encrypt/EncryptExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/readwritesplitting/ReadWriteSplittingExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/resource/ResourceExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/shadow/ShadowExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/sharding/ShardingExecutor.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/util/FileUtils.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/client/datasource-config.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/logback.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/config-schema.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/server.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/pom.xml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ProxyHintExample.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/config/DataSourceConfiguration.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Address.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Order.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/OrderItem.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/factory/YamlDataSourceFactory.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/AddressRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderItemRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderRepository.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/service/OrderService.java delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/sql-hint-data-source.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/config-sql-hint-data-source.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml delete mode 100644 examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/logback.xml diff --git a/examples/README.md b/examples/README.md index 6d1fa83bf5b63..6ed4bcd8691d3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -34,28 +34,14 @@ mvn clean install -Prelease ``` shardingsphere-example - ├── example-core - │   ├── config-utility - │   ├── example-api - │   ├── example-raw-jdbc - │   ├── example-spring-jpa - │   └── example-spring-mybatis ├── shardingsphere-jdbc-example-generator ├── shardingsphere-parser-example - ├── shardingsphere-proxy-example - │   ├── shardingsphere-proxy-boot-mybatis-example - │   ├── shardingsphere-proxy-distsql-example - │   └── shardingsphere-proxy-hint-example └── src/resources -   └── manual_schema.sql + └── manual_schema.sql ``` ## Available Examples -| Example | Description | -|------------------------------------------------------------------------------|--------------------------------------------------------------------------------| -| [ShardingSphere-JDBC Examples](shardingsphere-jdbc-example-generator/README.md) | Generate the examples by configuration and show how to use ShardingSphere-JDBC | -| [DistSQL](shardingsphere-proxy-example/shardingsphere-proxy-distsql-example) | show how to use DistSQL in ShardingSphere-Proxy | -| APM(Pending) | show how to use APM in ShardingSphere | -| proxy(Pending) | show how to use ShardingSphere-Proxy | -| [docker](./docker/docker-compose.md) | show how to use docker to setup the environment for ShardingSphere | +| Example | Description | +|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------| +| [ShardingSphere-JDBC Examples](shardingsphere-jdbc-example-generator/README.md) | Generate the examples by configuration and show how to use ShardingSphere-JDBC | diff --git a/examples/README_ZH.md b/examples/README_ZH.md deleted file mode 100644 index d77a88f01e949..0000000000000 --- a/examples/README_ZH.md +++ /dev/null @@ -1,62 +0,0 @@ -# Apache ShardingSphere 示例 - -1.x 版本示例,请参阅 `https://github.com/apache/shardingsphere/tree/${tag}/shardingsphere-jdbc-example` - -2.x,3.x 或 4.x 版本示例,请参见 `https://github.com/apache/shardingsphere-example/tree/${tag}` - -**注意事项** - -- *`shardingsphere-jdbc-example-generator`模块是一个全新的示例体验模块* - -- -*如果采用手动模式,请在首次运行示例之前执行[初始化脚本](https://github.com/apache/shardingsphere/blob/master/examples/src/resources/manual_schema.sql)。* - -- *请确保 MySQL 上的主从数据同步正确运行。否则,读写分离示例查询从库数据为空。* - -## 使用 `master` 分支 - -请在开始该示例之前,请确保已安装了来自 [Apache ShardingSphere](https://github.com/apache/shardingsphere) 的全部依赖项。 -如果您是 ShardingSphere 的新手,您可以准备如下依赖: - -1. 下载并安装 [Apache ShardingSphere](https://github.com/apache/shardingsphere): - -```bash -## 下载源码 -git clone https://github.com/apache/shardingsphere.git - -## 编译源码 -cd shardingsphere -mvn clean install -Prelease -``` - -## 模块设计 - -### 项目结构 - -``` -shardingsphere-example - ├── example-core - │   ├── config-utility - │   ├── example-api - │   ├── example-raw-jdbc - │   ├── example-spring-jpa - │   └── example-spring-mybatis - ├── shardingsphere-jdbc-example-generator - ├── shardingsphere-parser-example - ├── shardingsphere-proxy-example - │   ├── shardingsphere-proxy-boot-mybatis-example - │   ├── shardingsphere-proxy-distsql-example - │   └── shardingsphere-proxy-hint-example - └── src/resources -   └── manual_schema.sql -``` - -## 用例列表 - -| 例子 | 描述 | -|------------------------------------------------------------------------------|--------------------------------------| -| [ShardingSphere-JDBC示例](shardingsphere-jdbc-example-generator/README.md) | 通过配置生成ShardingSphere-JDBC的演示示例 | -| [DistSQL](shardingsphere-proxy-example/shardingsphere-proxy-distsql-example) | 演示在 ShardingSphere-Proxy 中使用 DistSQL | -| APM 监控(Pending) | 演示在 ShardingSphere 中使用 APM 监控 | -| proxy(Pending) | 演示使用 ShardingSphere-Proxy | -| [docker](./docker/docker-compose.md) | 演示通过 docker 创建 ShardingSphere 所依赖的环境 | diff --git a/examples/pom.xml b/examples/pom.xml index 0e7929d8cf509..add9a8d68b6fc 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -27,7 +27,6 @@ ${project.artifactId} - shardingsphere-proxy-example shardingsphere-parser-example shardingsphere-jdbc-example-generator diff --git a/examples/shardingsphere-proxy-example/pom.xml b/examples/shardingsphere-proxy-example/pom.xml deleted file mode 100644 index 8b38f084e4edd..0000000000000 --- a/examples/shardingsphere-proxy-example/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere.example - shardingsphere-examples - ${revision} - - shardingsphere-proxy-example - pom - ${project.artifactId} - - - shardingsphere-proxy-boot-mybatis-example - shardingsphere-proxy-hint-example - shardingsphere-proxy-distsql-example - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - org.codehaus.mojo - flatten-maven-plugin - [1.1.0,) - - flatten - - - - - - - - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/pom.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/pom.xml deleted file mode 100644 index 03c1ebbca8de0..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere.example - shardingsphere-proxy-example - ${revision} - - shardingsphere-proxy-boot-mybatis-example - ${project.artifactId} - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/ProxySpringBootStarterExample.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/ProxySpringBootStarterExample.java deleted file mode 100644 index cda9bb6728676..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/ProxySpringBootStarterExample.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis; - -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.service.OrderService; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.ComponentScan; - -import java.sql.SQLException; - -/* - * 1. Copy resources/conf/*.yaml to ShardingSphere-Proxy conf folder and overwrite original file. - * - * If you want to use sharding, please select config-sharding.yaml - * If you want to use readwrite-splitting, please select config-readwrite-splitting.yaml - * - * 2. Please make sure ShardingSphere-Proxy is running before you run this example. - */ -@ComponentScan("org.apache.shardingsphere.example") -@SpringBootApplication -public class ProxySpringBootStarterExample { - - public static void main(final String[] args) throws SQLException { - try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ProxySpringBootStarterExample.class, args)) { - process(applicationContext); - } - } - - private static void process(final ConfigurableApplicationContext applicationContext) throws SQLException { - OrderService orderService = applicationContext.getBean(OrderService.class); - orderService.initEnvironment(); - orderService.processSuccess(); - try { - orderService.processFailure(); - } catch (final Exception ex) { - System.out.println(ex.getMessage()); - orderService.printData(); - } finally { - orderService.cleanEnvironment(); - } - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Address.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Address.java deleted file mode 100644 index b6ef6253c55ad..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Address.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.entity; - -import java.io.Serializable; - -public class Address implements Serializable { - - private static final long serialVersionUID = 661434701950670670L; - - private Long addressId; - - private String addressName; - - public Long getAddressId() { - return addressId; - } - - public void setAddressId(final Long addressId) { - this.addressId = addressId; - } - - public String getAddressName() { - return addressName; - } - - public void setAddressName(final String addressName) { - this.addressName = addressName; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Order.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Order.java deleted file mode 100644 index 5b8175b56326d..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/Order.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.entity; - -import java.io.Serializable; - -public class Order implements Serializable { - - private static final long serialVersionUID = 661434701950670670L; - - private long orderId; - - 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 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, user_id: %s, address_id: %s, status: %s", orderId, userId, addressId, status); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/OrderItem.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/OrderItem.java deleted file mode 100644 index fed87a6b63669..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/entity/OrderItem.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.entity; - -import java.io.Serializable; - -public class OrderItem implements Serializable { - - private static final long serialVersionUID = 263434701950670170L; - - private long orderItemId; - - private long orderId; - - private int userId; - - 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 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, status: %s", orderItemId, orderId, userId, status); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/AddressRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/AddressRepository.java deleted file mode 100644 index fc15d659589e3..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/AddressRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.repository; - -import org.apache.ibatis.annotations.Mapper; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Address; - -import java.sql.SQLException; -import java.util.List; - -@Mapper -public interface AddressRepository { - - void createTableIfNotExists() throws SQLException; - - void dropTable() throws SQLException; - - void truncateTable() throws SQLException; - - void insert(Address address) throws SQLException; - - void delete(Long primaryKey) throws SQLException; - - List
selectAll() throws SQLException; -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderItemRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderItemRepository.java deleted file mode 100644 index 09709248a84c5..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderItemRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.repository; - -import org.apache.ibatis.annotations.Mapper; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Address; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.OrderItem; - -import java.sql.SQLException; -import java.util.List; - -@Mapper -public interface OrderItemRepository { - - void createTableIfNotExists() throws SQLException; - - void dropTable() throws SQLException; - - void truncateTable() throws SQLException; - - void insert(OrderItem orderItem) throws SQLException; - - void delete(Long primaryKey) throws SQLException; - - List
selectAll() throws SQLException; -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderRepository.java deleted file mode 100644 index 08528268ed2d4..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/repository/OrderRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.proxy.spring.boot.mybatis.repository; - -import org.apache.ibatis.annotations.Mapper; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Address; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Order; - -import java.sql.SQLException; -import java.util.List; - -@Mapper -public interface OrderRepository { - - void createTableIfNotExists() throws SQLException; - - void dropTable() throws SQLException; - - void truncateTable() throws SQLException; - - void insert(Order order) throws SQLException; - - void delete(Long primaryKey) throws SQLException; - - List
selectAll() throws SQLException; -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/service/OrderService.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/service/OrderService.java deleted file mode 100644 index 752270029a504..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/proxy/spring/boot/mybatis/service/OrderService.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.apache.shardingsphere.example.proxy.spring.boot.mybatis.service; - -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Address; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.Order; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.entity.OrderItem; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.repository.AddressRepository; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.repository.OrderItemRepository; -import org.apache.shardingsphere.example.proxy.spring.boot.mybatis.repository.OrderRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -@Service -public class OrderService { - - @Resource - private OrderRepository orderRepository; - - @Resource - private OrderItemRepository orderItemRepository; - - @Resource - private AddressRepository addressRepository; - - public void initEnvironment() throws SQLException { - orderRepository.createTableIfNotExists(); - orderItemRepository.createTableIfNotExists(); - orderRepository.truncateTable(); - orderItemRepository.truncateTable(); - initAddressTable(); - } - - private void initAddressTable() throws SQLException { - addressRepository.createTableIfNotExists(); - addressRepository.truncateTable(); - for (int i = 1; i <= 10; i++) { - Address entity = new Address(); - entity.setAddressId((long) i); - entity.setAddressName("address_" + i); - addressRepository.insert(entity); - } - } - - public void cleanEnvironment() throws SQLException { - orderRepository.dropTable(); - orderItemRepository.dropTable(); - addressRepository.dropTable(); - } - - @Transactional - public void processSuccess() throws SQLException { - System.out.println("-------------- Process Success Begin ---------------"); - List orderIds = insertData(); - printData(); - deleteData(orderIds); - printData(); - System.out.println("-------------- Process Success Finish --------------"); - } - - @Transactional - public void processFailure() throws SQLException { - System.out.println("-------------- Process Failure Begin ---------------"); - insertData(); - System.out.println("-------------- Process Failure Finish --------------"); - throw new RuntimeException("Exception occur for transaction test."); - } - - private List insertData() throws SQLException { - System.out.println("---------------------------- Insert Data ----------------------------"); - List result = new ArrayList<>(10); - for (int i = 1; i <= 10; i++) { - Order order = new Order(); - order.setUserId(i); - order.setAddressId(i); - order.setStatus("INSERT_TEST"); - orderRepository.insert(order); - OrderItem item = new OrderItem(); - item.setOrderId(order.getOrderId()); - item.setUserId(i); - item.setStatus("INSERT_TEST"); - orderItemRepository.insert(item); - result.add(order.getOrderId()); - } - return result; - } - - private void deleteData(final List orderIds) throws SQLException { - System.out.println("---------------------------- Delete Data ----------------------------"); - for (Long each : orderIds) { - orderRepository.delete(each); - orderItemRepository.delete(each); - } - } - - public void printData() throws SQLException { - System.out.println("---------------------------- Print Order Data -----------------------"); - for (Object each : orderRepository.selectAll()) { - System.out.println(each); - } - System.out.println("---------------------------- Print OrderItem Data -------------------"); - for (Object each : orderItemRepository.selectAll()) { - System.out.println(each); - } - } -} \ No newline at end of file diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/AddressMapper.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/AddressMapper.xml deleted file mode 100644 index e08a4c9f87023..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/AddressMapper.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - CREATE TABLE IF NOT EXISTS t_address (address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id)); - - - - TRUNCATE TABLE t_address; - - - - DROP TABLE IF EXISTS t_address; - - - - INSERT INTO t_address (address_id, address_name) VALUES (#{addressId,jdbcType=BIGINT}, #{addressName,jdbcType=VARCHAR}); - - - - DELETE FROM t_address WHERE address_id = #{addressId,jdbcType=BIGINT}; - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderItemMapper.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderItemMapper.xml deleted file mode 100644 index 23890722aca7e..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderItemMapper.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - CREATE TABLE IF NOT EXISTS t_order_item (order_item_id BIGINT AUTO_INCREMENT, order_id BIGINT, user_id INT NOT NULL, status VARCHAR(50) , PRIMARY KEY (order_item_id)); - - - - TRUNCATE TABLE t_order_item; - - - - DROP TABLE IF EXISTS t_order_item; - - - - INSERT INTO t_order_item (order_id, user_id, status) VALUES (#{orderId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR}); - - - - DELETE FROM t_order_item WHERE order_id = #{orderId,jdbcType=INTEGER}; - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml deleted file mode 100644 index df15e5c820f44..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT AUTO_INCREMENT, user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id)); - - - - TRUNCATE TABLE t_order; - - - - DROP TABLE IF EXISTS t_order; - - - - INSERT INTO t_order (user_id, address_id, status) VALUES (#{userId,jdbcType=INTEGER}, #{addressId,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}); - - - - DELETE FROM t_order WHERE order_id = #{orderId,jdbcType=INTEGER}; - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml deleted file mode 100644 index 77c43ce4d781a..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/application.properties b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/application.properties deleted file mode 100644 index 638dbe02df5fd..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/application.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# 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. -# - -mybatis.config-location=classpath:META-INF/mybatis-config.xml - -spring.datasource.type=com.zaxxer.hikari.HikariDataSource -spring.datasource.driver-class-name=com.mysql.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3307/sharding_db?useServerPrepStmts=true&cachePrepStmts=true -spring.datasource.username=root -spring.datasource.password=root diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-readwrite-splitting.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-readwrite-splitting.yaml deleted file mode 100644 index 37bb842e26263..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-readwrite-splitting.yaml +++ /dev/null @@ -1,63 +0,0 @@ -# -# 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. -# - -###################################################################################################### -# -# Here you can configure the rules for the proxy. -# This example is configuration of readwrite-splitting rule. -# -###################################################################################################### - -databaseName: readwrite-splitting_db - -dataSources: - write_ds: - url: jdbc:mysql://127.0.0.1:3306/demo_write_ds?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - read_ds_0: - url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_0?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - read_ds_1: - url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_1?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - -rules: -- !READWRITE_SPLITTING - dataSources: - readwrite_ds: - writeDataSourceName: write_ds - readDataSourceNames: - - read_ds_0 - - read_ds_1 diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-sharding.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-sharding.yaml deleted file mode 100644 index 6eb43063776c9..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-sharding.yaml +++ /dev/null @@ -1,97 +0,0 @@ -# -# 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. -# - -###################################################################################################### -# -# Here you can configure the rules for the proxy. -# This example is configuration of sharding rule. -# -###################################################################################################### - -databaseName: sharding_db - -dataSources: - ds_0: - url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - ds_1: - url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - -rules: -- !SHARDING - tables: - t_order: - actualDataNodes: ds_${0..1}.t_order_${0..1} - tableStrategy: - standard: - shardingColumn: order_id - shardingAlgorithmName: t_order_inline - keyGenerateStrategy: - column: order_id - keyGeneratorName: snowflake - t_order_item: - actualDataNodes: ds_${0..1}.t_order_item_${0..1} - tableStrategy: - standard: - shardingColumn: order_id - shardingAlgorithmName: t_order_item_inline - keyGenerateStrategy: - column: order_item_id - keyGeneratorName: snowflake - bindingTables: - - t_order,t_order_item - defaultDatabaseStrategy: - standard: - shardingColumn: user_id - shardingAlgorithmName: database_inline - defaultTableStrategy: - none: - - shardingAlgorithms: - database_inline: - type: INLINE - props: - algorithm-expression: ds_${user_id % 2} - t_order_inline: - type: INLINE - props: - algorithm-expression: t_order_${order_id % 2} - t_order_item_inline: - type: INLINE - props: - algorithm-expression: t_order_item_${order_id % 2} - - keyGenerators: - snowflake: - type: SNOWFLAKE - -- !BROADCAST - tables: - - t_address diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml deleted file mode 100644 index 852d0d178d085..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# -# 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. -# - -###################################################################################################### -# -# If you want to configure governance, authorization and proxy properties, please refer to this file. -# -###################################################################################################### - -#mode: -# type: Cluster -# repository: -# type: ZooKeeper -# props: -# namespace: governance_ds -# server-lists: localhost:2181 -# retryIntervalMilliseconds: 500 -# timeToLiveSeconds: 60 -# maxRetries: 3 -# operationTimeoutMilliseconds: 500 - -authority: - users: - - user: root - password: root - - user: sharding - password: sharding - privilege: - type: ALL_PERMITTED - -props: - max-connections-size-per-query: 1 - kernel-executor-size: 16 # Infinite by default. - proxy-frontend-flush-threshold: 128 # The default value is 128. - sql-show: false - check-table-metadata-enabled: false diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/logback.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/logback.xml deleted file mode 100644 index 3f30788d84a05..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/logback.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - ${log.context.name} - - - - ${log.pattern} - - - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/pom.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/pom.xml deleted file mode 100644 index f50b974abf9df..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere.example - shardingsphere-proxy-example - ${revision} - - shardingsphere-proxy-distsql-example - ${project.artifactId} - - - - org.apache.shardingsphere - shardingsphere-jdbc-core - - - org.apache.shardingsphere - shardingsphere-infra-common - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLExecutor.java deleted file mode 100644 index 18f5a60730910..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLExecutor.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.proxy.distsql; - -import java.sql.SQLException; -import java.sql.Statement; - -public interface DistSQLExecutor { - - void init(Statement statement); - - void execute() throws SQLException, InterruptedException; -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLFeatureExample.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLFeatureExample.java deleted file mode 100644 index ceaed8d86aecf..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/DistSQLFeatureExample.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.proxy.distsql; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.factory.DataSourceFactory; -import org.apache.shardingsphere.example.proxy.distsql.feature.FeatureType; -import org.apache.shardingsphere.example.proxy.distsql.util.FileUtils; - -import javax.sql.DataSource; -import java.io.IOException; -import java.sql.Connection; -import java.sql.Statement; - -@Slf4j -public final class DistSQLFeatureExample { - - public static void main(final String[] args) throws IOException { - DataSource dataSource = DataSourceFactory.createDataSource(FileUtils.getFile("/client/datasource-config.yaml")); - execute(dataSource); - } - - private static void execute(final DataSource dataSource) { - try { - Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement(); - DistSQLExecutor featureExecutor = selectFeature().getExecutor(); - featureExecutor.init(statement); - featureExecutor.execute(); - // CHECKSTYLE:OFF - } catch (final Exception ex) { - // CHECKSTYLE:ON - log.error(ex.getMessage()); - } - } - - private static FeatureType selectFeature() { -// return FeatureType.RESOURCE; -// return FeatureType.SHADOW; -// return FeatureType.ENCRYPT; -// return FeatureType.SHARDING; - return FeatureType.READWRITE_SPLITTING; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/config/DataSourceConfiguration.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/config/DataSourceConfiguration.java deleted file mode 100644 index 27af6faf04af7..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/config/DataSourceConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.proxy.distsql.config; - -import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; - -public final class DataSourceConfiguration implements YamlConfiguration { - - private String driverClassName; - - private String jdbcUrl; - - private String username; - - private String password; - - public String getDriverClassName() { - return driverClassName; - } - - public void setDriverClassName(final String driverClassName) { - this.driverClassName = driverClassName; - } - - public String getJdbcUrl() { - return jdbcUrl; - } - - public void setJdbcUrl(final String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - public String getUsername() { - return username; - } - - public void setUsername(final String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(final String password) { - this.password = password; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/factory/DataSourceFactory.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/factory/DataSourceFactory.java deleted file mode 100644 index 2ce8102bc907a..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/factory/DataSourceFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.proxy.distsql.factory; - -import com.zaxxer.hikari.HikariDataSource; -import org.apache.shardingsphere.example.proxy.distsql.config.DataSourceConfiguration; -import org.apache.shardingsphere.infra.util.yaml.YamlEngine; - -import javax.sql.DataSource; -import java.io.File; -import java.io.IOException; - -public final class DataSourceFactory { - - public static DataSource createDataSource(final File yamlFile) throws IOException { - DataSourceConfiguration datasourceConfig = YamlEngine.unmarshal(yamlFile, DataSourceConfiguration.class); - HikariDataSource result = new HikariDataSource(); - result.setDriverClassName(datasourceConfig.getDriverClassName()); - result.setJdbcUrl(datasourceConfig.getJdbcUrl()); - result.setUsername(datasourceConfig.getUsername()); - result.setPassword(datasourceConfig.getPassword()); - return result; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/AbstractFeatureExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/AbstractFeatureExecutor.java deleted file mode 100644 index 7601255a38399..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/AbstractFeatureExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.proxy.distsql.feature; - -import org.apache.shardingsphere.example.proxy.distsql.DistSQLExecutor; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.LinkedList; -import java.util.List; - -public abstract class AbstractFeatureExecutor implements DistSQLExecutor { - - protected Statement statement; - - protected void executeUseSchema() throws SQLException { - statement.execute("use `example_db`"); - } - - protected List> getResultData(ResultSet resultSet) throws SQLException { - List> result = new LinkedList<>(); - while (resultSet.next()) { - List row = new LinkedList<>(); - for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) { - row.add(resultSet.getString(i + 1)); - } - result.add(row); - } - return result; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/FeatureType.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/FeatureType.java deleted file mode 100644 index 10baef426a3df..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/FeatureType.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.proxy.distsql.feature; - -import org.apache.shardingsphere.example.proxy.distsql.DistSQLExecutor; -import org.apache.shardingsphere.example.proxy.distsql.feature.encrypt.EncryptExecutor; -import org.apache.shardingsphere.example.proxy.distsql.feature.readwritesplitting.ReadWriteSplittingExecutor; -import org.apache.shardingsphere.example.proxy.distsql.feature.resource.ResourceExecutor; -import org.apache.shardingsphere.example.proxy.distsql.feature.shadow.ShadowExecutor; -import org.apache.shardingsphere.example.proxy.distsql.feature.sharding.ShardingExecutor; - -public enum FeatureType { - - RESOURCE { - @Override - public DistSQLExecutor getExecutor() { - return new ResourceExecutor(); - } - }, SHADOW { - @Override - public DistSQLExecutor getExecutor() { - return new ShadowExecutor(); - } - }, ENCRYPT { - @Override - public DistSQLExecutor getExecutor() { - return new EncryptExecutor(); - } - }, SHARDING { - @Override - public DistSQLExecutor getExecutor() { - return new ShardingExecutor(); - } - }, READWRITE_SPLITTING { - @Override - public DistSQLExecutor getExecutor() { - return new ReadWriteSplittingExecutor(); - } - }; - - public abstract DistSQLExecutor getExecutor(); -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/encrypt/EncryptExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/encrypt/EncryptExecutor.java deleted file mode 100644 index 0f663da4bc0a8..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/encrypt/EncryptExecutor.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.proxy.distsql.feature.encrypt; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.feature.AbstractFeatureExecutor; -import org.apache.shardingsphere.infra.util.json.JsonUtils; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* - * Please ensure that the schema example_db has been added to the Proxy - */ -@Slf4j -public final class EncryptExecutor extends AbstractFeatureExecutor { - - private static final String ADD_RULE = "CREATE ENCRYPT RULE t_encrypt (\n" + - "COLUMNS(\n" + - "(NAME=user_id,CIPHER=user_cipher,TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),\n" + - "(NAME=order_id, CIPHER =order_cipher,TYPE(NAME='MD5'))\n" + - ")),\n" + - "t_encrypt_2 (\n" + - "COLUMNS(\n" + - "(NAME=user_id,CIPHER=user_cipher,TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),\n" + - "(NAME=order_id, CIPHER=order_cipher,TYPE(NAME='MD5'))\n" + - "))"; - - private static final String ALTER_RULE = "ALTER ENCRYPT RULE t_encrypt (\n" + - "COLUMNS(\n" + - "(NAME=user_id,CIPHER=user_cipher,TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),\n" + - "(NAME=order_id,CIPHER=order_cipher,TYPE(NAME='MD5'))\n" + - "))"; - - private static final String DROP_RULE = "DROP ENCRYPT RULE t_encrypt,t_encrypt_2"; - - private static final String SHOW_RULE = "SHOW ENCRYPT RULES"; - - @Override - public void init(Statement statement) { - this.statement = statement; - } - - @Override - public void execute() throws SQLException { - executeUseSchema(); - executeShowRule(); - executeAddRule(); - executeShowRule(); - executeAlterRule(); - executeShowRule(); - executeDropRule(); - executeShowRule(); - } - - private void executeShowRule() throws SQLException { - log.info("show rule..."); - ResultSet resultSet = statement.executeQuery(SHOW_RULE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeAddRule() throws SQLException { - log.info("add rule..."); - statement.execute(ADD_RULE); - } - - private void executeAlterRule() throws SQLException { - log.info("alter rule..."); - statement.execute(ALTER_RULE); - } - - private void executeDropRule() throws SQLException { - log.info("drop rule..."); - statement.execute(DROP_RULE); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/readwritesplitting/ReadWriteSplittingExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/readwritesplitting/ReadWriteSplittingExecutor.java deleted file mode 100644 index 44f39b807731e..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/readwritesplitting/ReadWriteSplittingExecutor.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.proxy.distsql.feature.readwritesplitting; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.feature.AbstractFeatureExecutor; -import org.apache.shardingsphere.infra.util.json.JsonUtils; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* - * Please make sure that resource ds_0, ds_1 and schema example_db have been added to Proxy - */ -@Slf4j -public final class ReadWriteSplittingExecutor extends AbstractFeatureExecutor { - - private static final String ADD_RULE = "CREATE READWRITE_SPLITTING RULE ms_group_0 (\n" + - "WRITE_STORAGE_UNIT=ds_0,\n" + - "READ_STORAGE_UNITS(ds_1),\n" + - "TYPE(NAME=random)\n" + - ")"; - - private static final String ALTER_RULE = "ALTER READWRITE_SPLITTING RULE ms_group_0 (\n" + - "WRITE_STORAGE_UNIT=ds_0,\n" + - "READ_STORAGE_UNITS(ds_1),\n" + - "TYPE(NAME=random,PROPERTIES(read_weight='2:0'))\n" + - ")"; - - private static final String DROP_RULE = "DROP READWRITE_SPLITTING RULE ms_group_0;\n"; - - private static final String SHOW_RULE = "SHOW READWRITE_SPLITTING RULES"; - - @Override - public void init(Statement statement) { - this.statement = statement; - } - - @Override - public void execute() throws SQLException { - executeUseSchema(); - executeShowRule(); - executeAddRule(); - executeShowRule(); - executeAlterRule(); - executeShowRule(); - executeDropRule(); - executeShowRule(); - } - - private void executeShowRule() throws SQLException { - log.info("show rule..."); - ResultSet resultSet = statement.executeQuery(SHOW_RULE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeAddRule() throws SQLException { - log.info("add rule..."); - statement.execute(ADD_RULE); - } - - private void executeAlterRule() throws SQLException { - log.info("alter rule..."); - statement.execute(ALTER_RULE); - } - - private void executeDropRule() throws SQLException { - log.info("drop rule..."); - statement.execute(DROP_RULE); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/resource/ResourceExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/resource/ResourceExecutor.java deleted file mode 100644 index 38cac8f26356f..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/resource/ResourceExecutor.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.proxy.distsql.feature.resource; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.feature.AbstractFeatureExecutor; -import org.apache.shardingsphere.infra.util.json.JsonUtils; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* - * Please ensure that the schema example_db has been added to the Proxy - */ -@Slf4j -public final class ResourceExecutor extends AbstractFeatureExecutor { - - private static final String ADD_RESOURCE = "ADD RESOURCE resource_0 (\n" + - " URL=\"jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false\",\n" + - " USER=root,\n" + - " PASSWORD=root,\n" + - " PROPERTIES(\"maximumPoolSize\"=10,\"idleTimeout\"=\"30000\")\n" + - "),resource_1 (\n" + - " URL=\"jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false\",\n" + - " USER=root,\n" + - " PASSWORD=root,\n" + - " PROPERTIES(\"maximumPoolSize\"=10,\"idleTimeout\"=\"30000\")\n" + - ")"; - - private static final String ALTER_RESOURCE = "ALTER RESOURCE resource_0 (\n" + - " HOST=127.0.0.1,\n" + - " PORT=3306,\n" + - " DB=demo_ds,\n" + - " USER=root,\n" + - " PASSWORD=root\n" + - ")"; - - private static final String DROP_RESOURCE = "DROP RESOURCE resource_0, resource_1"; - - private static final String SHOW_RESOURCE = "SHOW SCHEMA RESOURCES"; - - @Override - public void init(Statement statement) { - this.statement = statement; - } - - @Override - public void execute() throws SQLException { - executeUseSchema(); - executeShowResources(); - executeAddResource(); - executeShowResources(); - executeAlterResource(); - executeShowResources(); - executeDropResource(); - executeShowResources(); - } - - private void executeShowResources() throws SQLException { - log.info("show schema resources..."); - ResultSet resultSet = statement.executeQuery(SHOW_RESOURCE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeAddResource() throws SQLException { - log.info("add resource..."); - statement.execute(ADD_RESOURCE); - } - - private void executeAlterResource() throws SQLException { - log.info("alter resource..."); - statement.execute(ALTER_RESOURCE); - } - - private void executeDropResource() throws SQLException { - log.info("drop resource..."); - statement.execute(DROP_RESOURCE); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/shadow/ShadowExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/shadow/ShadowExecutor.java deleted file mode 100644 index f501717f1ab19..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/shadow/ShadowExecutor.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.proxy.distsql.feature.shadow; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.feature.AbstractFeatureExecutor; -import org.apache.shardingsphere.infra.util.json.JsonUtils; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* - * Please make sure that resource ds_0, ds_1 and schema example_db have been added to Proxy - */ -@Slf4j -public final class ShadowExecutor extends AbstractFeatureExecutor { - - private static final String ADD_RULE = "CREATE SHADOW RULE shadow_rule(\n" + - "SOURCE=ds_0,\n" + - "SHADOW=ds_1,\n" + - "t_order(TYPE(NAME=SQL_HINT),TYPE(NAME=REGEX_MATCH, PROPERTIES(\"operation\"=\"insert\",\"column\"=\"user_id\", \"regex\"='[1]'))), \n" + - "t_order_item(TYPE(NAME=SQL_HINT)));"; - - private static final String ALTER_RULE = "ALTER SHADOW RULE shadow_rule(\n" + - "SOURCE=ds_1,\n" + - "SHADOW=ds_0,\n" + - "t_order(TYPE(NAME=SQL_HINT),TYPE(NAME=REGEX_MATCH, PROPERTIES(\"operation\"=\"insert\",\"column\"=\"user_id\", \"regex\"='[1]'))), \n" + - "t_order_item(TYPE(NAME=SQL_HINT)))"; - - private static final String DROP_RULE = "DROP SHADOW RULE shadow_rule"; - - private static final String DROP_ALGORITHM = "DROP SHADOW ALGORITHM sql_hint_algorithm,shadow_rule_t_order_regex_match,shadow_rule_t_order_item_sql_hint"; - - private static final String SHOW_RULE = "SHOW SHADOW RULES"; - - private static final String SHOW_TABLE_RULE = "SHOW SHADOW TABLE RULES"; - - private static final String SHOW_ALGORITHM = "SHOW SHADOW ALGORITHMS"; - - @Override - public void init(Statement statement) { - this.statement = statement; - } - - @Override - public void execute() throws SQLException { - executeUseSchema(); - executeShowRule(); - executeAddRule(); - executeShowRule(); - executeShowTableRule(); - executeShowAlgorithm(); - executeAlterRule(); - executeShowRule(); - executeShowTableRule(); - executeShowAlgorithm(); - executeDropRule(); - executeDropAlgorithm(); - executeShowRule(); - executeShowTableRule(); - executeShowAlgorithm(); - } - - private void executeShowRule() throws SQLException { - log.info("show rule..."); - ResultSet resultSet = statement.executeQuery(SHOW_RULE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeShowTableRule() throws SQLException { - log.info("show table rule..."); - ResultSet resultSet = statement.executeQuery(SHOW_TABLE_RULE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeShowAlgorithm() throws SQLException { - log.info("show algorithm..."); - ResultSet resultSet = statement.executeQuery(SHOW_ALGORITHM); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeAddRule() throws SQLException { - log.info("add rule..."); - statement.execute(ADD_RULE); - } - - private void executeAlterRule() throws SQLException { - log.info("alter rule..."); - statement.execute(ALTER_RULE); - } - - private void executeDropRule() throws SQLException { - log.info("drop rule..."); - statement.execute(DROP_RULE); - } - - private void executeDropAlgorithm() throws SQLException { - log.info("drop algorithm..."); - statement.execute(DROP_ALGORITHM); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/sharding/ShardingExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/sharding/ShardingExecutor.java deleted file mode 100644 index 0fa6284fd4d3a..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/feature/sharding/ShardingExecutor.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.proxy.distsql.feature.sharding; - -import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.example.proxy.distsql.feature.AbstractFeatureExecutor; -import org.apache.shardingsphere.infra.util.json.JsonUtils; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* - * Please make sure that resource ds_0, ds_1 and schema example_db have been added to Proxy - */ -@Slf4j -public final class ShardingExecutor extends AbstractFeatureExecutor { - - private static final String ADD_RULE = "CREATE SHARDING TABLE RULE t_order (\n" + - "STORAGE_UNITS(ds_0,ds_1),\n" + - "SHARDING_COLUMN=order_id,\n" + - "TYPE(NAME=hash_mod,PROPERTIES(\"sharding-count\"=4)),\n" + - "KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME=snowflake))\n" + - ")"; - - private static final String ALTER_RULE = "ALTER SHARDING TABLE RULE t_order (\n" + - "STORAGE_UNITS(ds_0,ds_1),\n" + - "SHARDING_COLUMN=order_id,\n" + - "TYPE(NAME=hash_mod,PROPERTIES(\"sharding-count\"=5)),\n" + - "KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME=snowflake))\n" + - ")"; - - private static final String DROP_RULE = "DROP SHARDING TABLE RULE t_order"; - - private static final String DROP_ALGORITHM = "DROP SHARDING ALGORITHM t_order_hash_mod"; - - private static final String SHOW_RULE = "SHOW SHARDING TABLE RULES"; - - private static final String SHOW_ALGORITHM = "SHOW SHARDING ALGORITHMS"; - - private static final String DROP_KEY_GENERATOR = "DROP SHARDING KEY GENERATOR t_order_snowflake"; - - private static final String SHOW_KEY_GENERATORS = "SHOW SHARDING KEY GENERATORS"; - - @Override - public void init(Statement statement) { - this.statement = statement; - } - - @Override - public void execute() throws SQLException { - executeUseSchema(); - executeShowRule(); - executeAddRule(); - executeShowRule(); - executeShowAlgorithm(); - executeAlterRule(); - executeShowRule(); - executeShowAlgorithm(); - executeDropRule(); - executeDropAlgorithm(); - executeShowRule(); - executeShowAlgorithm(); - executeShowKeyGenerators(); - executeDropKeyGenerator(); - executeShowKeyGenerators(); - } - - private void executeShowRule() throws SQLException { - log.info("show rule..."); - ResultSet resultSet = statement.executeQuery(SHOW_RULE); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeShowAlgorithm() throws SQLException { - log.info("show algorithm..."); - ResultSet resultSet = statement.executeQuery(SHOW_ALGORITHM); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeAddRule() throws SQLException { - log.info("add rule..."); - statement.execute(ADD_RULE); - } - - private void executeAlterRule() throws SQLException { - log.info("alter rule..."); - statement.execute(ALTER_RULE); - } - - private void executeDropRule() throws SQLException { - log.info("drop rule..."); - statement.execute(DROP_RULE); - } - - private void executeDropAlgorithm() throws SQLException { - log.info("drop algorithm..."); - statement.execute(DROP_ALGORITHM); - } - - private void executeShowKeyGenerators() throws SQLException { - log.info("show sharding key generators..."); - ResultSet resultSet = statement.executeQuery(SHOW_KEY_GENERATORS); - log.info(JsonUtils.toJsonString(getResultData(resultSet))); - } - - private void executeDropKeyGenerator() throws SQLException { - log.info("drop sharding key generator..."); - statement.execute(DROP_KEY_GENERATOR); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/util/FileUtils.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/util/FileUtils.java deleted file mode 100644 index 81af379e30aab..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/util/FileUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.proxy.distsql.util; - -import org.apache.shardingsphere.example.proxy.distsql.DistSQLFeatureExample; - -import java.io.File; - -public final class FileUtils { - - public static File getFile(final String path) { - return new File(DistSQLFeatureExample.class.getResource(path).getFile()); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/client/datasource-config.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/client/datasource-config.yaml deleted file mode 100644 index 3f4602718cdcb..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/client/datasource-config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# - -driverClassName: com.mysql.jdbc.Driver -jdbcUrl: jdbc:mysql://127.0.0.1:3309/example_db?useSSL=false -username: root -password: root diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/logback.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/logback.xml deleted file mode 100644 index d4c800224ea52..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/logback.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - ${log.context.name} - - - - ${log.pattern} - - - - - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/config-schema.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/config-schema.yaml deleted file mode 100644 index 566f650cde3e7..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/config-schema.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# -# 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. -# - -###################################################################################################### -# -# Here you can configure the schema for the proxy. -# This example is configuration of schema. -# -###################################################################################################### -# -#databaseName: example_db -# -#dataSources: -# ds_0: -# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_0?serverTimezone=UTC&useSSL=false -# username: postgres -# password: postgres -# connectionTimeoutMilliseconds: 30000 -# idleTimeoutMilliseconds: 60000 -# maxLifetimeMilliseconds: 1800000 -# maxPoolSize: 50 -# minPoolSize: 1 -# ds_1: -# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_1?serverTimezone=UTC&useSSL=false -# username: postgres -# password: postgres -# connectionTimeoutMilliseconds: 30000 -# idleTimeoutMilliseconds: 60000 -# maxLifetimeMilliseconds: 1800000 -# maxPoolSize: 50 -# minPoolSize: 1 -# - - -###################################################################################################### -# -# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. -# -###################################################################################################### - -databaseName: example_db - -dataSources: - ds_0: - url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - ds_1: - url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/server.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/server.yaml deleted file mode 100644 index 4949ace90eb04..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/resources/server/server.yaml +++ /dev/null @@ -1,62 +0,0 @@ - -# -# 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. -# - -###################################################################################################### -# -# If you want to configure governance, authorization and proxy properties, please refer to this file. -# -###################################################################################################### - -mode: - type: Cluster - repository: - type: ZooKeeper - props: - namespace: governance_ds - server-lists: localhost:2181 - retryIntervalMilliseconds: 500 - timeToLiveSeconds: 60 - maxRetries: 3 - operationTimeoutMilliseconds: 500 - -authority: - users: - - user: root - password: root - - user: sharding - password: sharding - privilege: - type: ALL_PERMITTED - -transaction: - defaultType: XA - providerType: Atomikos - -sqlParser: - sqlCommentParseEnabled: true - -props: - max-connections-size-per-query: 1 - kernel-executor-size: 16 # Infinite by default. - proxy-frontend-flush-threshold: 128 # The default value is 128. - sql-show: false - check-table-metadata-enabled: false - # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy. - # The default value is -1, which means set the minimum value for different JDBC drivers. - proxy-backend-query-fetch-size: -1 - proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide. diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/pom.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/pom.xml deleted file mode 100644 index 8a98097c709bf..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere.example - shardingsphere-proxy-example - ${revision} - - shardingsphere-proxy-hint-example - ${project.artifactId} - - - - org.apache.shardingsphere - shardingsphere-jdbc-core - - - org.apache.shardingsphere - shardingsphere-infra-common - - - diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java deleted file mode 100644 index d2c99877c8027..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ModuloHintShardingAlgorithm.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.proxy.hint; - -import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingAlgorithm; -import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue; - -import java.util.Collection; -import java.util.LinkedList; - -public final class ModuloHintShardingAlgorithm implements HintShardingAlgorithm { - - @Override - public Collection doSharding(final Collection availableTargetNames, final HintShardingValue shardingValue) { - Collection result = new LinkedList<>(); - for (String each : availableTargetNames) { - for (String value : shardingValue.getValues()) { - if (each.endsWith(String.valueOf(Long.parseLong(value) % 2))) { - result.add(each); - } - } - } - return result; - } - - @Override - public String getType() { - return "HINT_TEST"; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ProxyHintExample.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ProxyHintExample.java deleted file mode 100644 index 38b97ab8c8242..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/ProxyHintExample.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.proxy.hint; - -import org.apache.shardingsphere.example.proxy.hint.factory.YamlDataSourceFactory; -import org.apache.shardingsphere.example.proxy.hint.service.OrderService; - -import javax.sql.DataSource; -import java.io.File; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; - -public final class ProxyHintExample { - - - public static void main(final String[] args) throws SQLException, IOException { - DataSource dataSource = getDataSource(); - OrderService orderService = new OrderService(dataSource); - orderService.initEnvironment(); - processWithHintValue(dataSource); - orderService.cleanEnvironment(); - } - - private static DataSource getDataSource() throws IOException { - return YamlDataSourceFactory.createDataSource(getFile("/META-INF/sql-hint-data-source.yaml")); - } - - private static File getFile(final String configFile) { - return new File(ProxyHintExample.class.getResource(configFile).getFile()); - } - - private static void processWithHintValue(final DataSource dataSource) throws SQLException { - try (Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement()) { - statement.execute("/* ShardingSphere hint: dataSourceName=ds_1 */select * from t_order"); - statement.execute("/* ShardingSphere hint: dataSourceName=ds_1 */SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id"); - statement.execute("/* ShardingSphere hint: dataSourceName=ds_1 */select * from t_order_item"); - statement.execute("/* ShardingSphere hint: dataSourceName=ds_1 */INSERT INTO t_order (user_id, address_id, status) VALUES (1, 1, 'init')"); - } - } - -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/config/DataSourceConfiguration.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/config/DataSourceConfiguration.java deleted file mode 100644 index d5f418705c1f2..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/config/DataSourceConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.proxy.hint.config; - -import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; - -public final class DataSourceConfiguration implements YamlConfiguration { - - private String driverClassName; - - private String jdbcUrl; - - private String username; - - private String password; - - public String getDriverClassName() { - return driverClassName; - } - - public void setDriverClassName(final String driverClassName) { - this.driverClassName = driverClassName; - } - - public String getJdbcUrl() { - return jdbcUrl; - } - - public void setJdbcUrl(final String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - public String getUsername() { - return username; - } - - public void setUsername(final String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(final String password) { - this.password = password; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Address.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Address.java deleted file mode 100644 index 43c659e452a21..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Address.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.proxy.hint.entity; - -import java.io.Serializable; - -public class Address implements Serializable { - - private static final long serialVersionUID = 661434701950670670L; - - private Long addressId; - - private String addressName; - - public Long getAddressId() { - return addressId; - } - - public void setAddressId(final Long addressId) { - this.addressId = addressId; - } - - public String getAddressName() { - return addressName; - } - - public void setAddressName(final String addressName) { - this.addressName = addressName; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Order.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Order.java deleted file mode 100644 index f43f40375a8af..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/Order.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.proxy.hint.entity; - -import java.io.Serializable; - -public class Order implements Serializable { - - private static final long serialVersionUID = 661434701950670670L; - - private long orderId; - - 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 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, user_id: %s, address_id: %s, status: %s", orderId, userId, addressId, status); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/OrderItem.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/OrderItem.java deleted file mode 100644 index 1703b867b7cf9..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/entity/OrderItem.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.proxy.hint.entity; - -import java.io.Serializable; - -public class OrderItem implements Serializable { - - private static final long serialVersionUID = 263434701950670170L; - - private long orderItemId; - - private long orderId; - - private int userId; - - 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 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, status: %s", orderItemId, orderId, userId, status); - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/factory/YamlDataSourceFactory.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/factory/YamlDataSourceFactory.java deleted file mode 100644 index 63c0fdad0e00e..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/factory/YamlDataSourceFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.proxy.hint.factory; - -import com.zaxxer.hikari.HikariDataSource; -import org.apache.shardingsphere.example.proxy.hint.config.DataSourceConfiguration; -import org.apache.shardingsphere.infra.util.yaml.YamlEngine; - -import javax.sql.DataSource; -import java.io.File; -import java.io.IOException; - -public final class YamlDataSourceFactory { - - public static DataSource createDataSource(final File yamlFile) throws IOException { - DataSourceConfiguration datasourceConfig = YamlEngine.unmarshal(yamlFile, DataSourceConfiguration.class); - HikariDataSource result = new HikariDataSource(); - result.setDriverClassName(datasourceConfig.getDriverClassName()); - result.setJdbcUrl(datasourceConfig.getJdbcUrl()); - result.setUsername(datasourceConfig.getUsername()); - result.setPassword(datasourceConfig.getPassword()); - return result; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/AddressRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/AddressRepository.java deleted file mode 100644 index f383dcf44f56f..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/AddressRepository.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.proxy.hint.repository; - -import org.apache.shardingsphere.example.proxy.hint.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
selectAll() throws SQLException { - String sql = "SELECT * FROM t_address"; - return getAddress(sql); - } - - private List
getAddress(final String sql) throws SQLException { - List
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-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderItemRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderItemRepository.java deleted file mode 100644 index 4df3f2d7698d7..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderItemRepository.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.proxy.hint.repository; - - -import org.apache.shardingsphere.example.proxy.hint.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 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, 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, 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.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 selectAll() throws SQLException { - // TODO Associated query with encrypt may query and decrypt failed. see https://github.com/apache/shardingsphere/issues/3352 -// String sql = "SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id"; - String sql = "SELECT * FROM t_order_item"; - return getOrderItems(sql); - } - - protected List getOrderItems(final String sql) throws SQLException { - List 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.setStatus(resultSet.getString(4)); - result.add(orderItem); - } - } - return result; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderRepository.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderRepository.java deleted file mode 100644 index 96e2300b6c69b..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/repository/OrderRepository.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.proxy.hint.repository; - - -import org.apache.shardingsphere.example.proxy.hint.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 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, 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, address_id, status) VALUES (?, ?, ?)"; - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { - preparedStatement.setInt(1, order.getUserId()); - preparedStatement.setLong(2, order.getAddressId()); - preparedStatement.setString(3, 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 selectAll() throws SQLException { - String sql = "SELECT * FROM t_order"; - return getOrders(sql); - } - - protected List getOrders(final String sql) throws SQLException { - List 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.setUserId(resultSet.getInt(2)); - order.setAddressId(resultSet.getLong(3)); - order.setStatus(resultSet.getString(4)); - result.add(order); - } - } - return result; - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/service/OrderService.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/service/OrderService.java deleted file mode 100644 index c0743209a297f..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/java/org/apache/shardingsphere/example/proxy/hint/service/OrderService.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.proxy.hint.service; - - -import org.apache.shardingsphere.example.proxy.hint.entity.Address; -import org.apache.shardingsphere.example.proxy.hint.entity.Order; -import org.apache.shardingsphere.example.proxy.hint.entity.OrderItem; -import org.apache.shardingsphere.example.proxy.hint.repository.AddressRepository; -import org.apache.shardingsphere.example.proxy.hint.repository.OrderItemRepository; -import org.apache.shardingsphere.example.proxy.hint.repository.OrderRepository; - -import javax.sql.DataSource; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public final class OrderService { - - private final OrderRepository orderRepository; - - private final OrderItemRepository orderItemRepository; - - private final AddressRepository addressRepository; - - public OrderService(final DataSource dataSource) { - orderRepository = new OrderRepository(dataSource); - orderItemRepository = new OrderItemRepository(dataSource); - addressRepository = new AddressRepository(dataSource); - } - - public OrderService(final OrderRepository orderRepository, final OrderItemRepository orderItemRepository, final AddressRepository addressRepository) { - this.orderRepository = orderRepository; - this.orderItemRepository = orderItemRepository; - this.addressRepository = addressRepository; - } - - public void initEnvironment() throws SQLException { - orderRepository.createTableIfNotExists(); - orderItemRepository.createTableIfNotExists(); - orderRepository.truncateTable(); - orderItemRepository.truncateTable(); - initAddressTable(); - } - - private void initAddressTable() throws SQLException { - addressRepository.createTableIfNotExists(); - addressRepository.truncateTable(); - initAddressData(); - } - - private void initAddressData() throws SQLException { - for (int i = 0; i < 10; i++) { - insertAddress(i); - } - } - - private void insertAddress(final int i) throws SQLException { - Address address = new Address(); - address.setAddressId((long) i); - address.setAddressName("address_" + i); - addressRepository.insert(address); - } - - public void cleanEnvironment() throws SQLException { - orderRepository.dropTable(); - orderItemRepository.dropTable(); - addressRepository.dropTable(); - } - - public void processSuccess() throws SQLException { - System.out.println("-------------- Process Success Begin ---------------"); - List orderIds = insertData(); - printData(); - deleteData(orderIds); - printData(); - System.out.println("-------------- Process Success Finish --------------"); - } - - public void processFailure() throws SQLException { - System.out.println("-------------- Process Failure Begin ---------------"); - insertData(); - System.out.println("-------------- Process Failure Finish --------------"); - throw new RuntimeException("Exception occur for transaction test."); - } - - private List insertData() throws SQLException { - System.out.println("---------------------------- Insert Data ----------------------------"); - List result = new ArrayList<>(10); - for (int i = 1; i <= 10; i++) { - Order order = insertOrder(i); - insertOrderItem(i, order); - result.add(order.getOrderId()); - } - return result; - } - - private Order insertOrder(final int i) throws SQLException { - Order order = new Order(); - order.setUserId(i); - order.setAddressId(i); - order.setStatus("INSERT_TEST"); - orderRepository.insert(order); - return order; - } - - private void insertOrderItem(final int i, final Order order) throws SQLException { - OrderItem item = new OrderItem(); - item.setOrderId(order.getOrderId()); - item.setUserId(i); - item.setStatus("INSERT_TEST"); - orderItemRepository.insert(item); - } - - private void deleteData(final List orderIds) throws SQLException { - System.out.println("---------------------------- Delete Data ----------------------------"); - for (Long each : orderIds) { - orderRepository.delete(each); - orderItemRepository.delete(each); - } - } - - public void printData() throws SQLException { - System.out.println("---------------------------- Print Order Data -----------------------"); - for (Object each : orderRepository.selectAll()) { - System.out.println(each); - } - System.out.println("---------------------------- Print OrderItem Data -------------------"); - for (Object each : orderItemRepository.selectAll()) { - System.out.println(each); - } - } -} diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm deleted file mode 100644 index dfea1083dfca0..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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.proxy.hint.ModuloHintShardingAlgorithm diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/sql-hint-data-source.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/sql-hint-data-source.yaml deleted file mode 100644 index 67b432be09dc5..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/META-INF/sql-hint-data-source.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# - -driverClassName: com.mysql.jdbc.Driver -jdbcUrl: jdbc:mysql://localhost:3307/sql_hint -username: root -password: root diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/config-sql-hint-data-source.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/config-sql-hint-data-source.yaml deleted file mode 100644 index 070a9c65e901b..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/config-sql-hint-data-source.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# -# 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. -# - -databaseName: sql_hint - -dataSources: - ds_0: - url: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - ds_1: - url: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 - username: root - password: - connectionTimeoutMilliseconds: 30000 - idleTimeoutMilliseconds: 60000 - maxLifetimeMilliseconds: 1800000 - maxPoolSize: 50 - minPoolSize: 1 - -rules: -- !SHARDING - tables: - t_order: - actualDataNodes: ds_${0..1}.t_order - t_order_item: - actualDataNodes: ds_${0..1}.t_order_item - bindingTables: - - t_order,t_order_item - defaultDatabaseStrategy: - none: - defaultTableStrategy: - none: - -- !BROADCAST - tables: - - t_address diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml deleted file mode 100644 index c6645621f43b8..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# -# 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. -# - -###################################################################################################### -# -# If you want to configure governance, authorization and proxy properties, please refer to this file. -# -###################################################################################################### - -#mode: -# type: Cluster -# repository: -# type: ZooKeeper -# props: -# namespace: governance_ds -# server-lists: localhost:2181 -# retryIntervalMilliseconds: 500 -# timeToLiveSeconds: 60 -# maxRetries: 3 -# operationTimeoutMilliseconds: 500 - -authority: - users: - - user: root - password: root - privilege: - type: ALL_PERMITTED - -props: - max-connections-size-per-query: 1 - kernel-executor-size: 16 # Infinite by default. - proxy-frontend-flush-threshold: 128 # The default value is 128. - sql-show: true - check-table-metadata-enabled: false diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/logback.xml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/logback.xml deleted file mode 100644 index d4c800224ea52..0000000000000 --- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/logback.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - ${log.context.name} - - - - ${log.pattern} - - - - - - -