You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/03 10:52:55 UTC
[shardingsphere] branch master updated: Complete insert statement
(#12186)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 83b5c8f Complete insert statement (#12186)
83b5c8f is described below
commit 83b5c8faee516282174622286de6a4471d345634
Author: gin <ja...@163.com>
AuthorDate: Fri Sep 3 18:52:26 2021 +0800
Complete insert statement (#12186)
* Optimize the xml configuration tag name.
* Add shadow statement validator.
* Add future shadow example.
* Add shadow statement validator verification.
* Remove useless import.
* Fix code format.
* Add serialVersionUID.
---
.../pom.xml | 23 ++++--
.../ShadowSpringNamespaceMybatisExample.java | 36 ++++++++
.../spring/namespace/mybatis/domain/OrderInfo.java | 34 ++++++++
.../namespace/mybatis/repository/ShadowMapper.java | 27 ++++++
.../namespace/mybatis/service/ShadowService.java | 23 ++++++
.../mybatis/service/impl/ShadowServiceImpl.java | 58 +++++++++++++
.../META-INF/application-shadow-databases.xml | 95 ++++++++++++++++++++++
.../resources/META-INF/mappers/ShadowMapper.xml} | 33 +++-----
.../src/main/resources/logback.xml} | 33 ++++----
.../{ => future-shadow-example}/pom.xml | 10 +--
.../other-feature-example/pom.xml | 1 +
.../shadow/route/ShadowSQLRouter.java | 9 ++
.../algorithm/ColumnShadowAlgorithmDeterminer.java | 36 +++++---
.../dml/ShadowInsertStatementRoutingEngine.java | 7 +-
.../engine/validator/ShadowStatementValidator.java | 37 +++++++++
.../validator/ShadowStatementValidatorFactory.java | 54 ++++++++++++
.../dml/ShadowInsertStatementValidator.java | 36 ++++++++
.../ColumnShadowAlgorithmDeterminerTest.java | 45 ++++++----
.../namespace/tag/ShadowRuleBeanDefinitionTag.java | 4 +-
.../main/resources/META-INF/namespace/shadow.xsd | 8 +-
.../shadow-algorithm-application-context.xml | 14 ++--
21 files changed, 529 insertions(+), 94 deletions(-)
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml
similarity index 69%
copy from examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
copy to examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml
index f48464d..8b2104c 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml
@@ -21,17 +21,22 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
+ <artifactId>future-shadow-example</artifactId>
<groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>shardingsphere-jdbc-example</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>other-feature-example</artifactId>
- <packaging>pom</packaging>
+ <artifactId>future-shadow-spring-namespace-mybatis-example</artifactId>
<name>${project.artifactId}</name>
-
- <modules>
- <module>encrypt-example</module>
- <module>hint-example</module>
- <module>shadow-example</module>
- </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere.example</groupId>
+ <artifactId>example-spring-mybatis</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-core-spring-namespace</artifactId>
+ </dependency>
+ </dependencies>
</project>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespace [...]
new file mode 100644
index 0000000..ff20ff3
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
@@ -0,0 +1,36 @@
+/*
+ * 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.shadow.spring.namespace.mybatis;
+
+import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.ShadowService;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.SQLException;
+
+public final class ShadowSpringNamespaceMybatisExample {
+
+ private static final String CONFIG_FILE = "META-INF/application-shadow-databases.xml";
+
+ public static void main(final String[] args) throws SQLException {
+ try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_FILE)) {
+ ShadowService shadowService = applicationContext.getBean("shadowService", ShadowService.class);
+ shadowService.executeInsertCase();
+ }
+ }
+}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/domain/OrderInfo.java b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/domain/OrderInfo.java
new file mode 100644
index 0000000..bb122ca
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/domain/OrderInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public final class OrderInfo implements Serializable {
+
+ private static final long serialVersionUID = -1590520493701492607L;
+
+ private Integer id;
+
+ private Integer userId;
+
+ private String content;
+}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/repository/ShadowMapper.java b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/repository/ShadowMapper.java
new file mode 100644
index 0000000..d4a8087
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/repository/ShadowMapper.java
@@ -0,0 +1,27 @@
+/*
+ * 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.shadow.spring.namespace.mybatis.repository;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface ShadowMapper {
+
+ void execute(@Param(value = "sql") String sql);
+}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/ShadowService.java b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/ShadowService.java
new file mode 100644
index 0000000..7e1eadc
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/ShadowService.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service;
+
+public interface ShadowService {
+
+ void executeInsertCase();
+}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/impl/ShadowServiceImpl.java b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/impl/ShadowService [...]
new file mode 100644
index 0000000..8f18170
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/service/impl/ShadowServiceImpl.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.impl;
+
+import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.repository.ShadowMapper;
+import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.ShadowService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.LinkedList;
+
+@Service(value = "shadowService")
+public final class ShadowServiceImpl implements ShadowService {
+
+ @Resource
+ private ShadowMapper shadowMapper;
+
+ private void execute(String sql) {
+ shadowMapper.execute(sql);
+ }
+
+ @Override
+ public void executeInsertCase() {
+ Collection<String> insertSQLs = initInsertCase();
+ for (String each : insertSQLs) {
+ execute(each);
+ }
+ }
+
+ private Collection<String> initInsertCase() {
+ Collection<String> result = new LinkedList<>();
+ String insert_case_1 = "INSERT INTO t_order (user_id, content) VALUES (1, 'insert_case_1')";
+ result.add(insert_case_1);
+ String insert_case_2 = "INSERT INTO t_order (user_id, content) VALUES (1, 'insert_case_2'), (1, 'insert_case_2')";
+ result.add(insert_case_2);
+ String insert_case_3 = "INSERT INTO t_order (user_id, content) VALUES (1, 'insert_case_3'), (2, 'insert_case_3')";
+ result.add(insert_case_3);
+ String insert_case_4 = "INSERT INTO t_order (user_id, content) SELECT user_id, content from t_order_data where user_id = 1";
+ result.add(insert_case_4);
+ return result;
+ }
+}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml
new file mode 100644
index 0000000..ed19f73
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:shadow="http://shardingsphere.apache.org/schema/shardingsphere/shadow"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd
+ http://shardingsphere.apache.org/schema/shardingsphere/datasource
+ http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+ http://shardingsphere.apache.org/schema/shardingsphere/shadow
+ http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow.xsd
+ ">
+ <context:component-scan base-package="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis" />
+ <bean id="ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ </bean>
+ <bean id="ds_shadow" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ds_shadow?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <shadow:shadow-algorithm id="user-id-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">insert</prop>
+ <prop key="column">user_id</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+ <shadow:shadow-algorithm id="simple-note-algorithm" type="SIMPLE_NOTE">
+ <props>
+ <prop key="shadow">true</prop>
+ <prop key="foo">bar</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:rule id="shadowRule" enable="true" column="shadow" sourceDataSourceNames="ds" shadowDataSourceNames="ds_shadow">
+ <shadow:data-source id="shadow-data-source" source-data-source-name="ds" shadow-data-source-name="ds_shadow"/>
+ <shadow:shadow-table name="t_order">
+ <shadow:algorithm shadow-algorithm-ref= "user-id-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref= "simple-note-algorithm" />
+ </shadow:shadow-table>
+ <shadow:shadow-table name="t_user">
+ <shadow:algorithm shadow-algorithm-ref= "simple-note-algorithm" />
+ </shadow:shadow-table>
+ </shadow:rule>
+
+ <shardingsphere:data-source id="shadowDataSource" data-source-names="ds,ds_shadow" rule-refs="shadowRule">
+ <props>
+ <prop key="sql-show">true</prop>
+ </props>
+ </shardingsphere:data-source>
+
+ <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+ <property name="dataSource" ref="shadowDataSource" />
+ </bean>
+ <tx:annotation-driven />
+
+ <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+ <property name="dataSource" ref="shadowDataSource"/>
+ <property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/>
+ </bean>
+
+ <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+ <property name="basePackage" value="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.repository"/>
+ <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
+ </bean>
+</beans>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/ShadowMapper.xml
similarity index 51%
copy from examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
copy to examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/ShadowMapper.xml
index f48464d..fad6fdd 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/ShadowMapper.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
@@ -16,22 +16,15 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>shardingsphere-jdbc-example</artifactId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>other-feature-example</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <modules>
- <module>encrypt-example</module>
- <module>hint-example</module>
- <module>shadow-example</module>
- </modules>
-</project>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.repository.ShadowMapper">
+ <resultMap id="ShadowInfoMap" type="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo">
+ <result column="id" property="id" jdbcType="INTEGER"/>
+ <result column="user_id" property="userId" jdbcType="INTEGER"/>
+ <result column="content" property="content" jdbcType="VARCHAR"/>
+ </resultMap>
+
+ <insert id="execute" parameterType="java.lang.String">
+ ${sql}
+ </insert>
+</mapper>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml
similarity index 53%
copy from examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
copy to examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml
index f48464d..d07a6433 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml
@@ -16,22 +16,19 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>shardingsphere-jdbc-example</artifactId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>other-feature-example</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
+<configuration>
+ <property name="log.context.name" value="future-shadow-spring-namespace-mybatis-example" />
+ <property name="log.charset" value="UTF-8" />
+ <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
+ <contextName>${log.context.name}</contextName>
- <modules>
- <module>encrypt-example</module>
- <module>hint-example</module>
- <module>shadow-example</module>
- </modules>
-</project>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder charset="${log.charset}">
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ </appender>
+ <root>
+ <level value="INFO" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/pom.xml
similarity index 85%
copy from examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
copy to examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/pom.xml
index f48464d..32c97c1 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/pom.xml
@@ -22,16 +22,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>shardingsphere-jdbc-example</artifactId>
+ <artifactId>other-feature-example</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>other-feature-example</artifactId>
+ <artifactId>future-shadow-example</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
-
+
<modules>
- <module>encrypt-example</module>
- <module>hint-example</module>
- <module>shadow-example</module>
+ <module>future-shadow-spring-namespace-mybatis-example</module>
</modules>
</project>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
index f48464d..03663ea 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
@@ -33,5 +33,6 @@
<module>encrypt-example</module>
<module>hint-example</module>
<module>shadow-example</module>
+ <module>future-shadow-example</module>
</modules>
</project>
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java
index bbe512f..0a00982 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java
@@ -27,6 +27,8 @@ import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.shadow.constant.ShadowOrder;
import org.apache.shardingsphere.shadow.route.future.engine.ShadowRouteEngineFactory;
+import org.apache.shardingsphere.shadow.route.future.engine.validator.ShadowStatementValidator;
+import org.apache.shardingsphere.shadow.route.future.engine.validator.ShadowStatementValidatorFactory;
import org.apache.shardingsphere.shadow.route.judge.ShadowDataSourceJudgeEngine;
import org.apache.shardingsphere.shadow.route.judge.impl.PreparedShadowDataSourceJudgeEngine;
import org.apache.shardingsphere.shadow.route.judge.impl.SimpleShadowDataSourceJudgeEngine;
@@ -38,6 +40,7 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* Shadow SQL router.
@@ -113,7 +116,13 @@ public final class ShadowSQLRouter implements SQLRouter<ShadowRule> {
routeContext.getRouteUnits().addAll(toBeAdded);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
private void doShadowDecorateFuture(final RouteContext routeContext, final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShadowRule rule, final ConfigurationProperties props) {
+ SQLStatementContext<?> sqlStatementContext = logicSQL.getSqlStatementContext();
+ Optional<ShadowStatementValidator> shadowStatementValidator = ShadowStatementValidatorFactory.newInstance(sqlStatementContext.getSqlStatement());
+ if (shadowStatementValidator.isPresent() && !shadowStatementValidator.get().preValidate(sqlStatementContext)) {
+ return;
+ }
ShadowRouteEngineFactory.newInstance(logicSQL).route(routeContext, logicSQL, metaData, rule, props);
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
index a29d543..7cdcd41 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
@@ -41,22 +42,22 @@ public final class ColumnShadowAlgorithmDeterminer implements ShadowAlgorithmDet
@Override
public boolean isShadow(final InsertStatementContext insertStatementContext, final Collection<String> relatedShadowTables, final String tableName) {
Collection<String> columnNames = insertStatementContext.getInsertColumnNames();
- List<List<Object>> groupedParameters = insertStatementContext.getGroupedParameters();
Iterator<String> columnNamesIt = columnNames.iterator();
- Iterator<List<Object>> groupedParametersIt = groupedParameters.iterator();
- int count = Math.min(columnNames.size(), groupedParameters.size());
- for (int i = 0; i < count; i++) {
- Optional<Collection<PreciseColumnShadowValue<Comparable<?>>>> preciseColumnShadowValues = getPreciseColumnShadowValues(columnNamesIt.next(), groupedParametersIt.next(), tableName);
- if (preciseColumnShadowValues.isPresent()) {
- if (isPassColumn(preciseColumnShadowValues.get(), columnShadowAlgorithm, relatedShadowTables)) {
+ List<InsertValueContext> insertValueContexts = insertStatementContext.getInsertValueContexts();
+ int index = 0;
+ while (columnNamesIt.hasNext()) {
+ Optional<Collection<Comparable<?>>> columnValues = getColumnValues(insertValueContexts, index);
+ if (columnValues.isPresent()) {
+ if (isShadowColumn(createPreciseColumnShadowValues(columnNamesIt.next(), columnValues.get(), tableName, ShadowOperationType.INSERT), columnShadowAlgorithm, relatedShadowTables)) {
return true;
}
}
+ index++;
}
return false;
}
- private boolean isPassColumn(final Collection<PreciseColumnShadowValue<Comparable<?>>> preciseColumnShadowValues, final ColumnShadowAlgorithm<Comparable<?>> columnShadowAlgorithm,
+ private boolean isShadowColumn(final Collection<PreciseColumnShadowValue<Comparable<?>>> preciseColumnShadowValues, final ColumnShadowAlgorithm<Comparable<?>> columnShadowAlgorithm,
final Collection<String> relatedShadowTables) {
for (PreciseColumnShadowValue<Comparable<?>> each : preciseColumnShadowValues) {
if (!columnShadowAlgorithm.isShadow(relatedShadowTables, each)) {
@@ -66,13 +67,24 @@ public final class ColumnShadowAlgorithmDeterminer implements ShadowAlgorithmDet
return true;
}
- private Optional<Collection<PreciseColumnShadowValue<Comparable<?>>>> getPreciseColumnShadowValues(final String columnName, final List<Object> groupedParameter, final String tableName) {
+ private Collection<PreciseColumnShadowValue<Comparable<?>>> createPreciseColumnShadowValues(final String columnName, final Collection<Comparable<?>> columnValues, final String tableName,
+ final ShadowOperationType operationType) {
Collection<PreciseColumnShadowValue<Comparable<?>>> result = new LinkedList<>();
- for (Object each : groupedParameter) {
- if (!(each instanceof Comparable<?>)) {
+ for (Comparable<?> each : columnValues) {
+ result.add(new PreciseColumnShadowValue<>(tableName, operationType, columnName, each));
+ }
+ return result;
+ }
+
+ private Optional<Collection<Comparable<?>>> getColumnValues(final List<InsertValueContext> insertValueContexts, final int index) {
+ Collection<Comparable<?>> result = new LinkedList<>();
+ for (InsertValueContext each : insertValueContexts) {
+ Object valueObject = each.getValue(index);
+ if (valueObject instanceof Comparable<?>) {
+ result.add((Comparable<?>) valueObject);
+ } else {
return Optional.empty();
}
- result.add(new PreciseColumnShadowValue<>(tableName, ShadowOperationType.INSERT, columnName, (Comparable<?>) each));
}
return Optional.of(result);
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngine.java
index cb8b309..ed52539 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngine.java
@@ -49,7 +49,12 @@ public final class ShadowInsertStatementRoutingEngine extends AbstractShadowRout
Collection<String> relatedShadowTables = getRelatedShadowTables(insertStatementContext, shadowRule);
initShadowTableDeterminer(relatedShadowTables, shadowRule);
for (String each : relatedShadowTables) {
- getShadowTableDeterminer(each).ifPresent(tableDeterminer -> tableDeterminer.isShadow(insertStatementContext, shadowRule, each));
+ Optional<ShadowTableDeterminer> shadowTableDeterminer = getShadowTableDeterminer(each);
+ if (shadowTableDeterminer.isPresent()) {
+ if (shadowTableDeterminer.get().isShadow(insertStatementContext, shadowRule, each)) {
+ return true;
+ }
+ }
}
return false;
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidator.java
new file mode 100644
index 0000000..dd86bba
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidator.java
@@ -0,0 +1,37 @@
+/*
+ * 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.shadow.route.future.engine.validator;
+
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+/**
+ * Shadow statement validator.
+ *
+ * @param <T> type of SQL statement
+ */
+public interface ShadowStatementValidator<T extends SQLStatement> {
+
+ /**
+ * Validate whether shadow operation is supported before route.
+ *
+ * @param sqlStatementContext SQL statement context
+ * @return is shadow or not
+ */
+ boolean preValidate(SQLStatementContext<T> sqlStatementContext);
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidatorFactory.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidatorFactory.java
new file mode 100644
index 0000000..0d2bffa
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/ShadowStatementValidatorFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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.shadow.route.future.engine.validator;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.shadow.route.future.engine.validator.dml.ShadowInsertStatementValidator;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+
+import java.util.Optional;
+
+/**
+ * Shadow statement validator factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShadowStatementValidatorFactory {
+
+ /**
+ * New instance of shadow statement validator.
+ *
+ * @param sqlStatement sql statement
+ * @return instance of shadow statement validator
+ */
+ public static Optional<ShadowStatementValidator> newInstance(final SQLStatement sqlStatement) {
+ if (sqlStatement instanceof DMLStatement) {
+ return getDMLStatementValidator(sqlStatement);
+ }
+ return Optional.empty();
+ }
+
+ private static Optional<ShadowStatementValidator> getDMLStatementValidator(final SQLStatement sqlStatement) {
+ if (sqlStatement instanceof InsertStatement) {
+ return Optional.of(new ShadowInsertStatementValidator());
+ }
+ return Optional.empty();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/dml/ShadowInsertStatementValidator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/dml/ShadowInsertStatementValidator.java
new file mode 100644
index 0000000..19ddd3e
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/validator/dml/ShadowInsertStatementValidator.java
@@ -0,0 +1,36 @@
+/*
+ * 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.shadow.route.future.engine.validator.dml;
+
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
+import org.apache.shardingsphere.shadow.route.future.engine.validator.ShadowStatementValidator;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+
+import java.util.Objects;
+
+/**
+ * Shadow insert statement validator.
+ */
+public final class ShadowInsertStatementValidator implements ShadowStatementValidator<InsertStatement> {
+
+ @Override
+ public boolean preValidate(final SQLStatementContext<InsertStatement> sqlStatementContext) {
+ return Objects.isNull(((InsertStatementContext) sqlStatementContext).getInsertSelectContext());
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
index 97c4a2f..21290da 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
@@ -18,9 +18,12 @@
package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
import com.google.common.collect.Lists;
+import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import org.junit.Test;
import java.util.Collection;
@@ -44,27 +47,47 @@ public final class ColumnShadowAlgorithmDeterminerTest {
private void assertFalseCase() {
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class);
when(insertStatementContext.getInsertColumnNames()).thenReturn(createColumnNames());
- when(insertStatementContext.getGroupedParameters()).thenReturn(createGroupedParametersFalseCase());
+ when(insertStatementContext.getInsertValueContexts()).thenReturn(createInsertValueContextsFalseCase());
ColumnShadowAlgorithmDeterminer columnShadowAlgorithmDeterminer = new ColumnShadowAlgorithmDeterminer(createColumnShadowAlgorithm());
assertThat(columnShadowAlgorithmDeterminer.isShadow(insertStatementContext, createRelatedShadowTables(), "t_user"), is(false));
}
- private List<List<Object>> createGroupedParametersFalseCase() {
- List<List<Object>> result = new LinkedList<>();
- result.add(Lists.newArrayList(1, 2));
- result.add(Lists.newArrayList("jack", "rose"));
- result.add(Lists.newArrayList(1, 2));
+ private List<InsertValueContext> createInsertValueContextsFalseCase() {
+ List<InsertValueContext> result = new LinkedList<>();
+ result.add(new InsertValueContext(createAssignmentsFalseCase(), Lists.newLinkedList(), 0));
+ return result;
+ }
+
+ private Collection<ExpressionSegment> createAssignmentsFalseCase() {
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ result.add(new LiteralExpressionSegment(0, 1, 1));
+ result.add(new LiteralExpressionSegment(2, 6, "jack"));
+ result.add(new LiteralExpressionSegment(7, 8, 2));
return result;
}
private void assertTrueCase() {
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class);
when(insertStatementContext.getInsertColumnNames()).thenReturn(createColumnNames());
- when(insertStatementContext.getGroupedParameters()).thenReturn(createGroupedParametersTrueCase());
+ when(insertStatementContext.getInsertValueContexts()).thenReturn(createInsertValueContextsTrueCase());
ColumnShadowAlgorithmDeterminer columnShadowAlgorithmDeterminer = new ColumnShadowAlgorithmDeterminer(createColumnShadowAlgorithm());
assertThat(columnShadowAlgorithmDeterminer.isShadow(insertStatementContext, createRelatedShadowTables(), "t_user"), is(true));
}
+ private List<InsertValueContext> createInsertValueContextsTrueCase() {
+ List<InsertValueContext> result = new LinkedList<>();
+ result.add(new InsertValueContext(createAssignmentsTrueCase(), Lists.newLinkedList(), 0));
+ return result;
+ }
+
+ private Collection<ExpressionSegment> createAssignmentsTrueCase() {
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ result.add(new LiteralExpressionSegment(0, 1, 1));
+ result.add(new LiteralExpressionSegment(2, 6, "jack"));
+ result.add(new LiteralExpressionSegment(7, 8, 1));
+ return result;
+ }
+
private Collection<String> createRelatedShadowTables() {
Collection<String> result = new LinkedList<>();
result.add("t_user");
@@ -87,14 +110,6 @@ public final class ColumnShadowAlgorithmDeterminerTest {
return properties;
}
- private List<List<Object>> createGroupedParametersTrueCase() {
- List<List<Object>> result = new LinkedList<>();
- result.add(Lists.newArrayList(1, 2));
- result.add(Lists.newArrayList("jack", "rose"));
- result.add(Lists.newArrayList(1, 1));
- return result;
- }
-
private List<String> createColumnNames() {
List<String> result = new LinkedList<>();
result.add("id");
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/tag/ShadowRuleBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/tag/ShadowRuleBeanDefinitionTag.java
index 3e08ddd..239c04e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/tag/ShadowRuleBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/tag/ShadowRuleBeanDefinitionTag.java
@@ -45,11 +45,11 @@ public final class ShadowRuleBeanDefinitionTag {
public static final String SHADOW_DATA_SOURCE_NAME_ATTRIBUTE = "shadow-data-source-name";
- public static final String SHADOW_TABLE_TAG = "table";
+ public static final String SHADOW_TABLE_TAG = "shadow-table";
public static final String SHADOW_TABLE_NAME_ATTRIBUTE = "name";
- public static final String SHADOW_TABLE_ALGORITHM_TAG = "table-algorithm";
+ public static final String SHADOW_TABLE_ALGORITHM_TAG = "algorithm";
public static final String SHADOW_TABLE_ALGORITHM_REF_ATTRIBUTE = "shadow-algorithm-ref";
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
index 320251b..2e05b1e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
@@ -28,7 +28,7 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="data-source" minOccurs="0" maxOccurs="unbounded" />
- <xsd:element ref="table" minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="shadow-table" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="enable" type="xsd:boolean"/>
@@ -54,16 +54,16 @@
</xsd:complexType>
</xsd:element>
- <xsd:element name="table">
+ <xsd:element name="shadow-table">
<xsd:complexType>
<xsd:sequence>
- <xsd:element ref="table-algorithm" maxOccurs="unbounded" />
+ <xsd:element ref="algorithm" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
- <xsd:element name="table-algorithm">
+ <xsd:element name="algorithm">
<xsd:complexType>
<xsd:attribute name="shadow-algorithm-ref" type="xsd:string" use="required"/>
</xsd:complexType>
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
index 903fe6b..9af70bf 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
@@ -41,12 +41,12 @@
<shadow:rule id="shadowRule" enable="true" column="shadow" sourceDataSourceNames="ds0,ds1" shadowDataSourceNames="shadow_ds0,shadow_ds1">
<shadow:data-source id="shadow-data-source" source-data-source-name="ds" shadow-data-source-name="ds-shadow"/>
- <shadow:table name="t_order">
- <shadow:table-algorithm shadow-algorithm-ref= "user-id-match-algorithm" />
- <shadow:table-algorithm shadow-algorithm-ref= "simple-note-algorithm" />
- </shadow:table>
- <shadow:table name="t_user">
- <shadow:table-algorithm shadow-algorithm-ref= "simple-note-algorithm" />
- </shadow:table>
+ <shadow:shadow-table name="t_order">
+ <shadow:algorithm shadow-algorithm-ref= "user-id-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref= "simple-note-algorithm" />
+ </shadow:shadow-table>
+ <shadow:shadow-table name="t_user">
+ <shadow:algorithm shadow-algorithm-ref= "simple-note-algorithm" />
+ </shadow:shadow-table>
</shadow:rule>
</beans>