You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/09/30 13:25:14 UTC
[shardingsphere] branch master updated: New merge shadow code
(#12866)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new cd59c1f New merge shadow code (#12866)
cd59c1f is described below
commit cd59c1f6b1cad0364dbdc38a3d82af2ac6251d79
Author: gin <ja...@163.com>
AuthorDate: Thu Sep 30 21:24:31 2021 +0800
New merge shadow code (#12866)
* Shadow code merge.
* Shadow code merge fix ut.
* Shadow code merge fix distsql.
* Shadow code merge fix jdbc ut.
* Shadow code merge fix proxy yaml.
* Remove future shadow example.
* Remove future shadow.
* Fix shadow rule.
* Fix shadow rule code.
* add
---
.../example/core/api/entity/FutureShadowUser.java | 91 --------
.../example/core/api/entity/ShadowUser.java | 35 ++--
.../api/repository/FutureShadowUserRepository.java | 23 ---
.../jdbc/repository/ShadowUserRepositoryImpl.java | 36 ++--
.../core/jdbc/service/ShadowUserServiceImpl.java | 2 +-
.../example/core/jpa/entity/ShadowUserEntity.java | 14 +-
.../jpa/repository/ShadowUserRepositoryImpl.java | 14 +-
.../core/jpa/service/ShadowUserServiceImpl.java | 2 +-
.../MybatisFutureShadowUserRepository.java | 82 --------
.../repository/MybatisShadowUserRepository.java | 48 ++++-
.../service/FutureShadowUserServiceImpl.java | 94 ---------
.../mybatis/service/ShadowUserServiceImpl.java | 16 +-
.../META-INF/mappers/FutureShadowUserMapper.xml | 68 ------
.../META-INF/mappers/ShadowUserMapper.xml | 32 ++-
.../config/local/LocalShadowConfiguration.java | 2 +-
.../pom.xml | 50 -----
.../src/main/resources/META-INF/mybatis-config.xml | 26 ---
.../src/main/resources/application.properties | 26 ---
.../src/main/resources/logback.xml | 36 ----
.../pom.xml | 42 ----
.../ShadowSpringNamespaceMybatisExample.java | 53 -----
.../spring/namespace/mybatis/domain/OrderInfo.java | 34 ---
.../namespace/mybatis/repository/OrderMapper.java | 40 ----
.../namespace/mybatis/repository/ShadowMapper.java | 27 ---
.../namespace/mybatis/service/OrderService.java | 27 ---
.../namespace/mybatis/service/SQLGenerator.java | 163 ---------------
.../namespace/mybatis/service/ShadowService.java | 31 ---
.../mybatis/service/impl/OrderServiceImpl.java | 111 ----------
.../mybatis/service/impl/ShadowServiceImpl.java | 61 ------
.../resources/META-INF/mappers/OrderMapper.xml | 67 ------
.../resources/META-INF/mappers/ShadowMapper.xml | 24 ---
.../src/main/resources/logback.xml | 34 ---
.../future-shadow-example/pom.xml | 36 ----
.../other-feature-example/pom.xml | 1 -
.../other-feature-example/shadow-example/pom.xml | 5 +-
.../shadow-example/shadow-raw-jdbc-example/pom.xml | 43 ----
.../jdbc/ShadowRawJavaConfigurationExample.java | 49 -----
.../jdbc/ShadowRawYamlConfigurationExample.java | 46 -----
.../EncryptShadowDatabasesConfiguration.java | 72 -------
...writeSplittingShadowDatabasesConfiguration.java | 51 -----
.../jdbc/config/ShadowDatabasesConfiguration.java | 41 ----
.../ShardingShadowDatabasesConfiguration.java | 78 -------
.../table/raw/jdbc/factory/DataSourceFactory.java | 45 ----
.../raw/jdbc/factory/YamlDataSourceFactory.java | 48 -----
.../META-INF/encrypt-shadow-databases.yaml | 61 ------
.../readwrite-splitting-shadow-databases.yaml | 61 ------
.../main/resources/META-INF/shadow-databases.yaml | 38 ----
.../META-INF/sharding-shadow-databases.yaml | 81 --------
.../src/main/resources/logback.xml | 34 ---
.../shadow-spring-boot-mybatis-example/pom.xml | 2 +-
.../mybatis/ShadowSpringBootMybatisExample.java | 2 +-
.../mybatis/ShadowSpringBootMybatisExample.java | 41 ----
.../src/main/resources/META-INF/mybatis-config.xml | 4 -
...application-encrypt-shadow-databases.properties | 47 -----
...readwrite-splitting-shadow-databases.properties | 51 -----
.../application-shadow-databases.properties | 34 ---
.../application-shadow-encrypt.properties | 10 +-
...plication-shadow-readwrite-splitting.properties | 0
...pplication-shadow-sharding-databases.properties | 4 -
.../main/resources/application-shadow.properties} | 14 +-
...pplication-sharding-shadow-databases.properties | 60 ------
.../src/main/resources/application.properties | 13 +-
.../ShadowSpringNamespaceMybatisExample.java | 10 +-
.../META-INF/application-shadow-databases.xml | 74 -------
...atabases.xml => application-shadow-encrypt.xml} | 69 +++++--
... => application-shadow-readwrite-splitting.xml} | 81 ++++++--
...l => application-shadow-sharding-databases.xml} | 60 +++++-
.../resources/META-INF/application-shadow.xml} | 48 +++--
.../shadow/api/config/ShadowRuleConfiguration.java | 21 +-
.../shadow/{column => }/ShadowOperationType.java | 2 +-
.../shadow/column/PreciseColumnShadowValue.java | 1 +
.../api/shadow/note/PreciseNoteShadowValue.java | 2 +-
.../AlgorithmProvidedShadowRuleConfiguration.java | 10 -
.../column/ColumnRegexMatchShadowAlgorithm.java | 2 +-
.../shadow/note/SimpleSQLNoteShadowAlgorithm.java | 2 +-
...ithmProvidedShadowRuleConfigurationChecker.java | 2 +-
.../checker/ShadowRuleConfigurationChecker.java | 2 +-
.../ShadowColumnCondition.java | 2 +-
.../shadow/condition/ShadowCondition.java | 84 --------
.../shadow/condition/ShadowConditionEngine.java | 130 ------------
.../ShadowDetermineCondition.java | 4 +-
.../shadow/rewrite/aware/ShadowRuleAware.java | 33 ---
.../context/ShadowSQLRewriteContextDecorator.java | 70 -------
.../rewrite/parameter/ShadowParameterRewriter.java | 48 -----
.../parameter/ShadowParameterRewriterBuilder.java | 57 ------
.../impl/ShadowInsertValueParameterRewriter.java | 71 -------
.../impl/ShadowPredicateParameterRewriter.java | 53 -----
.../impl/ShadowUpdateValueParameterRewriter.java | 65 ------
.../rewrite/token/ShadowTokenGenerateBuilder.java | 58 ------
.../generator/BaseShadowSQLTokenGenerator.java | 46 -----
.../impl/ShadowInsertColumnTokenGenerator.java | 77 -------
.../impl/ShadowInsertValuesTokenGenerator.java | 123 -----------
.../impl/ShadowPredicateColumnTokenGenerator.java | 93 ---------
.../impl/ShadowUpdateColumnTokenGenerator.java | 71 -------
.../token/pojo/ShadowInsertValuesToken.java | 43 ----
.../shadow/route/ShadowSQLRouter.java | 74 +------
.../{future => }/engine/ShadowRouteEngine.java | 2 +-
.../engine/ShadowRouteEngineFactory.java | 12 +-
.../determiner/ShadowAlgorithmDeterminer.java | 3 +-
.../engine/determiner/ShadowDeterminerFactory.java | 6 +-
.../algorithm/ColumnShadowAlgorithmDeterminer.java | 10 +-
.../algorithm/NoteShadowAlgorithmDeterminer.java | 8 +-
.../dml/AbstractShadowDMLStatementRouteEngine.java | 10 +-
.../dml/ShadowDeleteStatementRoutingEngine.java | 18 +-
.../dml/ShadowInsertStatementRoutingEngine.java | 8 +-
.../dml/ShadowSelectStatementRoutingEngine.java | 17 +-
.../dml/ShadowUpdateStatementRoutingEngine.java | 18 +-
.../impl/ShadowNonDMLStatementRoutingEngine.java | 10 +-
.../{future => }/engine/util/ShadowExtractor.java | 2 +-
.../route/judge/ShadowDataSourceJudgeEngine.java | 31 ---
.../impl/PreparedShadowDataSourceJudgeEngine.java | 110 ----------
.../impl/SimpleShadowDataSourceJudgeEngine.java | 78 -------
.../route/judge/util/ShadowValueJudgeUtil.java | 39 ----
.../shardingsphere/shadow/rule/ShadowRule.java | 24 +--
.../shadow/rule/checker/ShadowRuleChecker.java | 2 +-
.../yaml/config/YamlShadowRuleConfiguration.java | 8 -
...eAlgorithmProviderConfigurationYamlSwapper.java | 15 +-
.../ShadowRuleConfigurationYamlSwapper.java | 16 +-
...nfra.rewrite.context.SQLRewriteContextDecorator | 18 --
.../ColumnRegexMatchShadowAlgorithmTest.java | 2 +-
.../note/SimpleSQLNoteShadowAlgorithmTest.java | 2 +-
...ProvidedShadowRuleConfigurationCheckerTest.java | 31 +--
.../ShadowRuleConfigurationCheckerTest.java | 28 +--
.../condition/ShadowConditionEngineTest.java | 46 -----
.../shadow/condition/ShadowConditionTest.java | 36 ----
.../ShadowSQLRewriteContextDecoratorTest.java | 45 ----
.../ShadowParameterRewriterBuilderTest.java | 42 ----
.../ShadowInsertValueParameterRewriterTest.java | 70 -------
.../impl/ShadowPredicateParameterRewriterTest.java | 48 -----
.../ShadowUpdateValueParameterRewriterTest.java | 89 --------
.../token/ShadowTokenGenerateBuilderTest.java | 41 ----
.../impl/ShadowInsertColumnTokenGeneratorTest.java | 94 ---------
.../impl/ShadowInsertValuesTokenGeneratorTest.java | 91 --------
.../ShadowPredicateColumnTokenGeneratorTest.java | 49 -----
.../impl/ShadowUpdateColumnTokenGeneratorTest.java | 97 ---------
.../token/pojo/ShadowInsertValuesTokenTest.java | 39 ----
.../shadow/route/ShadowSQLRouterTest.java | 191 -----------------
.../engine/ShadowRouteEngineFactoryTest.java | 4 +-
.../determiner/ShadowDeterminerFactoryTest.java | 6 +-
.../ColumnShadowAlgorithmDeterminerTest.java | 13 +-
.../NoteShadowAlgorithmDeterminerTest.java | 11 +-
.../ShadowInsertStatementRoutingEngineTest.java | 8 +-
.../impl/PreparedShadowDataSourceRouterTest.java | 126 ------------
.../impl/SimpleShadowDataSourceRouterTest.java | 174 ----------------
.../route/judge/util/ShadowValueJudgeUtilTest.java | 77 -------
.../shardingsphere/shadow/rule/ShadowRuleTest.java | 19 +-
...orithmProviderConfigurationYamlSwapperTest.java | 31 +--
.../ShadowRuleConfigurationYamlSwapperTest.java | 19 +-
...urationsForYamlShadowRuleConfigurationTest.java | 11 -
.../src/test/resources/yaml/shadow-rule.yaml | 58 +++++-
.../converter/ShadowRuleStatementConverter.java | 2 +-
.../AlterShadowAlgorithmStatementUpdater.java | 3 +-
.../query/ShadowAlgorithmQueryResultSetTest.java | 2 +-
.../query/ShadowRuleQueryResultSetTest.java | 2 +-
.../query/ShadowTableRuleQueryResultSetTest.java | 2 +-
.../PropertiesShadowSpringBootStarterTest.java | 9 -
.../boot/YmlShadowSpringBootStarterTest.java | 9 -
.../application-shadow-properties.properties | 4 -
.../src/test/resources/application-shadow-yml.yml | 4 -
.../parser/ShadowRuleBeanDefinitionParser.java | 8 -
.../namespace/tag/ShadowRuleBeanDefinitionTag.java | 7 -
.../main/resources/META-INF/namespace/shadow.xsd | 5 -
.../ShadowAlgorithmSpringNamespaceTest.java | 9 -
.../namespace/ShadowSpringNamespaceTest.java | 54 -----
.../shadow-algorithm-application-context.xml | 3 +-
.../META-INF/spring/shadow-application-context.xml | 28 ---
...hardingSphereDataSourceForFutureShadowTest.java | 72 -------
.../FutureShadowPreparedStatementTest.java | 228 ---------------------
.../core/statement/FutureShadowStatementTest.java | 175 ----------------
.../statement/ShadowPreparedStatementTest.java | 222 +++++++++++---------
.../jdbc/core/statement/ShadowStatementTest.java | 133 +++++++-----
.../resources/config/config-future-shadow.yaml | 69 -------
.../src/test/resources/config/config-shadow.yaml | 47 ++++-
.../spring/boot/SpringBootStarterTest.java | 33 ++-
.../test/resources/application-common.properties | 20 +-
.../src/main/resources/conf/config-shadow.yaml | 113 ++++++++--
176 files changed, 926 insertions(+), 6471 deletions(-)
diff --git a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/FutureShadowUser.java b/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/FutureShadowUser.java
deleted file mode 100644
index 459afd9..0000000
--- a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/FutureShadowUser.java
+++ /dev/null
@@ -1,91 +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.core.api.entity;
-
-import java.io.Serializable;
-
-public class FutureShadowUser implements Serializable {
-
- private static final long serialVersionUID = -6711618386636677067L;
-
- private int userId;
-
- private int userType;
-
- private String userName;
-
- private String userNamePlain;
-
- private String pwd;
-
- private String assistedQueryPwd;
-
- public int getUserId() {
- return userId;
- }
-
- public void setUserId(int userId) {
- this.userId = userId;
- }
-
- public int getUserType() {
- return userType;
- }
-
- public void setUserType(int userType) {
- this.userType = userType;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getUserNamePlain() {
- return userNamePlain;
- }
-
- public void setUserNamePlain(String userNamePlain) {
- this.userNamePlain = userNamePlain;
- }
-
- public String getPwd() {
- return pwd;
- }
-
- public void setPwd(String pwd) {
- this.pwd = pwd;
- }
-
- public String getAssistedQueryPwd() {
- return assistedQueryPwd;
- }
-
- public void setAssistedQueryPwd(String assistedQueryPwd) {
- this.assistedQueryPwd = assistedQueryPwd;
- }
-
- @Override
- public String toString() {
- return String.format("user_id: %d, user_type: %d, user_name: %s, user_name_plain: %s, pwd: %s, assisted_query_pwd: %s", userId, userType, userName, userNamePlain, pwd,
- assistedQueryPwd);
- }
-}
diff --git a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/ShadowUser.java b/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/ShadowUser.java
index c5c334e..3c3dd74 100644
--- a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/ShadowUser.java
+++ b/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/entity/ShadowUser.java
@@ -21,10 +21,12 @@ import java.io.Serializable;
public class ShadowUser implements Serializable {
- private static final long serialVersionUID = 263434701950670170L;
+ private static final long serialVersionUID = -6711618386636677067L;
private int userId;
+ private int userType;
+
private String userName;
private String userNamePlain;
@@ -33,21 +35,27 @@ public class ShadowUser implements Serializable {
private String assistedQueryPwd;
- private Boolean shadow;
-
public int getUserId() {
return userId;
}
- public void setUserId(final int userId) {
+ public void setUserId(int userId) {
this.userId = userId;
}
+ public int getUserType() {
+ return userType;
+ }
+
+ public void setUserType(int userType) {
+ this.userType = userType;
+ }
+
public String getUserName() {
return userName;
}
- public void setUserName(final String userName) {
+ public void setUserName(String userName) {
this.userName = userName;
}
@@ -55,7 +63,7 @@ public class ShadowUser implements Serializable {
return userNamePlain;
}
- public void setUserNamePlain(final String userNamePlain) {
+ public void setUserNamePlain(String userNamePlain) {
this.userNamePlain = userNamePlain;
}
@@ -63,7 +71,7 @@ public class ShadowUser implements Serializable {
return pwd;
}
- public void setPwd(final String pwd) {
+ public void setPwd(String pwd) {
this.pwd = pwd;
}
@@ -71,20 +79,13 @@ public class ShadowUser implements Serializable {
return assistedQueryPwd;
}
- public void setAssistedQueryPwd(final String assistedQueryPwd) {
+ public void setAssistedQueryPwd(String assistedQueryPwd) {
this.assistedQueryPwd = assistedQueryPwd;
}
- public Boolean isShadow() {
- return shadow;
- }
-
- public void setShadow(final Boolean shadow) {
- this.shadow = shadow;
- }
-
@Override
public String toString() {
- return String.format("user_id: %d, user_name: %s, user_name_plain: %s, pwd: %s, assisted_query_pwd: %s, shadow: %s", userId, userName, userNamePlain, pwd, assistedQueryPwd, shadow);
+ return String.format("user_id: %d, user_type: %d, user_name: %s, user_name_plain: %s, pwd: %s, assisted_query_pwd: %s", userId, userType, userName, userNamePlain, pwd,
+ assistedQueryPwd);
}
}
diff --git a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/repository/FutureShadowUserRepository.java b/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/repository/FutureShadowUserRepository.java
deleted file mode 100644
index 7b079bd..0000000
--- a/examples/example-core/example-api/src/main/java/org/apache/shardingsphere/example/core/api/repository/FutureShadowUserRepository.java
+++ /dev/null
@@ -1,23 +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.core.api.repository;
-
-import org.apache.shardingsphere.example.core.api.entity.FutureShadowUser;
-
-public interface FutureShadowUserRepository extends CommonRepository<FutureShadowUser, Long> {
-}
diff --git a/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/repository/ShadowUserRepositoryImpl.java b/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/repository/ShadowUserRepositoryImpl.java
index 11ba1a0..53fea49 100644
--- a/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/repository/ShadowUserRepositoryImpl.java
+++ b/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/repository/ShadowUserRepositoryImpl.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.example.core.jdbc.repository;
import org.apache.shardingsphere.example.core.api.entity.ShadowUser;
-import org.apache.shardingsphere.example.core.api.repository.ShadowUserRepository;
+import org.apache.shardingsphere.example.core.api.repository.CommonRepository;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -29,7 +29,7 @@ import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
-public final class ShadowUserRepositoryImpl implements ShadowUserRepository {
+public final class ShadowUserRepositoryImpl implements CommonRepository<ShadowUser, Long> {
private final DataSource dataSource;
@@ -40,7 +40,7 @@ public final class ShadowUserRepositoryImpl implements ShadowUserRepository {
@Override
public void createTableIfNotExists() throws SQLException {
String sql = "CREATE TABLE IF NOT EXISTS t_user "
- + "(user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id))";
+ + "(user_id INT NOT NULL AUTO_INCREMENT, user_type INT NOT NULL, user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id))";
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
@@ -67,13 +67,13 @@ public final class ShadowUserRepositoryImpl implements ShadowUserRepository {
@Override
public Long insert(final ShadowUser entity) throws SQLException {
- String sql = "INSERT INTO t_user (user_id, user_name, pwd,shadow) VALUES (?, ?, ?,?)";
+ String sql = "INSERT INTO t_user (user_id, user_type, user_name, pwd) VALUES (?, ?, ?, ?)";
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, entity.getUserId());
- preparedStatement.setString(2, entity.getUserName());
- preparedStatement.setString(3, entity.getPwd());
- preparedStatement.setBoolean(4, entity.isShadow());
+ preparedStatement.setInt(2, entity.getUserType());
+ preparedStatement.setString(3, entity.getUserName());
+ preparedStatement.setString(4, entity.getPwd());
preparedStatement.executeUpdate();
}
return (long) entity.getUserId();
@@ -81,38 +81,38 @@ public final class ShadowUserRepositoryImpl implements ShadowUserRepository {
@Override
public void delete(final Long id) throws SQLException {
- String sql = "DELETE FROM t_user WHERE user_id=? and shadow=?";
- deleteUser(sql, id, true);
- deleteUser(sql, id, false);
+ String sql = "DELETE FROM t_user WHERE user_id = ? and shadow= ?";
+ deleteUser(sql, id, (int) (id % 2));
+ deleteUser(sql, id, (int) (id % 2));
}
- private void deleteUser(final String sql, final Long id, final boolean isShadow) throws SQLException {
+ private void deleteUser(final String sql, final Long id, final int userType) throws SQLException {
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setLong(1, id);
- preparedStatement.setBoolean(2, isShadow);
+ preparedStatement.setInt(2, userType);
preparedStatement.executeUpdate();
}
}
@Override
public List<ShadowUser> selectAll() throws SQLException {
- List<ShadowUser> users;
- String sql = "SELECT * FROM t_user where shadow=?";
- users = getUsers(sql, false);
- users.addAll(getUsers(sql, true));
+ String sql = "SELECT * FROM t_user where user_type = ?";
+ List<ShadowUser> users = getUsers(sql, 1);
+ users.addAll(getUsers(sql, 0));
return users;
}
- private List<ShadowUser> getUsers(final String sql, final boolean isShadow) throws SQLException {
+ private List<ShadowUser> getUsers(final String sql, final int userType) throws SQLException {
List<ShadowUser> result = new LinkedList<>();
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
- preparedStatement.setBoolean(1, isShadow);
+ preparedStatement.setInt(1, userType);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
ShadowUser user = new ShadowUser();
user.setUserId(resultSet.getInt("user_id"));
+ user.setUserType(resultSet.getInt("user_type"));
user.setUserName(resultSet.getString("user_name"));
user.setPwd(resultSet.getString("pwd"));
result.add(user);
diff --git a/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/service/ShadowUserServiceImpl.java b/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/service/ShadowUserServiceImpl.java
index d733db8..91a1256 100644
--- a/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/service/ShadowUserServiceImpl.java
+++ b/examples/example-core/example-raw-jdbc/src/main/java/org/apache/shardingsphere/example/core/jdbc/service/ShadowUserServiceImpl.java
@@ -68,9 +68,9 @@ public final class ShadowUserServiceImpl implements ExampleService {
for (int i = 1; i <= 10; i++) {
ShadowUser user = new ShadowUser();
user.setUserId(i);
+ user.setUserType(i % 2);
user.setUserName("test_" + i);
user.setPwd("pwd" + i);
- user.setShadow(i % 2 == 0);
userRepository.insert(user);
result.add((long) user.getUserId());
}
diff --git a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/entity/ShadowUserEntity.java b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/entity/ShadowUserEntity.java
index d6577b4..daaa9ba 100644
--- a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/entity/ShadowUserEntity.java
+++ b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/entity/ShadowUserEntity.java
@@ -25,7 +25,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
@Entity
-@Table(name = "t_shadow_user")
+@Table(name = "t_user")
public final class ShadowUserEntity extends ShadowUser {
private static final long serialVersionUID = -3708998745561667721L;
@@ -37,6 +37,12 @@ public final class ShadowUserEntity extends ShadowUser {
return super.getUserId();
}
+ @Column(name = "user_type")
+ @Override
+ public int getUserType() {
+ return super.getUserType();
+ }
+
@Column(name = "user_name")
@Override
public String getUserName() {
@@ -48,10 +54,4 @@ public final class ShadowUserEntity extends ShadowUser {
public String getPwd() {
return super.getPwd();
}
-
- @Column(name = "shadow")
- @Override
- public Boolean isShadow() {
- return super.isShadow();
- }
}
diff --git a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/repository/ShadowUserRepositoryImpl.java b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/repository/ShadowUserRepositoryImpl.java
index e678d34..5df391d 100644
--- a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/repository/ShadowUserRepositoryImpl.java
+++ b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/repository/ShadowUserRepositoryImpl.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.example.core.jpa.repository;
import org.apache.shardingsphere.example.core.api.entity.ShadowUser;
-import org.apache.shardingsphere.example.core.api.repository.ShadowUserRepository;
+import org.apache.shardingsphere.example.core.api.repository.CommonRepository;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
@@ -30,7 +30,7 @@ import java.util.List;
@Repository
@Transactional
-public class ShadowUserRepositoryImpl implements ShadowUserRepository {
+public class ShadowUserRepositoryImpl implements CommonRepository<ShadowUser, Long> {
@PersistenceContext
private EntityManager entityManager;
@@ -58,9 +58,9 @@ public class ShadowUserRepositoryImpl implements ShadowUserRepository {
@Override
public void delete(final Long id) {
- Query query = entityManager.createQuery("DELETE FROM ShadowUserEntity o WHERE o.userId = ?1 and o.shadow = ?2");
+ Query query = entityManager.createQuery("DELETE FROM ShadowUserEntity o WHERE o.userId = ?1 and o.userType = ?2");
query.setParameter(1, id.intValue());
- query.setParameter(2, id % 2 == 0);
+ query.setParameter(2, id % 2);
query.executeUpdate();
}
@@ -68,10 +68,10 @@ public class ShadowUserRepositoryImpl implements ShadowUserRepository {
@SuppressWarnings("unchecked")
public List<ShadowUser> selectAll() {
List<ShadowUser> users = new ArrayList<>();
- Query query = entityManager.createQuery("SELECT o FROM ShadowUserEntity o WHERE o.shadow = ?1");
- query.setParameter(1, true);
+ Query query = entityManager.createQuery("SELECT o FROM ShadowUserEntity o WHERE o.userType = ?1");
+ query.setParameter(1, 0);
users.addAll(query.getResultList());
- query.setParameter(1, false);
+ query.setParameter(1, 1);
users.addAll(query.getResultList());
return users;
}
diff --git a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/service/ShadowUserServiceImpl.java b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/service/ShadowUserServiceImpl.java
index 73c3685..b67203b 100644
--- a/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/service/ShadowUserServiceImpl.java
+++ b/examples/example-core/example-spring-jpa/src/main/java/org/apache/shardingsphere/example/core/jpa/service/ShadowUserServiceImpl.java
@@ -68,9 +68,9 @@ public class ShadowUserServiceImpl implements ExampleService {
for (int i = 1; i <= 10; i++) {
ShadowUserEntity user = new ShadowUserEntity();
user.setUserId(i);
+ user.setUserType(i % 2);
user.setUserName("test_jpa_" + i);
user.setPwd("pwd_jpa_" + i);
- user.setShadow(i % 2 == 0);
userRepository.insert(user);
result.add((long) user.getUserId());
}
diff --git a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisFutureShadowUserRepository.java b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisFutureShadowUserRepository.java
deleted file mode 100644
index 9b647ac..0000000
--- a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisFutureShadowUserRepository.java
+++ /dev/null
@@ -1,82 +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.core.mybatis.repository;
-
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.shardingsphere.example.core.api.entity.FutureShadowUser;
-import org.apache.shardingsphere.example.core.api.repository.FutureShadowUserRepository;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Mapper
-public interface MybatisFutureShadowUserRepository extends FutureShadowUserRepository {
-
- @Override
- default void createTableIfNotExists() throws SQLException {
- createTableIfNotExistsNative();
- createTableIfNotExistsShadow();
- }
-
- void createTableIfNotExistsNative();
-
- void createTableIfNotExistsShadow();
-
- @Override
- default void truncateTable() throws SQLException {
- truncateTableNative();
- truncateTableShadow();
- }
-
- void truncateTableNative();
-
- void truncateTableShadow();
-
- @Override
- default void dropTable() throws SQLException {
- dropTableNative();
- dropTableShadow();
- }
-
- void dropTableNative();
-
- void dropTableShadow();
-
- @Override
- default List<FutureShadowUser> selectAll() throws SQLException {
- List<FutureShadowUser> result = new ArrayList<>();
- result.addAll(selectAllByShadow(0));
- result.addAll(selectAllByShadow(1));
- return result;
- }
-
- List<FutureShadowUser> selectAllByShadow(int userType) throws SQLException;
-
- @Override
- default void delete(Long primaryKey) throws SQLException {
- Map<String, Long> idTypeMapping = new HashMap<>(2);
- idTypeMapping.put("userId", primaryKey);
- idTypeMapping.put("userType", primaryKey % 2);
- deleteOne(idTypeMapping);
- }
-
- void deleteOne(Map<String, Long> idTypeMapping);
-}
diff --git a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
index 913f5da..7308b02 100644
--- a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
+++ b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
@@ -23,18 +23,60 @@ import org.apache.shardingsphere.example.core.api.repository.ShadowUserRepositor
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
@Mapper
public interface MybatisShadowUserRepository extends ShadowUserRepository {
@Override
+ default void createTableIfNotExists() throws SQLException {
+ createTableIfNotExistsShadow();
+ createTableIfNotExistsNative();
+ }
+
+ void createTableIfNotExistsNative();
+
+ void createTableIfNotExistsShadow();
+
+ @Override
+ default void truncateTable() throws SQLException {
+ truncateTableShadow();
+ truncateTableNative();
+ }
+
+ void truncateTableNative();
+
+ void truncateTableShadow();
+
+ @Override
+ default void dropTable() throws SQLException {
+ dropTableShadow();
+ dropTableNative();
+ }
+
+ void dropTableNative();
+
+ void dropTableShadow();
+
+ @Override
default List<ShadowUser> selectAll() throws SQLException {
List<ShadowUser> result = new ArrayList<>();
- result.addAll(selectAllByShadow(true));
- result.addAll(selectAllByShadow(false));
+ result.addAll(selectAllByShadow(0));
+ result.addAll(selectAllByShadow(1));
return result;
}
- List<ShadowUser> selectAllByShadow(boolean shadow) throws SQLException;
+ List<ShadowUser> selectAllByShadow(int userType) throws SQLException;
+
+ @Override
+ default void delete(Long primaryKey) throws SQLException {
+ Map<String, Long> idTypeMapping = new HashMap<>(2);
+ idTypeMapping.put("userId", primaryKey);
+ idTypeMapping.put("userType", primaryKey % 2);
+ deleteOne(idTypeMapping);
+ }
+
+ void deleteOne(Map<String, Long> idTypeMapping);
}
diff --git a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/FutureShadowUserServiceImpl.java b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/FutureShadowUserServiceImpl.java
deleted file mode 100644
index 0588784..0000000
--- a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/FutureShadowUserServiceImpl.java
+++ /dev/null
@@ -1,94 +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.core.mybatis.service;
-
-import org.apache.shardingsphere.example.core.api.entity.FutureShadowUser;
-import org.apache.shardingsphere.example.core.api.repository.FutureShadowUserRepository;
-import org.apache.shardingsphere.example.core.api.service.ExampleService;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-@Service("futureShadow")
-public class FutureShadowUserServiceImpl implements ExampleService {
-
- @Resource
- private FutureShadowUserRepository userRepository;
-
- @Override
- public void initEnvironment() throws SQLException {
- userRepository.createTableIfNotExists();
- userRepository.truncateTable();
- }
-
- @Override
- public void cleanEnvironment() throws SQLException {
- userRepository.dropTable();
- }
-
- @Override
- public void processSuccess() throws SQLException {
- System.out.println("-------------- Process Success Begin ---------------");
- List<Long> userIds = insertData();
- printData();
- deleteData(userIds);
- printData();
- System.out.println("-------------- Process Success Finish --------------");
- }
-
- private List<Long> insertData() throws SQLException {
- System.out.println("---------------------------- Insert Data ----------------------------");
- List<Long> result = new ArrayList<>(10);
- for (int i = 1; i <= 10; i++) {
- FutureShadowUser user = new FutureShadowUser();
- user.setUserId(i);
- user.setUserType(i % 2);
- user.setUserName("test_mybatis_" + i);
- user.setPwd("pwd_mybatis_" + i);
- userRepository.insert(user);
- result.add((long) user.getUserId());
- }
- return result;
- }
-
- private void deleteData(final List<Long> userIds) throws SQLException {
- System.out.println("---------------------------- Delete Data ----------------------------");
- for (Long each : userIds) {
- userRepository.delete(each);
- }
- }
-
- @Override
- 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.");
- }
-
- @Override
- public void printData() throws SQLException {
- System.out.println("---------------------------- Print User Data -----------------------");
- for (Object each : userRepository.selectAll()) {
- System.out.println(each);
- }
- }
-}
diff --git a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/ShadowUserServiceImpl.java b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/ShadowUserServiceImpl.java
index f5e06c5..aa95126 100644
--- a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/ShadowUserServiceImpl.java
+++ b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/service/ShadowUserServiceImpl.java
@@ -60,15 +60,22 @@ public class ShadowUserServiceImpl implements ExampleService {
for (int i = 1; i <= 10; i++) {
ShadowUser user = new ShadowUser();
user.setUserId(i);
+ user.setUserType(i % 2);
user.setUserName("test_mybatis_" + i);
user.setPwd("pwd_mybatis_" + i);
- user.setShadow(i % 2 == 0);
userRepository.insert(user);
result.add((long) user.getUserId());
}
return result;
}
+ private void deleteData(final List<Long> userIds) throws SQLException {
+ System.out.println("---------------------------- Delete Data ----------------------------");
+ for (Long each : userIds) {
+ userRepository.delete(each);
+ }
+ }
+
@Override
public void processFailure() throws SQLException {
System.out.println("-------------- Process Failure Begin ---------------");
@@ -77,13 +84,6 @@ public class ShadowUserServiceImpl implements ExampleService {
throw new RuntimeException("Exception occur for transaction test.");
}
- private void deleteData(final List<Long> userIds) throws SQLException {
- System.out.println("---------------------------- Delete Data ----------------------------");
- for (Long each : userIds) {
- userRepository.delete(each);
- }
- }
-
@Override
public void printData() throws SQLException {
System.out.println("---------------------------- Print User Data -----------------------");
diff --git a/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/FutureShadowUserMapper.xml b/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/FutureShadowUserMapper.xml
deleted file mode 100644
index e3ec076..0000000
--- a/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/FutureShadowUserMapper.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?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.
- -->
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="org.apache.shardingsphere.example.core.mybatis.repository.MybatisFutureShadowUserRepository">
- <resultMap id="baseResultMap" type="org.apache.shardingsphere.example.core.api.entity.FutureShadowUser">
- <result column="user_id" property="userId" jdbcType="INTEGER"/>
- <result column="user_type" property="userType" jdbcType="INTEGER"/>
- <result column="user_name" property="userName" jdbcType="VARCHAR"/>
- <result column="pwd" property="pwd" jdbcType="VARCHAR"/>
- <result column="assisted_query_pwd" property="assistedQueryPwd" jdbcType="VARCHAR"/>
- </resultMap>
-
- <update id="createTableIfNotExistsNative">
- CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_type INT(11), user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id));
- </update>
-
- <update id="createTableIfNotExistsShadow">
- CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_type INT(11), user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id)) /*shadow:true,foo:bar*/;
- </update>
-
- <update id="truncateTableNative">
- TRUNCATE TABLE t_user;
- </update>
-
- <update id="truncateTableShadow">
- TRUNCATE TABLE t_user /*shadow:true,foo:bar*/;
- </update>
-
- <update id="dropTableNative">
- DROP TABLE IF EXISTS t_user;
- </update>
-
- <update id="dropTableShadow">
- DROP TABLE IF EXISTS t_user /*shadow:true,foo:bar*/;
- </update>
-
- <insert id="insert">
- INSERT INTO t_user (user_id, user_type, user_name, pwd) VALUES (#{userId,jdbcType=INTEGER}, #{userType,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR});
- </insert>
-
- <delete id="deleteOne">
- DELETE FROM t_user WHERE user_id = #{userId,jdbcType=INTEGER} AND user_type = #{userType,jdbcType=INTEGER};
- </delete>
-
- <select id="selectAll" resultMap="baseResultMap">
- SELECT * FROM t_user WHERE user_type = #{userType,jdbcType=INTEGER};
- </select>
-
- <select id="selectAllByShadow" resultMap="baseResultMap">
- SELECT * FROM t_user WHERE user_type = #{userType,jdbcType=INTEGER};
- </select>
-</mapper>
diff --git a/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/ShadowUserMapper.xml b/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/ShadowUserMapper.xml
index 0ad5b39..2850a54 100644
--- a/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/ShadowUserMapper.xml
+++ b/examples/example-core/example-spring-mybatis/src/main/resources/META-INF/mappers/ShadowUserMapper.xml
@@ -20,37 +20,49 @@
<mapper namespace="org.apache.shardingsphere.example.core.mybatis.repository.MybatisShadowUserRepository">
<resultMap id="baseResultMap" type="org.apache.shardingsphere.example.core.api.entity.ShadowUser">
<result column="user_id" property="userId" jdbcType="INTEGER"/>
+ <result column="user_type" property="userType" jdbcType="INTEGER"/>
<result column="user_name" property="userName" jdbcType="VARCHAR"/>
<result column="pwd" property="pwd" jdbcType="VARCHAR"/>
<result column="assisted_query_pwd" property="assistedQueryPwd" jdbcType="VARCHAR"/>
- <result column="shadow" property="shadow" jdbcType="BOOLEAN"/>
</resultMap>
- <update id="createTableIfNotExists">
- CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id));
+ <update id="createTableIfNotExistsNative">
+ CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_type INT(11), user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id));
</update>
- <update id="truncateTable">
+ <update id="createTableIfNotExistsShadow">
+ CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_type INT(11), user_name VARCHAR(200), pwd VARCHAR(200), PRIMARY KEY (user_id)) /*shadow:true,foo:bar*/;
+ </update>
+
+ <update id="truncateTableNative">
TRUNCATE TABLE t_user;
</update>
- <update id="dropTable">
+ <update id="truncateTableShadow">
+ TRUNCATE TABLE t_user /*shadow:true,foo:bar*/;
+ </update>
+
+ <update id="dropTableNative">
DROP TABLE IF EXISTS t_user;
</update>
+ <update id="dropTableShadow">
+ DROP TABLE IF EXISTS t_user /*shadow:true,foo:bar*/;
+ </update>
+
<insert id="insert">
- INSERT INTO t_user (user_id, user_name, pwd, shadow) VALUES (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, #{shadow,jdbcType=BOOLEAN})
+ INSERT INTO t_user (user_id, user_type, user_name, pwd) VALUES (#{userId,jdbcType=INTEGER}, #{userType,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR});
</insert>
- <delete id="delete">
- DELETE FROM t_user WHERE user_id = #{userId,jdbcType=INTEGER} AND shadow = #{shadow,jdbcType=BOOLEAN};
+ <delete id="deleteOne">
+ DELETE FROM t_user WHERE user_id = #{userId,jdbcType=INTEGER} AND user_type = #{userType,jdbcType=INTEGER};
</delete>
<select id="selectAll" resultMap="baseResultMap">
- SELECT * FROM t_user;
+ SELECT * FROM t_user WHERE user_type = #{userType,jdbcType=INTEGER};
</select>
<select id="selectAllByShadow" resultMap="baseResultMap">
- SELECT * FROM t_user WHERE shadow = #{shadow,jdbcType=BOOLEAN};
+ SELECT * FROM t_user WHERE user_type = #{userType,jdbcType=INTEGER};
</select>
</mapper>
diff --git a/examples/shardingsphere-jdbc-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalShadowConfiguration.java b/examples/shardingsphere-jdbc-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalShadowConfiguration.java
index e98c748..5d802cf 100644
--- a/examples/shardingsphere-jdbc-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalShadowConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/cluster-mode-example/cluster-mode-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/cluster/mode/raw/jdbc/config/local/LocalShadowConfiguration.java
@@ -51,6 +51,6 @@ public final class LocalShadowConfiguration implements ExampleConfiguration {
}
private ShadowRuleConfiguration getShadowRuleConfiguration() {
- return new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("shadow_ds"));
+ return new ShadowRuleConfiguration();
}
}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/pom.xml
deleted file mode 100644
index 3394f29..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/pom.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?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.
- -->
-
-<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>
- <artifactId>future-shadow-example</artifactId>
- <groupId>org.apache.shardingsphere.example</groupId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>future-shadow-spring-boot-mybatis-example</artifactId>
- <name>${project.artifactId}</name>
-
- <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-boot-starter</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml
deleted file mode 100644
index ea8de7a..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?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.
- -->
-
-<!DOCTYPE configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
-<configuration>
- <mappers>
- <mapper resource="META-INF/mappers/FutureShadowUserMapper.xml"/>
- </mappers>
-</configuration>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application.properties b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application.properties
deleted file mode 100644
index 01a6cdb..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application.properties
+++ /dev/null
@@ -1,26 +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.
-#
-
-spring.profiles.active=shadow-databases
-#spring.profiles.active=shadow-readwrite-splitting
-#spring.profiles.active=shadow-sharding-databases
-#spring.profiles.active=shadow-encrypt
-
-spring.shardingsphere.props.sql-show=true
-spring.shardingsphere.props.sql-comment-parse-enabled=true
-
-mybatis.config-location=classpath:META-INF/mybatis-config.xml
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/logback.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/logback.xml
deleted file mode 100644
index 3d75f49..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<configuration>
- <property name="log.context.name" value="future-shadow-spring-boot-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>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder charset="${log.charset}">
- <pattern>${log.pattern}</pattern>
- </encoder>
- </appender>
- <logger name="org.springframework" level="WARN" />
- <logger name="com.zaxxer.hikari" level="WARN" />
- <root>
- <level value="INFO" />
- <appender-ref ref="STDOUT" />
- </root>
-</configuration>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml
deleted file mode 100644
index 8b2104c..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/pom.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?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.
- -->
-
-<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>
- <artifactId>future-shadow-example</artifactId>
- <groupId>org.apache.shardingsphere.example</groupId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>future-shadow-spring-namespace-mybatis-example</artifactId>
- <name>${project.artifactId}</name>
-
- <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 [...]
deleted file mode 100644
index 7832d51..0000000
--- 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
+++ /dev/null
@@ -1,53 +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.shadow.spring.namespace.mybatis;
-
-import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.OrderService;
-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)) {
- executeShadowService(applicationContext);
- executeOrderService(applicationContext);
- }
- }
-
- private static void executeOrderService(final ConfigurableApplicationContext applicationContext) {
- OrderService orderService = applicationContext.getBean("orderService", OrderService.class);
- orderService.executeInsertCase();
- orderService.executeDeleteCase();
- orderService.executeUpdateCase();
- }
-
- private static void executeShadowService(final ConfigurableApplicationContext applicationContext) {
- ShadowService shadowService = applicationContext.getBean("shadowService", ShadowService.class);
- shadowService.executeInsertCase();
- shadowService.executeDeleteCase();
- shadowService.executeUpdateCase();
- shadowService.executeSelectCase();
- shadowService.executeNoteCase();
- }
-}
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
deleted file mode 100644
index bb122ca..0000000
--- 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
+++ /dev/null
@@ -1,34 +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.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/OrderMapper.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/OrderMapper.java
deleted file mode 100644
index 1b9cf43..0000000
--- 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/OrderMapper.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.shadow.spring.namespace.mybatis.repository;
-
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo;
-
-import java.util.List;
-import java.util.Map;
-
-@Mapper
-public interface OrderMapper {
-
- void saveOne(OrderInfo orderInfo);
-
- void saveBatch(List<OrderInfo> orderList);
-
- void updateOne(OrderInfo orderInfo);
-
- void updateByUserIds(Map<String, Object> updateMap);
-
- void remove(OrderInfo orderInfo);
-
- void removeInUserIds(List<Integer> userIds);
-}
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
deleted file mode 100644
index d4a8087..0000000
--- 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
+++ /dev/null
@@ -1,27 +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.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/OrderService.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/OrderService.java
deleted file mode 100644
index 85976c5..0000000
--- 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/OrderService.java
+++ /dev/null
@@ -1,27 +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.shadow.spring.namespace.mybatis.service;
-
-public interface OrderService {
-
- void executeInsertCase();
-
- void executeUpdateCase();
-
- void executeDeleteCase();
-}
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/SQLGenerator.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/SQLGenerator.java
deleted file mode 100644
index c82a96b..0000000
--- 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/SQLGenerator.java
+++ /dev/null
@@ -1,163 +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.shadow.spring.namespace.mybatis.service;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * Sql generator.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SQLGenerator {
-
- /**
- * Init insert case.
- *
- * @return insert case sql
- */
- public static 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'), (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;
- }
-
- /**
- * Init update case.
- *
- * @return update case sql
- */
- public static Collection<String> initUpdateCase() {
- Collection<String> result = new LinkedList<>();
- String update_case_1 = "UPDATE t_order SET user_id = 2, content = 'update_case_1' WHERE user_id = 1 and content = 'update_case_1'";
- result.add(update_case_1);
- String update_case_2 = "UPDATE t_order SET user_id = 2, content = 'update_case_2' WHERE user_id = 2 and content = 'update_case_1'";
- result.add(update_case_2);
- String update_case_3 = "UPDATE t_order SET user_id = 2, content = 'update_case_3' WHERE user_id in (1, 1) or content = 'aa'";
- result.add(update_case_3);
- String update_case_4 = "UPDATE t_order SET user_id = 2, content = 'update_case_4' WHERE user_id in (1, 2, 3) or content BETWEEN 'aaa' AND 'bbb'";
- result.add(update_case_4);
- String update_case_5 = "UPDATE t_order SET user_id = 2, content = 'update_case_5' WHERE user_id like '1'";
- result.add(update_case_5);
- String update_case_6 = "UPDATE t_order SET user_id = 2, content = 'update_case_6' WHERE user_id not like '1'";
- result.add(update_case_6);
- String update_case_7 = "UPDATE t_order SET user_id = 2, content = 'update_case_7' WHERE user_id = 1 or user_id in (2, 3) ";
- result.add(update_case_7);
- String update_case_8 = "UPDATE t_order SET user_id = 2, content = 'update_case_8' WHERE user_id = 2 or user_id in (1, 1) ";
- result.add(update_case_8);
- String update_case_9 = "UPDATE t_order SET user_id = 2, content = 'update_case_9' WHERE user_id in (select user_id from t_order_data where user_id = 1)";
- result.add(update_case_9);
- String update_case_10 = "UPDATE t_order SET user_id = 2, content = 'update_case_10' WHERE user_id BETWEEN 0 AND 2 or content = 'aa'";
- result.add(update_case_10);
- return result;
- }
-
- /**
- * Init delete case.
- *
- * @return delete case sql
- */
- public static Collection<String> initDeleteCase() {
- Collection<String> result = new LinkedList<>();
- String delete_case_1 = "DELETE FROM t_order WHERE user_id = 1 and content = 'delete_case_1'";
- result.add(delete_case_1);
- String delete_case_2 = "DELETE FROM t_order WHERE user_id = 2 and content = 'delete_case_2'";
- result.add(delete_case_2);
- String delete_case_3 = "DELETE FROM t_order WHERE user_id in (1, 1) or content = 'aa'";
- result.add(delete_case_3);
- String delete_case_4 = "DELETE FROM t_order WHERE user_id in (1, 2, 3) or content BETWEEN 'aaa' AND 'bbb'";
- result.add(delete_case_4);
- String delete_case_5 = "DELETE FROM t_order WHERE user_id like '1'";
- result.add(delete_case_5);
- String delete_case_6 = "DELETE FROM t_order WHERE user_id not like '1'";
- result.add(delete_case_6);
- String delete_case_7 = "DELETE FROM t_order WHERE user_id = 1 or user_id in (2, 3) ";
- result.add(delete_case_7);
- String delete_case_8 = "DELETE FROM t_order WHERE user_id = 2 or user_id in (1, 1) ";
- result.add(delete_case_8);
- String delete_case_9 = "DELETE FROM t_order WHERE user_id in (select user_id from t_order_data where user_id = 1)";
- result.add(delete_case_9);
- String delete_case_10 = "DELETE FROM t_order WHERE user_id BETWEEN 0 AND 2 or content = 'aa'";
- result.add(delete_case_10);
- return result;
- }
-
- /**
- * Init select case.
- *
- * @return select case sql
- */
- public static Collection<String> initSelectCase() {
- Collection<String> result = new LinkedList<>();
- String select_case_1 = "SELECT user_id, content FROM t_order WHERE user_id = 1";
- result.add(select_case_1);
- String select_case_2 = "SELECT user_id, content FROM t_order WHERE user_id = 2";
- result.add(select_case_2);
- String select_case_3 = "SELECT user_id, content FROM t_order WHERE user_id in (1, 1)";
- result.add(select_case_3);
- String select_case_4 = "SELECT user_id, content FROM t_order WHERE user_id in (1, 2)";
- result.add(select_case_4);
- String select_case_5 = "SELECT user_id, content FROM t_order WHERE user_id BETWEEN 0 AND 2 and user_id = 1";
- result.add(select_case_5);
- String select_case_6 = "SELECT user_id, content FROM t_order WHERE user_id BETWEEN 0 AND 2";
- result.add(select_case_6);
- String select_case_7 = "SELECT tor1.user_id as user_id, tor2.user_id as new_user_id, tor1.content as content FROM t_order as tor1 left join t_order as tor2 on tor1.id = tor2.id " +
- "left join t_order as tor3 on tor1.id = tor3.id where tor1.user_id = 1 and tor2.content = 'insert_case_2'";
- result.add(select_case_7);
- String select_case_8 = "SELECT t_order.user_id as user_id, tor1.user_id as new_user_id, t_order.content as content FROM t_order left join t_order as tor1 on t_order.id = tor1.id " +
- "left join t_order as tor2 on t_order.id = tor2.id where t_order.user_id = 1 and tor1.content = 'insert_case_2'";
- result.add(select_case_8);
- String select_case_9 = "SELECT t_order.user_id as user_id, tor1.user_id as new_user_id, tor2.content as content FROM t_order left join t_order as tor1 on t_order.id = tor1.id " +
- "left join (select * from t_order_data) as tor2 on t_order.id = tor2.id where t_order.user_id = 1 and tor1.content = 'insert_case_2'";
- result.add(select_case_9);
- String select_case_10 = "SELECT tor1.user_id as user_id, tor2.user_id as new_user_id, tor1.content as content FROM t_order as tor1 left join t_order as tor2 on tor1.id = tor2.id " +
- "left join t_order_data as tor3 on tor1.id = tor3.id where tor3.user_id = 2 and tor2.content = 'insert_case_2'";
- result.add(select_case_10);
- String select_case_11 = "SELECT user_id, content FROM t_order WHERE user_id like '1'";
- result.add(select_case_11);
- String select_case_12 = "SELECT user_id, content FROM t_order WHERE user_id not like '1'";
- result.add(select_case_12);
- String select_case_13 = "SELECT max(id) as max_id, user_id FROM t_order WHERE user_id = 1 group by user_id having max_id = 2";
- result.add(select_case_13);
- String select_case_14 = "SELECT max(id) as max_id, user_id FROM t_order WHERE user_id = 2 group by user_id having max_id = 1";
- result.add(select_case_14);
- String select_case_15 = "SELECT tor0.user_id as user_id_0, tor1.user_id as user_id_1, tor2.user_id as user_id_2 FROM t_order as tor0 left join t_order_data as tor1 on tor0.id = tor1.id " +
- "left join (select * from t_order_data) as tor2 on tor0.id = tor2.id where tor0.user_id = 1 and tor1.user_id in (1,1) and tor1.content = 'insert_case_2'";
- result.add(select_case_15);
- return result;
- }
-
- public static Collection<String> initNoteCase() {
- Collection<String> result = new LinkedList<>();
- String note_case_1 = "create table t_user(id int(11) not null , user_name varchar(32) not null ) /*shadow:true,foo:bar,aaa:ddd*/";
- result.add(note_case_1);
- String note_case_2 = "INSERT INTO t_order (user_id, content) VALUES (1, 'note_case_1') /*shadow:true,foo:bar,aaa:ddd*/";
- result.add(note_case_2);
- return result;
- }
-}
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
deleted file mode 100644
index 811e448..0000000
--- 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
+++ /dev/null
@@ -1,31 +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.shadow.spring.namespace.mybatis.service;
-
-public interface ShadowService {
-
- void executeInsertCase();
-
- void executeUpdateCase();
-
- void executeDeleteCase();
-
- void executeSelectCase();
-
- void executeNoteCase();
-}
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/OrderServiceImpl.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/OrderServiceImpl.java
deleted file mode 100644
index 7c27d04..0000000
--- 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/OrderServiceImpl.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.shadow.spring.namespace.mybatis.service.impl;
-
-import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo;
-import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.repository.OrderMapper;
-import org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.OrderService;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-@Service(value = "orderService")
-public final class OrderServiceImpl implements OrderService {
-
- @Resource
- private OrderMapper orderMapper;
-
- @Override
- public void executeInsertCase() {
- executeOneInsertCase();
- executeBatchInsertCase();
- }
-
- private void executeBatchInsertCase() {
- List<OrderInfo> orders = new ArrayList<>();
- OrderInfo orderInfo1 = new OrderInfo();
- orderInfo1.setUserId(1);
- orderInfo1.setContent("insert_case_2");
- orders.add(orderInfo1);
- OrderInfo orderInfo2 = new OrderInfo();
- orderInfo2.setUserId(2);
- orderInfo2.setContent("insert_case_2");
- orders.add(orderInfo2);
- OrderInfo orderInfo3 = new OrderInfo();
- orderInfo3.setUserId(1);
- orderInfo3.setContent("insert_case_2");
- orders.add(orderInfo3);
- orderMapper.saveBatch(orders);
- }
-
- private void executeOneInsertCase() {
- OrderInfo orderInfo = new OrderInfo();
- orderInfo.setUserId(1);
- orderInfo.setContent("insert_case_1");
- orderMapper.saveOne(orderInfo);
- }
-
- @Override
- public void executeUpdateCase() {
- executeOneUpdateCase();
- executeInUpdateCase();
- }
-
- private void executeInUpdateCase() {
- Map<String, Object> updateMap = new LinkedHashMap<>();
- List<Integer> userIds = new LinkedList<>();
- userIds.add(1);
- userIds.add(2);
- updateMap.put("userIds",userIds);
- updateMap.put("content","update_case_2");
- orderMapper.updateByUserIds(updateMap);
-
- }
-
- private void executeOneUpdateCase() {
- OrderInfo orderInfo = new OrderInfo();
- orderInfo.setUserId(1);
- orderInfo.setContent("update_case_1");
- orderMapper.updateOne(orderInfo);
- }
-
- @Override
- public void executeDeleteCase() {
- executeRemoveOneCase();
- executeRemoveInCase();
- }
-
- private void executeRemoveInCase() {
- List<Integer> userIds = new LinkedList<>();
- userIds.add(1);
- userIds.add(1);
- userIds.add(1);
- orderMapper.removeInUserIds(userIds);
- }
-
- private void executeRemoveOneCase() {
- OrderInfo orderInfo = new OrderInfo();
- orderInfo.setUserId(1);
- orderMapper.remove(orderInfo);
- }
-}
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 [...]
deleted file mode 100644
index 7e23a43..0000000
--- 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
+++ /dev/null
@@ -1,61 +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.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.apache.shardingsphere.example.shadow.spring.namespace.mybatis.service.SQLGenerator;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-
-@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() {
- SQLGenerator.initInsertCase().forEach(this::execute);
- }
-
- @Override
- public void executeUpdateCase() {
- SQLGenerator.initUpdateCase().forEach(this::execute);
- }
-
- @Override
- public void executeDeleteCase() {
- SQLGenerator.initDeleteCase().forEach(this::execute);
- }
-
- @Override
- public void executeSelectCase() {
- SQLGenerator.initSelectCase().forEach(this::execute);
- }
-
- @Override
- public void executeNoteCase() {
- SQLGenerator.initNoteCase().forEach(this::execute);
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml
deleted file mode 100644
index 2183cc1..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/OrderMapper.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?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.
- -->
-
-<!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.OrderMapper">
- <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="saveOne" parameterType="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo">
- insert into t_order(user_id, content) values (#{userId}, #{content})
- </insert>
-
- <insert id="saveBatch" parameterType="java.util.List">
- insert into t_order(user_id, content) values
- <foreach collection="list" item="order" separator=",">
- (#{order.userId}, #{order.content})
- </foreach>
- </insert>
-
- <update id="updateOne" parameterType="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo">
- update t_order
- <set>
- <if test="content != null">content=#{content}</if>
- </set>
- where user_id = #{userId}
- </update>
-
- <update id="updateByUserIds" parameterType="java.util.Map">
- update t_order
- <set>
- <if test="content != null">content=#{content}</if>
- </set>
- where user_id in
- <foreach collection="userIds" item="userId" separator="," open="(" close=")">
- #{userId}
- </foreach>
- </update>
-
- <delete id="remove" parameterType="org.apache.shardingsphere.example.shadow.spring.namespace.mybatis.domain.OrderInfo">
- DELETE FROM t_order WHERE user_id = #{userId}
- </delete>
-
- <delete id="removeInUserIds" parameterType="java.util.List">
- DELETE FROM t_order WHERE user_id in
- <foreach collection="list" item="userId" separator="," open="(" close=")">
- #{userId}
- </foreach>
- </delete>
-</mapper>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/ShadowMapper.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
deleted file mode 100644
index 3d9580b..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/mappers/ShadowMapper.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?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.
- -->
-
-<!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">
- <insert id="execute" parameterType="java.lang.String">
- ${sql}
- </insert>
-</mapper>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml
deleted file mode 100644
index d07a6433..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-namespace-mybatis-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<configuration>
- <property name="log.context.name" value="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>
-
- <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/future-shadow-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/pom.xml
deleted file mode 100644
index 9414ad3..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?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.
- -->
-
-<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>other-feature-example</artifactId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>future-shadow-example</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <modules>
- <module>future-shadow-spring-namespace-mybatis-example</module>
- <module>future-shadow-spring-boot-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 03663ea..f48464d 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/pom.xml
@@ -33,6 +33,5 @@
<module>encrypt-example</module>
<module>hint-example</module>
<module>shadow-example</module>
- <module>future-shadow-example</module>
</modules>
</project>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/pom.xml
index 17566bf..e5d04f9 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/pom.xml
@@ -28,10 +28,9 @@
<artifactId>shadow-example</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
-
+
<modules>
- <module>shadow-raw-jdbc-example</module>
- <module>shadow-spring-boot-mybatis-example</module>
<module>shadow-spring-namespace-mybatis-example</module>
+ <module>shadow-spring-boot-mybatis-example</module>
</modules>
</project>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/pom.xml
deleted file mode 100644
index 98ea985..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/pom.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?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.
- -->
-
-<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>shadow-example</artifactId>
- <version>5.0.0-RC1-SNAPSHOT</version>
- </parent>
- <artifactId>shadow-raw-jdbc-example</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>example-raw-jdbc</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-jdbc-core</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawJavaConfigurationExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawJavaConfigurationExample.java
deleted file mode 100644
index d9b1ed3..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawJavaConfigurationExample.java
+++ /dev/null
@@ -1,49 +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.
- */
-
-/*
- * Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica.
- */
-
-package org.apache.shardingsphere.example.shadow.table.raw.jdbc;
-
-import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
-import org.apache.shardingsphere.example.core.api.service.ExampleService;
-import org.apache.shardingsphere.example.core.jdbc.repository.ShadowUserRepositoryImpl;
-import org.apache.shardingsphere.example.core.jdbc.service.ShadowUserServiceImpl;
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.factory.DataSourceFactory;
-import org.apache.shardingsphere.example.type.ShardingType;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-
-public final class ShadowRawJavaConfigurationExample {
-
- private static ShardingType shardingType = ShardingType.SHADOW;
-// private static ShardingType shardingType = ShardingType.READWRITE_SPLITTING_SHADOW;
-// private static ShardingType shardingType = ShardingType.ENCRYPT_SHADOW;
-// private static ShardingType shardingType = ShardingType.SHARDING_SHADOW_DATABASES;
-
- public static void main(final String[] args) throws SQLException {
- DataSource dataSource = DataSourceFactory.newInstance(shardingType);
- ExampleExecuteTemplate.run(getExampleService(dataSource));
- }
-
- private static ExampleService getExampleService(final DataSource dataSource) {
- return new ShadowUserServiceImpl(new ShadowUserRepositoryImpl(dataSource));
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawYamlConfigurationExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawYamlConfigurationExample.java
deleted file mode 100644
index e373817..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/ShadowRawYamlConfigurationExample.java
+++ /dev/null
@@ -1,46 +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.shadow.table.raw.jdbc;
-
-import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
-import org.apache.shardingsphere.example.core.api.service.ExampleService;
-import org.apache.shardingsphere.example.core.jdbc.repository.ShadowUserRepositoryImpl;
-import org.apache.shardingsphere.example.core.jdbc.service.ShadowUserServiceImpl;
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.factory.YamlDataSourceFactory;
-import org.apache.shardingsphere.example.type.ShardingType;
-
-import javax.sql.DataSource;
-import java.io.IOException;
-import java.sql.SQLException;
-
-public final class ShadowRawYamlConfigurationExample {
-
- private static ShardingType shardingType = ShardingType.SHADOW;
-// private static ShardingType shardingType = ShardingType.READWRITE_SPLITTING_SHADOW;
-// private static ShardingType shardingType = ShardingType.ENCRYPT_SHADOW;
-// private static ShardingType shardingType = ShardingType.SHARDING_SHADOW_DATABASES;
-
- public static void main(final String[] args) throws SQLException, IOException {
- DataSource dataSource = YamlDataSourceFactory.newInstance(shardingType);
- ExampleExecuteTemplate.run(getExampleService(dataSource));
- }
-
- private static ExampleService getExampleService(final DataSource dataSource) {
- return new ShadowUserServiceImpl(new ShadowUserRepositoryImpl(dataSource));
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java
deleted file mode 100644
index 01d35cd..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java
+++ /dev/null
@@ -1,72 +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.shadow.table.raw.jdbc.config;
-
-import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.example.config.ExampleConfiguration;
-import org.apache.shardingsphere.example.core.api.DataSourceUtil;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-
-public final class EncryptShadowDatabasesConfiguration implements ExampleConfiguration {
-
- @Override
- public DataSource getDataSource() throws SQLException {
- Map<String, DataSource> dataSourceMap = new HashMap<>(2, 1);
- dataSourceMap.put("ds", DataSourceUtil.createDataSource("demo_ds"));
- dataSourceMap.put("ds_0", DataSourceUtil.createDataSource("shadow_demo_ds"));
- EncryptRuleConfiguration encryptRuleConfig = new EncryptRuleConfiguration(getEncryptTableRuleConfigurations(), getEncryptAlgorithmConfigurations());
- Properties props = new Properties();
- props.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true");
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("ds_0"));
- return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Arrays.asList(shadowRuleConfig, encryptRuleConfig), props);
- }
-
- private Collection<EncryptTableRuleConfiguration> getEncryptTableRuleConfigurations() {
- Collection<EncryptTableRuleConfiguration> result = new LinkedList<>();
- Collection<EncryptColumnRuleConfiguration> columns = new LinkedList<>();
- columns.add(new EncryptColumnRuleConfiguration("user_name", "user_name", "", "user_name_plain", "name_encryptor"));
- columns.add(new EncryptColumnRuleConfiguration("pwd", "pwd", "assisted_query_pwd", "", "pwd_encryptor"));
- result.add(new EncryptTableRuleConfiguration("t_user", columns));
- return result;
- }
-
- private Map<String, ShardingSphereAlgorithmConfiguration> getEncryptAlgorithmConfigurations() {
- Map<String, ShardingSphereAlgorithmConfiguration> result = new LinkedHashMap<>(2, 1);
- Properties props = new Properties();
- props.setProperty("aes-key-value", "123456");
- result.put("name_encryptor", new ShardingSphereAlgorithmConfiguration("AES", props));
- result.put("pwd_encryptor", new ShardingSphereAlgorithmConfiguration("assistedTest", null));
- return result;
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ReadwriteSplittingShadowDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ReadwriteSplittingShadowDatabasesConfiguration.java
deleted file mode 100644
index 2e0a264..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ReadwriteSplittingShadowDatabasesConfiguration.java
+++ /dev/null
@@ -1,51 +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.shadow.table.raw.jdbc.config;
-
-import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.example.config.ExampleConfiguration;
-import org.apache.shardingsphere.example.core.api.DataSourceUtil;
-import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class ReadwriteSplittingShadowDatabasesConfiguration implements ExampleConfiguration {
-
- @Override
- public DataSource getDataSource() throws SQLException {
- Map<String, DataSource> dataSourceMap = new HashMap<>(4, 1);
- dataSourceMap.put("write_ds", DataSourceUtil.createDataSource("demo_write_ds"));
- dataSourceMap.put("read_ds", DataSourceUtil.createDataSource("demo_read_ds"));
- dataSourceMap.put("shadow_write_ds", DataSourceUtil.createDataSource("demo_shadow_write_ds"));
- dataSourceMap.put("shadow_read_ds", DataSourceUtil.createDataSource("demo_shadow_read_ds"));
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Arrays.asList("write_ds", "read_ds"), Arrays.asList("shadow_write_ds", "shadow_read_ds"));
- return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Arrays.asList(shadowRuleConfig, getReadwriteSplittingRuleConfiguration()), null);
- }
-
- private ReadwriteSplittingRuleConfiguration getReadwriteSplittingRuleConfiguration() {
- ReadwriteSplittingDataSourceRuleConfiguration config = new ReadwriteSplittingDataSourceRuleConfiguration("pr_ds", "", "write_ds", Collections.singletonList("read_ds"), null, false);
- return new ReadwriteSplittingRuleConfiguration(Collections.singletonList(config), Collections.emptyMap());
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShadowDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShadowDatabasesConfiguration.java
deleted file mode 100644
index 13ebaf8..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShadowDatabasesConfiguration.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.shadow.table.raw.jdbc.config;
-
-import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.example.config.ExampleConfiguration;
-import org.apache.shardingsphere.example.core.api.DataSourceUtil;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class ShadowDatabasesConfiguration implements ExampleConfiguration {
-
- @Override
- public DataSource getDataSource() throws SQLException {
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("ds_0"));
- Map<String, DataSource> dataSourceMap = new HashMap<>(2, 1);
- dataSourceMap.put("ds", DataSourceUtil.createDataSource("demo_ds"));
- dataSourceMap.put("ds_0", DataSourceUtil.createDataSource("shadow_demo_ds"));
- return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Collections.singleton(shadowRuleConfig), null);
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShardingShadowDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShardingShadowDatabasesConfiguration.java
deleted file mode 100644
index 96f2bd9..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/ShardingShadowDatabasesConfiguration.java
+++ /dev/null
@@ -1,78 +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.shadow.table.raw.jdbc.config;
-
-import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.example.config.ExampleConfiguration;
-import org.apache.shardingsphere.example.core.api.DataSourceUtil;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-public final class ShardingShadowDatabasesConfiguration implements ExampleConfiguration {
-
- @Override
- public DataSource getDataSource() throws SQLException {
- Map<String, DataSource> dataSourceMap = new HashMap<>(4, 1);
- dataSourceMap.put("ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
- dataSourceMap.put("ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
- dataSourceMap.put("shadow_ds_0", DataSourceUtil.createDataSource("shadow_demo_ds_0"));
- dataSourceMap.put("shadow_ds_1", DataSourceUtil.createDataSource("shadow_demo_ds_1"));
- ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
- shardingRuleConfig.getTables().add(getUserTableConfiguration());
- Properties props = new Properties();
- props.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms() .put("database_inline", new ShardingSphereAlgorithmConfiguration("INLINE", props));
- props = new Properties();
- props.setProperty("algorithm-expression", "t_user");
- shardingRuleConfig.getShardingAlgorithms() .put("table_inline", new ShardingSphereAlgorithmConfiguration("INLINE", props));
- props.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true");
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Arrays.asList("ds_0", "ds_1"), Arrays.asList("shadow_ds_0", "shadow_ds_1"));
- return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Arrays.asList(shadowRuleConfig, shardingRuleConfig), props);
- }
-
- private ShardingTableRuleConfiguration getUserTableConfiguration() {
- ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_user", "ds_${0..1}.t_user");
- result.setTableShardingStrategy(getTableStandardShardingStrategyConfiguration());
- result.setDatabaseShardingStrategy(getDatabaseStandardShardingStrategyConfiguration());
- return result;
- }
-
- private StandardShardingStrategyConfiguration getTableStandardShardingStrategyConfiguration() {
- InlineShardingAlgorithm inlineShardingAlgorithm = new InlineShardingAlgorithm();
- inlineShardingAlgorithm.getProps().setProperty("algorithm-expression", "t_user");
- return new StandardShardingStrategyConfiguration("user_id", "table_inline");
- }
-
- private StandardShardingStrategyConfiguration getDatabaseStandardShardingStrategyConfiguration() {
- InlineShardingAlgorithm inlineShardingAlgorithm = new InlineShardingAlgorithm();
- inlineShardingAlgorithm.getProps().setProperty("algorithm-expression", "ds_${user_id % 2}");
- return new StandardShardingStrategyConfiguration("user_id", "database_inline");
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/DataSourceFactory.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/DataSourceFactory.java
deleted file mode 100644
index 6951a1e..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/DataSourceFactory.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.shadow.table.raw.jdbc.factory;
-
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.config.EncryptShadowDatabasesConfiguration;
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.config.ReadwriteSplittingShadowDatabasesConfiguration;
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.config.ShadowDatabasesConfiguration;
-import org.apache.shardingsphere.example.shadow.table.raw.jdbc.config.ShardingShadowDatabasesConfiguration;
-import org.apache.shardingsphere.example.type.ShardingType;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-
-public final class DataSourceFactory {
-
- public static DataSource newInstance(final ShardingType shardingType) throws SQLException {
- switch (shardingType) {
- case SHADOW:
- return new ShadowDatabasesConfiguration().getDataSource();
- case SHARDING_SHADOW_DATABASES:
- return new ShardingShadowDatabasesConfiguration().getDataSource();
- case ENCRYPT_SHADOW:
- return new EncryptShadowDatabasesConfiguration().getDataSource();
- case READWRITE_SPLITTING_SHADOW:
- return new ReadwriteSplittingShadowDatabasesConfiguration().getDataSource();
- default:
- throw new UnsupportedOperationException(shardingType.name());
- }
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/YamlDataSourceFactory.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/YamlDataSourceFactory.java
deleted file mode 100644
index 128e78f..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/factory/YamlDataSourceFactory.java
+++ /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.
- */
-
-package org.apache.shardingsphere.example.shadow.table.raw.jdbc.factory;
-
-import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.example.type.ShardingType;
-
-import javax.sql.DataSource;
-import java.io.File;
-import java.io.IOException;
-import java.sql.SQLException;
-
-public final class YamlDataSourceFactory {
-
- public static DataSource newInstance(final ShardingType shardingType) throws SQLException, IOException {
- switch (shardingType) {
- case SHARDING_SHADOW_DATABASES:
- return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/sharding-shadow-databases.yaml"));
- case SHADOW:
- return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/shadow-databases.yaml"));
- case ENCRYPT_SHADOW:
- return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/encrypt-shadow-databases.yaml"));
- case READWRITE_SPLITTING_SHADOW:
- return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/readwrite-splitting-shadow-databases.yaml"));
- default:
- throw new UnsupportedOperationException(shardingType.name());
- }
- }
-
- private static File getFile(final String fileName) {
- return new File(YamlDataSourceFactory.class.getResource(fileName).getFile());
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/encrypt-shadow-databases.yaml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/encrypt-shadow-databases.yaml
deleted file mode 100644
index a8f9e96..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/encrypt-shadow-databases.yaml
+++ /dev/null
@@ -1,61 +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.
-#
-
-dataSources:
- ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
-
-rules:
-- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - ds
- shadowDataSourceNames:
- - ds_0
-
-- !ENCRYPT
- tables:
- t_user:
- columns:
- user_name:
- plainColumn: user_name_plain
- cipherColumn: user_name
- encryptorName: name_encryptor
- pwd:
- cipherColumn: pwd
- assistedQueryColumn: assisted_query_pwd
- encryptorName: pwd_encryptor
- encryptors:
- name_encryptor:
- type: AES
- props:
- aes-key-value: 123456abc
- pwd_encryptor:
- type: assistedTest
-
-props:
- sql-show: true
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/readwrite-splitting-shadow-databases.yaml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/readwrite-splitting-shadow-databases.yaml
deleted file mode 100644
index 8a89047..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/readwrite-splitting-shadow-databases.yaml
+++ /dev/null
@@ -1,61 +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.
-#
-
-dataSources:
- write_ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- read_ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- shadow_write_ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_shadow_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- shadow_read_ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_shadow_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
-
-rules:
-- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - write_ds
- - read_ds
- shadowDataSourceNames:
- - shadow_write_ds
- - shadow_read_ds
-
-- !READWRITE_SPLITTING
- dataSources:
- pr_ds:
- writeDataSourceName: write_ds
- readDataSourceNames: [read_ds]
-
-props:
- sql-show: true
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/shadow-databases.yaml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/shadow-databases.yaml
deleted file mode 100644
index e326f9a..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/shadow-databases.yaml
+++ /dev/null
@@ -1,38 +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.
-#
-
-dataSources:
- ds:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
-
-rules:
-- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - ds
- shadowDataSourceNames:
- - ds_0
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/sharding-shadow-databases.yaml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/sharding-shadow-databases.yaml
deleted file mode 100644
index c11e09e..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/META-INF/sharding-shadow-databases.yaml
+++ /dev/null
@@ -1,81 +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.
-#
-
-dataSources:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- shadow_ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/shadow_demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
- shadow_ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/shadow_demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
-
-rules:
-- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - ds_0
- - ds_1
- shadowDataSourceNames:
- - shadow_ds_0
- - shadow_ds_1
-- !SHARDING
- tables:
- t_user:
- actualDataNodes: ds_${0..1}.t_user
- databaseStrategy:
- standard:
- shardingColumn: user_id
- shardingAlgorithmName: database_inline
- tableStrategy:
- standard:
- shardingColumn: user_id
- shardingAlgorithmName: table_inline
- defaultDatabaseStrategy:
- none:
- defaultTableStrategy:
- none:
-
- shardingAlgorithms:
- database_inline:
- type: INLINE
- props:
- algorithm-expression: ds_${user_id % 2}
- table_inline:
- type: INLINE
- props:
- algorithm-expression: t_user
-
-props:
- sql-show: true
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/logback.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/logback.xml
deleted file mode 100644
index 3d24ca1..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<configuration>
- <property name="log.context.name" value="shadow-raw-jdbc-example" />
- <property name="log.charset" value="UTF-8" />
- <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
- <contextName>${log.context.name}</contextName>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder charset="${log.charset}">
- <pattern>${log.pattern}</pattern>
- </encoder>
- </appender>
- <root>
- <level value="INFO" />
- <appender-ref ref="STDOUT" />
- </root>
-</configuration>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/pom.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/pom.xml
index b7c227f..c21be5f 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/pom.xml
@@ -27,7 +27,7 @@
</parent>
<artifactId>shadow-spring-boot-mybatis-example</artifactId>
<name>${project.artifactId}</name>
-
+
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere.example</groupId>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
similarity index 97%
rename from examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
index 34b7903..3bbbb27 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
@@ -35,7 +35,7 @@ public class ShadowSpringBootMybatisExample {
public static void main(final String[] args) throws SQLException {
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ShadowSpringBootMybatisExample.class, args)) {
- ExampleExecuteTemplate.run(applicationContext.getBean("futureShadow", ExampleService.class));
+ ExampleExecuteTemplate.run(applicationContext.getBean("shadow", ExampleService.class));
}
}
}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/boot/mybatis/ShadowSpringBootMybatisExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/boot/mybatis/ShadowSpringBootMybatisExample.java
deleted file mode 100644
index 2207b8a..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/boot/mybatis/ShadowSpringBootMybatisExample.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.shadow.table.spring.boot.mybatis;
-
-import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
-import org.apache.shardingsphere.example.core.api.service.ExampleService;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.ComponentScan;
-
-import java.sql.SQLException;
-
-@ComponentScan("org.apache.shardingsphere.example.core.mybatis")
-@MapperScan(basePackages = "org.apache.shardingsphere.example.core.mybatis.repository")
-@SpringBootApplication(exclude = JtaAutoConfiguration.class)
-public class ShadowSpringBootMybatisExample {
-
- public static void main(final String[] args) throws SQLException {
- try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ShadowSpringBootMybatisExample.class, args)) {
- ExampleExecuteTemplate.run(applicationContext.getBean("shadow", ExampleService.class));
- }
- }
-}
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml
index fa18441..7c150d7 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/META-INF/mybatis-config.xml
@@ -21,10 +21,6 @@
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<mappers>
- <mapper resource="META-INF/mappers/AddressMapper.xml"/>
- <mapper resource="META-INF/mappers/OrderMapper.xml"/>
- <mapper resource="META-INF/mappers/OrderItemMapper.xml"/>
- <mapper resource="META-INF/mappers/UserMapper.xml"/>
<mapper resource="META-INF/mappers/ShadowUserMapper.xml"/>
</mappers>
</configuration>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-encrypt-shadow-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-encrypt-shadow-databases.properties
deleted file mode 100644
index 6f55477..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-encrypt-shadow-databases.properties
+++ /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.
-#
-
-spring.shardingsphere.datasource.names=ds,shadow-ds
-
-spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.ds.username=root
-spring.shardingsphere.datasource.ds.password=
-
-spring.shardingsphere.datasource.shadow-ds.jdbc-url=jdbc:mysql://localhost:3306/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-ds.username=root
-spring.shardingsphere.datasource.shadow-ds.password=
-
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds
-
-spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.type=AES
-spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.props.aes-key-value=123456
-spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.type=assistedTest
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.user_name.cipher-column=user_name
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.user_name.plain-column=user_name_plain
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.user_name.encryptor-name=name-encryptor
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.cipher-column=pwd
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.assisted-query-column=assisted_query_pwd
-spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.encryptor-name=pwd-encryptor
-
-spring.shardingsphere.props.query.with.cipher.comlum=true
-spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-readwrite-splitting-shadow-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-readwrite-splitting-shadow-databases.properties
deleted file mode 100644
index 685cf0c..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-readwrite-splitting-shadow-databases.properties
+++ /dev/null
@@ -1,51 +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.
-#
-
-spring.shardingsphere.datasource.names=write-ds,read-ds,shadow-write-ds,shadow-read-ds
-
-spring.shardingsphere.datasource.write-ds.jdbc-url=jdbc:mysql://localhost:3306/demo_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.write-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.write-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.write-ds.username=root
-spring.shardingsphere.datasource.write-ds.password=
-
-spring.shardingsphere.datasource.shadow-write-ds.jdbc-url=jdbc:mysql://localhost:3306/demo_shadow_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-write-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-write-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-write-ds.username=root
-spring.shardingsphere.datasource.shadow-write-ds.password=
-
-spring.shardingsphere.datasource.read-ds.jdbc-url=jdbc:mysql://localhost:3306/demo_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.read-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.read-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.read-ds.username=root
-spring.shardingsphere.datasource.read-ds.password=
-
-spring.shardingsphere.datasource.shadow-read-ds.jdbc-url=jdbc:mysql://localhost:3306/demo_shadow_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-read-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-read-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-read-ds.username=root
-spring.shardingsphere.datasource.shadow-read-ds.password=
-
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=write-ds,read-ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-write-ds,shadow-read-ds
-
-spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
-spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=write-ds
-spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=read-ds
-spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.load-balancer-name=round_robin
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties
deleted file mode 100644
index 8147240..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties
+++ /dev/null
@@ -1,34 +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.
-#
-
-spring.shardingsphere.datasource.names=ds,shadow-ds
-
-spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.ds.username=root
-spring.shardingsphere.datasource.ds.password=
-
-spring.shardingsphere.datasource.shadow-ds.jdbc-url=jdbc:mysql://localhost:3306/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-ds.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-ds.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-ds.username=root
-spring.shardingsphere.datasource.shadow-ds.password=
-
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties
similarity index 94%
rename from examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties
index d03cf8e..4af3d7d 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-encrypt.properties
@@ -41,15 +41,11 @@ spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.cipher-colu
spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.assisted-query-column=assisted_query_pwd
spring.shardingsphere.rules.encrypt.tables.t_shadow_user.columns.pwd.encryptor-name=pwd-encryptor
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds
-
spring.shardingsphere.rules.shadow.enable=true
-spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.source-data-source-name=ds
-spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.shadow-data-source-name=shadow-ds
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.source-data-source-name=ds
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.shadow-data-source-name=shadow-ds
-spring.shardingsphere.rules.shadow.tables.t_user.data-source-names=shadow-data-source-0
+spring.shardingsphere.rules.shadow.tables.t_user.data-source-names=shadow-data-source
spring.shardingsphere.rules.shadow.tables.t_user.shadow-algorithm-names=user-id-insert-match-algorithm,user-id-delete-match-algorithm,user-id-select-match-algorithm,simple-note-algorithm
spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-match-algorithm.type=COLUMN_REGEX_MATCH
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
similarity index 100%
rename from examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties
similarity index 96%
rename from examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties
index 664d5de..c36dd3d 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-sharding-databases.properties
@@ -49,10 +49,6 @@ spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=ds-$->{0..1
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id % 2}
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds-0,ds-1
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds-0,shadow-ds-1
-
spring.shardingsphere.rules.shadow.enable=true
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.source-data-source-name=ds-0
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.shadow-data-source-name=shadow-ds-0
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow.properties
similarity index 88%
rename from examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow.properties
index 6d8fd03..f5a583e 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/future-shadow-example/future-shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-databases.properties
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow.properties
@@ -17,27 +17,23 @@
spring.shardingsphere.datasource.names=ds,shadow-ds
-spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds.username=root
spring.shardingsphere.datasource.ds.password=
-spring.shardingsphere.datasource.shadow-ds.jdbc-url=jdbc:mysql://localhost:3306/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.shadow-ds.jdbc-url=jdbc:mysql://localhost:3306/ds_shadow?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.shadow-ds.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.shadow-ds.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.shadow-ds.username=root
spring.shardingsphere.datasource.shadow-ds.password=
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds
-
spring.shardingsphere.rules.shadow.enable=true
-spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.source-data-source-name=ds
-spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.shadow-data-source-name=shadow-ds
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.source-data-source-name=ds
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.shadow-data-source-name=shadow-ds
-spring.shardingsphere.rules.shadow.tables.t_user.data-source-names=shadow-data-source-0
+spring.shardingsphere.rules.shadow.tables.t_user.data-source-names=shadow-data-source
spring.shardingsphere.rules.shadow.tables.t_user.shadow-algorithm-names=user-id-insert-match-algorithm,user-id-delete-match-algorithm,user-id-select-match-algorithm,simple-note-algorithm
spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-match-algorithm.type=COLUMN_REGEX_MATCH
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-sharding-shadow-databases.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-sharding-shadow-databases.properties
deleted file mode 100644
index 6ce2e5e..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-sharding-shadow-databases.properties
+++ /dev/null
@@ -1,60 +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.
-#
-
-spring.shardingsphere.datasource.names=ds-0,ds-1,shadow-ds-0,shadow-ds-1
-
-spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.ds-0.username=root
-spring.shardingsphere.datasource.ds-0.password=
-
-spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.ds-1.username=root
-spring.shardingsphere.datasource.ds-1.password=
-
-spring.shardingsphere.datasource.shadow-ds-0.jdbc-url=jdbc:mysql://localhost:3306/shadow_demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-ds-0.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-ds-0.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-ds-0.username=root
-spring.shardingsphere.datasource.shadow-ds-0.password=
-
-spring.shardingsphere.datasource.shadow-ds-1.jdbc-url=jdbc:mysql://localhost:3306/shadow_demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
-spring.shardingsphere.datasource.shadow-ds-1.type=com.zaxxer.hikari.HikariDataSource
-spring.shardingsphere.datasource.shadow-ds-1.driver-class-name=com.mysql.jdbc.Driver
-spring.shardingsphere.datasource.shadow-ds-1.username=root
-spring.shardingsphere.datasource.shadow-ds-1.password=
-
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds-0,ds-1
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow-ds-0,shadow-ds-1
-
-spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
-spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
-
-spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=ds-$->{0..1}.t_user
-
-spring.shardingsphere.rules.sharding.tables.t_user.key-generate-strategy.column=user_id
-spring.shardingsphere.rules.sharding.tables.t_user.key-generate-strategy.key-generator-name=snowflake
-
-spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
-spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id % 2}
-
-spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
-spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application.properties b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application.properties
index 177e9af..50e5973 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application.properties
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application.properties
@@ -15,9 +15,12 @@
# limitations under the License.
#
-mybatis.config-location=classpath:META-INF/mybatis-config.xml
+spring.profiles.active=shadow
+#spring.profiles.active=shadow-readwrite-splitting
+#spring.profiles.active=shadow-sharding-databases
+#spring.profiles.active=shadow-encrypt
+
+spring.shardingsphere.props.sql-show=true
+spring.shardingsphere.props.sql-comment-parse-enabled=true
-spring.profiles.active=shadow-databases
-#spring.profiles.active=readwrite-splitting-shadow-databases
-#spring.profiles.active=sharding-shadow-databases
-#spring.profiles.active=encrypt-shadow-databases
+mybatis.config-location=classpath:META-INF/mybatis-config.xml
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
similarity index 88%
rename from examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
index 6b982f6..f54157b 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/table/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/shadow/spring/namespace/mybatis/ShadowSpringNamespaceMybatisExample.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.example.shadow.table.spring.namespace.mybatis;
+package org.apache.shardingsphere.example.shadow.spring.namespace.mybatis;
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
import org.apache.shardingsphere.example.core.api.service.ExampleService;
@@ -26,10 +26,10 @@ import java.sql.SQLException;
public final class ShadowSpringNamespaceMybatisExample {
- private static final String CONFIG_FILE = "META-INF/application-shadow-databases.xml";
-// private static final String CONFIG_FILE = "META-INF/application-sharding-shadow-databases.xml";
-// private static final String CONFIG_FILE = "META-INF/application-readwrite-splitting-shadow-databases.xml";
-// private static final String CONFIG_FILE = "META-INF/application-encrypt-shadow-databases.xml";
+ private static final String CONFIG_FILE = "META-INF/application-shadow.xml";
+// private static final String CONFIG_FILE = "META-INF/application-shadow-encrypt.xml";
+// private static final String CONFIG_FILE = "META-INF/application-shadow-readwrite-splitting.xml";
+// private static final String CONFIG_FILE = "META-INF/application-shadow-sharding-databases.xml";
public static void main(final String[] args) throws SQLException {
try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_FILE)) {
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml
deleted file mode 100644
index a42a47f..0000000
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-databases.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<?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.core.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/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
- <property name="username" value="root"/>
- <property name="password" value=""/>
- </bean>
-
- <bean id="shadow_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/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
- <property name="username" value="root"/>
- <property name="password" value=""/>
- </bean>
-
- <shadow:rule id="shadowRule" column="shadow" sourceDataSourceNames="ds" shadowDataSourceNames="shadow_ds"/>
-
- <shardingsphere:data-source id="shadowDataSource" data-source-names="ds,shadow_ds" 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.core.mybatis.repository"/>
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
- </bean>
-</beans>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-encrypt-shadow-databases.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-encrypt.xml
similarity index 64%
rename from examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-encrypt-shadow-databases.xml
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-encrypt.xml
index c0af924..ac8df47 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-encrypt-shadow-databases.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-encrypt.xml
@@ -40,25 +40,24 @@
<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/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <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="shadow_ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+ <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/shadow_demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <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:rule id="shadowRule" column="shadow" sourceDataSourceNames="ds" shadowDataSourceNames="shadow_ds"/>
-
+
<encrypt:encrypt-algorithm id="name_encryptor" type="AES">
<props>
<prop key="aes-key-value">123456</prop>
</props>
</encrypt:encrypt-algorithm>
+
<encrypt:encrypt-algorithm id="pwd_encryptor" type="assistedTest" />
<encrypt:rule id="encryptRule">
@@ -67,19 +66,65 @@
<encrypt:column logic-column="pwd" cipher-column="pwd" assisted-query-column="assisted_query_pwd" encrypt-algorithm-ref="pwd_encryptor" />
</encrypt:table>
</encrypt:rule>
-
- <shardingsphere:data-source id="encryptShadowDataSource" data-source-names="ds,shadow_ds" rule-refs="shadowRule,encryptRule" />
-
+
+ <shadow:shadow-algorithm id="user-id-insert-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">insert</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-delete-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">delete</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-select-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">select</prop>
+ <prop key="column">user_type</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">
+ <shadow:data-source id="shadow-data-source" source-data-source-name="ds" shadow-data-source-name="ds_shadow"/>
+ <shadow:shadow-table name="t_user" data-sources="shadow-data-source">
+ <shadow:algorithm shadow-algorithm-ref="user-id-insert-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-delete-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-select-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="simple-note-algorithm" />
+ </shadow:shadow-table>
+ </shadow:rule>
+
+ <shardingsphere:data-source id="shadowEncryptDataSource" data-source-names="ds,ds_shadow" rule-refs="shadowRule,encryptRule">
+ <props>
+ <prop key="sql-show">true</prop>
+ <prop key="sql-comment-parse-enabled">true</prop>
+ </props>
+ </shardingsphere:data-source>
+
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="encryptShadowDataSource" />
+ <property name="dataSource" ref="shadowEncryptDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="encryptShadowDataSource"/>
+ <property name="dataSource" ref="shadowEncryptDataSource"/>
<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.core.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-readwrite-splitting-shadow-databases.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-readwrite-splitting.xml
similarity index 67%
rename from examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-readwrite-splitting-shadow-databases.xml
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-readwrite-splitting.xml
index 0b0a772..ccf62d7 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-readwrite-splitting-shadow-databases.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-readwrite-splitting.xml
@@ -37,56 +37,97 @@
http://shardingsphere.apache.org/schema/shardingsphere/readwrite-splitting/readwrite-splitting.xsd
">
<context:component-scan base-package="org.apache.shardingsphere.example.core.mybatis" />
-
- <bean id="write_ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+
+ <bean id="write-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/demo_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <bean id="read_ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+
+ <bean id="read-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/demo_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <bean id="shadow_write_ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+
+ <bean id="write-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/demo_shadow_write_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <bean id="shadow_read_ds" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+
+ <bean id="read-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/demo_shadow_read_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <shadow:rule id="shadowRule" column="shadow" sourceDataSourceNames="write_ds,read_ds" shadowDataSourceNames="shadow_write_ds,shadow_read_ds"/>
- <shardingsphere:data-source id="shadowDataSource" data-source-names="write_ds,read_ds,shadow_write_ds,shadow_read_ds" rule-refs="shadowRule,readWriteSplittingRule">
- <props>
- <prop key="sql-show">true</prop>
- </props>
- </shardingsphere:data-source>
-
<readwrite-splitting:load-balance-algorithm id="randomStrategy" type="RANDOM" />
-
+
<readwrite-splitting:rule id="readWriteSplittingRule">
<readwrite-splitting:data-source-rule id="demo_ds" write-data-source-name="write_ds" read-data-source-names="read_ds" load-balance-algorithm-ref="randomStrategy" />
</readwrite-splitting:rule>
-
+
+ <shadow:shadow-algorithm id="user-id-insert-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">insert</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-delete-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">delete</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-select-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">select</prop>
+ <prop key="column">user_type</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">
+ <shadow:data-source id="shadow-data-source-write" source-data-source-name="write-ds" shadow-data-source-name="write-ds-shadow"/>
+ <shadow:data-source id="shadow-data-source-read" source-data-source-name="read-ds" shadow-data-source-name="read-ds-shadow"/>
+ <shadow:shadow-table name="t_user" data-sources="shadow-data-source-write,shadow-data-source-read">
+ <shadow:algorithm shadow-algorithm-ref="user-id-insert-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-delete-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-select-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="simple-note-algorithm" />
+ </shadow:shadow-table>
+ </shadow:rule>
+
+ <shardingsphere:data-source id="shadowReadWriteDataSource" data-source-names="write-ds,read-ds,write-ds-shadow,read-ds-shadow" rule-refs="shadowRule,readWriteSplittingRule">
+ <props>
+ <prop key="sql-show">true</prop>
+ <prop key="sql-comment-parse-enabled">true</prop>
+ </props>
+ </shardingsphere:data-source>
+
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="shadowDataSource" />
+ <property name="dataSource" ref="shadowReadWriteDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="shadowDataSource"/>
+ <property name="dataSource" ref="shadowReadWriteDataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/>
</bean>
diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-shadow-databases.xml b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-sharding-databases.xml
similarity index 69%
rename from examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-shadow-databases.xml
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-sharding-databases.xml
index f76a99e..b658cb4 100644
--- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-shadow-databases.xml
+++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow-sharding-databases.xml
@@ -44,22 +44,19 @@
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
<bean id="ds_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <bean id="shadow_ds_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+ <bean id="ds_shadow_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shadow_demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
-
- <bean id="shadow_ds_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
+ <bean id="ds_shadow_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shadow_demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
@@ -80,24 +77,65 @@
</props>
</sharding:sharding-algorithm>
- <shadow:rule id="shadowRule" column="shadow" sourceDataSourceNames="ds_0,ds_1" shadowDataSourceNames="shadow_ds_0,shadow_ds_1"/>
+ <shadow:shadow-algorithm id="user-id-insert-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">insert</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-delete-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">delete</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
- <shardingsphere:data-source id="shardingShadowDataSource" data-source-names="ds_0,ds_1,shadow_ds_0,shadow_ds_1" rule-refs="shadowRule,shardingRule">
+ <shadow:shadow-algorithm id="user-id-select-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">select</prop>
+ <prop key="column">user_type</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">
+ <shadow:data-source id="shadow-data-source-0" source-data-source-name="ds_0" shadow-data-source-name="ds_shadow_0"/>
+ <shadow:data-source id="shadow-data-source-1" source-data-source-name="ds_1" shadow-data-source-name="ds_shadow_1"/>
+ <shadow:shadow-table name="t_user" data-sources="shadow-data-source-0,shadow-data-source-1">
+ <shadow:algorithm shadow-algorithm-ref="user-id-insert-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-delete-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-select-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="simple-note-algorithm" />
+ </shadow:shadow-table>
+ </shadow:rule>
+
+ <shardingsphere:data-source id="shadowShardingDatasourceDataSource" data-source-names="write-ds,read-ds,write-ds-shadow,read-ds-shadow" rule-refs="shadowRule,readWriteSplittingRule">
<props>
<prop key="sql-show">true</prop>
+ <prop key="sql-comment-parse-enabled">true</prop>
</props>
</shardingsphere:data-source>
-
+
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="shardingShadowDataSource" />
+ <property name="dataSource" ref="shadowShardingDatasourceDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="shardingShadowDataSource"/>
+ <property name="dataSource" ref="shadowShardingDatasourceDataSource"/>
<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.core.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
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/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow.xml
similarity index 80%
rename from 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
rename to examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow.xml
index c203159..b5f3830 100644
--- 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/shadow-example/shadow-spring-namespace-mybatis-example/src/main/resources/META-INF/application-shadow.xml
@@ -23,23 +23,25 @@
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/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
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" />
+ <context:component-scan base-package="org.apache.shardingsphere.example.core.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"/>
@@ -47,13 +49,30 @@
<property name="password" value=""/>
</bean>
- <shadow:shadow-algorithm id="user-id-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <shadow:shadow-algorithm id="user-id-insert-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">insert</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-delete-match-algorithm" type="COLUMN_REGEX_MATCH">
+ <props>
+ <prop key="operation">delete</prop>
+ <prop key="column">user_type</prop>
+ <prop key="regex">[1]</prop>
+ </props>
+ </shadow:shadow-algorithm>
+
+ <shadow:shadow-algorithm id="user-id-select-match-algorithm" type="COLUMN_REGEX_MATCH">
<props>
<prop key="operation">select</prop>
- <prop key="column">user_id</prop>
+ <prop key="column">user_type</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>
@@ -61,13 +80,12 @@
</props>
</shadow:shadow-algorithm>
- <shadow:rule id="shadowRule" enable="true" column="shadow" sourceDataSourceNames="ds" shadowDataSourceNames="ds_shadow">
+ <shadow:rule id="shadowRule" enable="true">
<shadow:data-source id="shadow-data-source" source-data-source-name="ds" shadow-data-source-name="ds_shadow"/>
- <shadow:shadow-table name="t_order" data-sources="shadow-data-source">
- <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" data-sources="shadow-data-source">
+ <shadow:algorithm shadow-algorithm-ref="user-id-insert-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-delete-match-algorithm" />
+ <shadow:algorithm shadow-algorithm-ref="user-id-select-match-algorithm" />
<shadow:algorithm shadow-algorithm-ref="simple-note-algorithm" />
</shadow:shadow-table>
</shadow:rule>
@@ -78,19 +96,19 @@
<prop key="sql-comment-parse-enabled">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="basePackage" value="org.apache.shardingsphere.example.core.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
index c441ded..3843e1f 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.shadow.api.config;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
@@ -29,7 +26,6 @@ import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceCo
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -37,28 +33,13 @@ import java.util.Map;
*/
@Getter
@Setter
-@RequiredArgsConstructor
public final class ShadowRuleConfiguration implements SchemaRuleConfiguration, DistributedRuleConfiguration {
- private final String column;
-
- private final List<String> sourceDataSourceNames;
-
- private final List<String> shadowDataSourceNames;
-
- private final boolean enable;
+ private boolean enable;
private Map<String, ShadowDataSourceConfiguration> dataSources = new LinkedHashMap<>();
private Map<String, ShadowTableConfiguration> tables = new LinkedHashMap<>();
private Map<String, ShardingSphereAlgorithmConfiguration> shadowAlgorithms = new LinkedHashMap<>();
-
- public ShadowRuleConfiguration(final String column, final List<String> sourceDataSourceNames, final List<String> shadowDataSourceNames) {
- this(column, sourceDataSourceNames, shadowDataSourceNames, false);
- Preconditions.checkArgument(!Strings.isNullOrEmpty(column), "Column is required.");
- Preconditions.checkArgument(!sourceDataSourceNames.isEmpty(), "SourceDataSourceNames is required.");
- Preconditions.checkArgument(!shadowDataSourceNames.isEmpty(), "ShadowDataSourceNames is required.");
- Preconditions.checkArgument(sourceDataSourceNames.size() == shadowDataSourceNames.size(), "SourceDataSourceNames and ShadowDataSourceNames size must same.");
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowOperationType.java
similarity index 97%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowOperationType.java
index 80aa4e2..d0ecc75 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowOperationType.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.api.shadow.column;
+package org.apache.shardingsphere.shadow.api.shadow;
import java.util.Optional;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
index 89a0fd3..7a5bfa9 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.shadow.api.shadow.column;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
/**
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
index 636de34..7237cc3 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.shadow.api.shadow.note;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
@RequiredArgsConstructor
@Getter
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/config/AlgorithmProvidedShadowRuleConfiguration.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/config/AlgorithmProvidedShadowRuleConfiguration.java
index d935a8b..db3fb0b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/config/AlgorithmProvidedShadowRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/config/AlgorithmProvidedShadowRuleConfiguration.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.shadow.algorithm.config;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
import org.apache.shardingsphere.infra.config.scope.SchemaRuleConfiguration;
@@ -27,7 +26,6 @@ import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -35,16 +33,8 @@ import java.util.Map;
*/
@Getter
@Setter
-@RequiredArgsConstructor
public final class AlgorithmProvidedShadowRuleConfiguration implements SchemaRuleConfiguration, DistributedRuleConfiguration {
- // fixme remove three fields when the api refactoring is complete
- private final String column;
-
- private final List<String> sourceDataSourceNames;
-
- private final List<String> shadowDataSourceNames;
-
private boolean enable;
private Map<String, ShadowDataSourceConfiguration> dataSources = new LinkedHashMap<>();
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
index a37a324..1b7c463 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.shadow.algorithm.shadow.column;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
import java.util.Collection;
import java.util.Objects;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
index 2c47567..32ba08b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.shadow.algorithm.shadow.note;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
index d9742bd..82f765b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
@@ -27,7 +27,7 @@ public final class AlgorithmProvidedShadowRuleConfigurationChecker extends Abstr
@Override
protected boolean isAvailableShadowRule(final AlgorithmProvidedShadowRuleConfiguration config) {
- return !config.getColumn().isEmpty() && null != config.getSourceDataSourceNames() && null != config.getShadowDataSourceNames();
+ return true;
}
@Override
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index 43f2052..bc66261 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -27,7 +27,7 @@ public final class ShadowRuleConfigurationChecker extends AbstractShadowRuleConf
@Override
protected boolean isAvailableShadowRule(final ShadowRuleConfiguration config) {
- return !config.getColumn().isEmpty() && null != config.getSourceDataSourceNames() && null != config.getShadowDataSourceNames();
+ return true;
}
@Override
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowColumnCondition.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowColumnCondition.java
similarity index 93%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowColumnCondition.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowColumnCondition.java
index 2bdfbaf..ea1e09f 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowColumnCondition.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowColumnCondition.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner;
+package org.apache.shardingsphere.shadow.condition;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowCondition.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowCondition.java
deleted file mode 100644
index b4dee26..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowCondition.java
+++ /dev/null
@@ -1,84 +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.shadow.condition;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-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.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Shadow condition.
- */
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class ShadowCondition {
-
- private final String columnName;
-
- private final int startIndex;
-
- private final int stopIndex;
-
- private final Map<Integer, Integer> positionIndexMap = new LinkedHashMap<>();
-
- private final Map<Integer, Object> positionValueMap = new LinkedHashMap<>();
-
- public ShadowCondition(final String columnName, final int startIndex, final int stopIndex, final ExpressionSegment expressionSegment) {
- this.columnName = columnName;
- this.startIndex = startIndex;
- this.stopIndex = stopIndex;
- putPositionMap(expressionSegment);
- }
-
- private void putPositionMap(final ExpressionSegment expressionSegment) {
- if (expressionSegment instanceof ParameterMarkerExpressionSegment) {
- positionIndexMap.put(0, ((ParameterMarkerExpressionSegment) expressionSegment).getParameterMarkerIndex());
- } else if (expressionSegment instanceof LiteralExpressionSegment) {
- positionValueMap.put(0, ((LiteralExpressionSegment) expressionSegment).getLiterals());
- }
- }
-
- /**
- * Get values.
- *
- * @param parameters SQL parameters
- * @return values
- */
- public List<Object> getValues(final List<Object> parameters) {
- List<Object> result = new ArrayList<>(positionValueMap.values());
- for (Entry<Integer, Integer> entry : positionIndexMap.entrySet()) {
- Object parameter = parameters.get(entry.getValue());
- if (entry.getKey() < result.size()) {
- result.add(entry.getKey(), parameter);
- } else {
- result.add(parameter);
- }
- }
- return result;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java
deleted file mode 100644
index 339f8f2..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java
+++ /dev/null
@@ -1,130 +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.shadow.condition;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.SimpleExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.AndPredicate;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.util.ColumnExtractor;
-import org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Optional;
-
-/**
- * Shadow condition engine.
- */
-@RequiredArgsConstructor
-public final class ShadowConditionEngine {
-
- private final ShadowRule shadowRule;
-
- /**
- * Create shadow condition.
- *
- * @param sqlStatementContext SQL statement context
- * @return shadow condition
- */
- public Optional<ShadowCondition> createShadowCondition(final SQLStatementContext sqlStatementContext) {
- if (sqlStatementContext instanceof WhereAvailable) {
- WhereAvailable whereAvailable = (WhereAvailable) sqlStatementContext;
- return createShadowConditionInWhereAvailable(whereAvailable);
- }
- return Optional.empty();
- }
-
- private Optional<ShadowCondition> createShadowConditionInWhereAvailable(final WhereAvailable whereAvailable) {
- return whereAvailable.getWhere().flatMap(this::createShadowConditionWhereSegment);
- }
-
- private Optional<ShadowCondition> createShadowConditionWhereSegment(final WhereSegment whereSegment) {
- return createShadowConditionAndPredicates(createAndPredicates(whereSegment));
- }
-
- private Collection<AndPredicate> createAndPredicates(final WhereSegment whereSegment) {
- return ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr());
- }
-
- private Optional<ShadowCondition> createShadowConditionAndPredicates(final Collection<AndPredicate> andPredicates) {
- for (AndPredicate each : new LinkedList<>(andPredicates)) {
- Optional<ShadowCondition> condition = createShadowConditionAndPredicate(each);
- if (condition.isPresent()) {
- return condition;
- }
- }
- return Optional.empty();
- }
-
- private Optional<ShadowCondition> createShadowConditionAndPredicate(final AndPredicate andPredicate) {
- for (ExpressionSegment predicate : andPredicate.getPredicates()) {
- for (ColumnSegment each : ColumnExtractor.extract(predicate)) {
- Optional<ShadowCondition> shadowCondition = createShadowConditionColumnSegment(each, predicate);
- if (shadowCondition.isPresent()) {
- return shadowCondition;
- }
- }
- }
- return Optional.empty();
- }
-
- private Optional<ShadowCondition> createShadowConditionColumnSegment(final ColumnSegment columnSegment, final ExpressionSegment expression) {
- return compareColumnName(columnSegment) ? createShadowConditionExpressionSegment(expression) : Optional.empty();
- }
-
- private boolean compareColumnName(final ColumnSegment columnSegment) {
- return shadowRule.getColumn().equals(columnSegment.getIdentifier().getValue());
- }
-
- private Optional<ShadowCondition> createShadowConditionExpressionSegment(final ExpressionSegment expression) {
- if (expression instanceof InExpression) {
- throw new ShardingSphereException("The SQL clause 'IN...' is unsupported in shadow rule.");
- }
- if (expression instanceof BetweenExpression) {
- throw new ShardingSphereException("The SQL clause 'BETWEEN...AND...' is unsupported in shadow rule.");
- }
- if (expression instanceof BinaryOperationExpression) {
- BinaryOperationExpression binaryOperationExpression = (BinaryOperationExpression) expression;
- return isSupportedOperator(binaryOperationExpression.getOperator()) ? createShadowConditionBinaryOperation((BinaryOperationExpression) expression)
- : Optional.empty();
- }
- return Optional.empty();
- }
-
- private boolean isSupportedOperator(final String operator) {
- return "=".equals(operator);
- }
-
- private Optional<ShadowCondition> createShadowConditionBinaryOperation(final BinaryOperationExpression binaryOperationExpression) {
- ExpressionSegment left = binaryOperationExpression.getLeft();
- ExpressionSegment right = binaryOperationExpression.getRight();
- return left instanceof ColumnSegment && right instanceof SimpleExpressionSegment
- ? Optional.of(new ShadowCondition(((ColumnSegment) left).getIdentifier().getValue(), right.getStartIndex(), binaryOperationExpression.getStopIndex(), right))
- : Optional.empty();
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDetermineCondition.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
similarity index 95%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDetermineCondition.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
index d6f59a5..b199c3a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDetermineCondition.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner;
+package org.apache.shardingsphere.shadow.condition;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import java.util.Collection;
import java.util.LinkedList;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/aware/ShadowRuleAware.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/aware/ShadowRuleAware.java
deleted file mode 100644
index 16ec1d1..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/aware/ShadowRuleAware.java
+++ /dev/null
@@ -1,33 +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.shadow.rewrite.aware;
-
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-
-/**
- * Shadow rule aware.
- */
-public interface ShadowRuleAware {
-
- /**
- * Set shadow rule.
- *
- * @param shadowRule shadow rule
- */
- void setShadowRule(ShadowRule shadowRule);
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java
deleted file mode 100644
index fa1a518..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.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.shadow.rewrite.context;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
-import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
-import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.shadow.constant.ShadowOrder;
-import org.apache.shardingsphere.shadow.rewrite.parameter.ShadowParameterRewriterBuilder;
-import org.apache.shardingsphere.shadow.rewrite.token.ShadowTokenGenerateBuilder;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-
-import java.util.List;
-
-/**
- * SQL rewrite context decorator for shadow.
- */
-public final class ShadowSQLRewriteContextDecorator implements SQLRewriteContextDecorator<ShadowRule> {
-
- @Override
- public void decorate(final ShadowRule shadowRule, final ConfigurationProperties props, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
- doShadowDecorate(shadowRule, sqlRewriteContext);
- }
-
- private void doShadowDecorate(final ShadowRule shadowRule, final SQLRewriteContext sqlRewriteContext) {
- doParameterRewriterDecorate(shadowRule, sqlRewriteContext);
- sqlRewriteContext.addSQLTokenGenerators(new ShadowTokenGenerateBuilder(shadowRule).getSQLTokenGenerators());
- }
-
- @SuppressWarnings("unchecked")
- private void doParameterRewriterDecorate(final ShadowRule shadowRule, final SQLRewriteContext sqlRewriteContext) {
- List<Object> parameters = sqlRewriteContext.getParameters();
- SQLStatementContext<?> sqlStatementContext = sqlRewriteContext.getSqlStatementContext();
- for (ParameterRewriter each : new ShadowParameterRewriterBuilder(shadowRule).getParameterRewriters(sqlRewriteContext.getSchema())) {
- if (!parameters.isEmpty() && each.isNeedRewrite(sqlStatementContext)) {
- ParameterBuilder parameterBuilder = sqlRewriteContext.getParameterBuilder();
- each.rewrite(parameterBuilder, sqlStatementContext, parameters);
- }
- }
- }
-
- @Override
- public int getOrder() {
- return ShadowOrder.ORDER;
- }
-
- @Override
- public Class<ShadowRule> getTypeClass() {
- return ShadowRule.class;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriter.java
deleted file mode 100644
index 29e2ddd..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriter.java
+++ /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.
- */
-
-package org.apache.shardingsphere.shadow.rewrite.parameter;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.rewrite.aware.ShadowRuleAware;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter;
-
-/**
- * Parameter rewriter for shadow.
- *
- * @param <T> type of SQL statement context
- */
-@Getter
-@Setter
-public abstract class ShadowParameterRewriter<T extends SQLStatementContext> implements ParameterRewriter<T>, ShadowRuleAware {
-
- private ShadowRule shadowRule;
-
- @Override
- public final boolean isNeedRewrite(final SQLStatementContext sqlStatementContext) {
- return isNeedRewriteForShadow(sqlStatementContext);
- }
-
- protected abstract boolean isNeedRewriteForShadow(SQLStatementContext sqlStatementContext);
-
- protected String getShadowColumn() {
- return shadowRule.getColumn();
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilder.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilder.java
deleted file mode 100644
index 6edd8a6..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilder.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.shadow.rewrite.parameter;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.shadow.rewrite.parameter.impl.ShadowUpdateValueParameterRewriter;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.shadow.rewrite.aware.ShadowRuleAware;
-import org.apache.shardingsphere.shadow.rewrite.parameter.impl.ShadowInsertValueParameterRewriter;
-import org.apache.shardingsphere.shadow.rewrite.parameter.impl.ShadowPredicateParameterRewriter;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter;
-import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriterBuilder;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * Parameter rewriter builder for shadow.
- */
-@RequiredArgsConstructor
-public final class ShadowParameterRewriterBuilder implements ParameterRewriterBuilder {
-
- private final ShadowRule shadowRule;
-
- @Override
- public Collection<ParameterRewriter> getParameterRewriters(final ShardingSphereSchema schema) {
- Collection<ParameterRewriter> result = getParameterRewriters();
- for (ParameterRewriter each : result) {
- ((ShadowRuleAware) each).setShadowRule(shadowRule);
- }
- return result;
- }
-
- private Collection<ParameterRewriter> getParameterRewriters() {
- Collection<ParameterRewriter> result = new LinkedList<>();
- result.add(new ShadowPredicateParameterRewriter());
- result.add(new ShadowInsertValueParameterRewriter());
- result.add(new ShadowUpdateValueParameterRewriter());
- return result;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriter.java
deleted file mode 100644
index dc4f785..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriter.java
+++ /dev/null
@@ -1,71 +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.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
-import org.apache.shardingsphere.shadow.rewrite.parameter.ShadowParameterRewriter;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Insert value parameter rewriter for shadow.
- */
-public final class ShadowInsertValueParameterRewriter extends ShadowParameterRewriter<InsertStatementContext> {
-
- @Override
- protected boolean isNeedRewriteForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof InsertStatementContext && isContainShadowColumn((InsertStatementContext) sqlStatementContext);
- }
-
- private boolean isContainShadowColumn(final InsertStatementContext insertStatementContext) {
- return insertStatementContext.getInsertColumnNames().contains(getShadowColumn());
- }
-
- @Override
- public void rewrite(final ParameterBuilder parameterBuilder, final InsertStatementContext insertStatementContext, final List<Object> parameters) {
- doShadowRewrite(parameterBuilder, insertStatementContext);
- }
-
- private void doShadowRewrite(final ParameterBuilder parameterBuilder, final InsertStatementContext insertStatementContext) {
- if (parameterBuilder instanceof GroupedParameterBuilder) {
- GroupedParameterBuilder groupedParameterBuilder = (GroupedParameterBuilder) parameterBuilder;
- int columnIndex = getShadowColumnIndex(groupedParameterBuilder, insertStatementContext);
- addRemovedParametersForShadow(groupedParameterBuilder, insertStatementContext, columnIndex);
- }
- }
-
- private void addRemovedParametersForShadow(final GroupedParameterBuilder groupedParameterBuilder, final InsertStatementContext insertStatementContext, final int columnIndex) {
- int count = 0;
- for (List<Object> each : insertStatementContext.getGroupedParameters()) {
- if (!each.isEmpty()) {
- groupedParameterBuilder.getParameterBuilders().get(count).addRemovedParameters(columnIndex);
- }
- count++;
- }
- }
-
- private int getShadowColumnIndex(final GroupedParameterBuilder groupedParameterBuilder, final InsertStatementContext insertStatementContext) {
- List<String> columnNames = new LinkedList<>(insertStatementContext.getColumnNames());
- groupedParameterBuilder.getDerivedColumnName().ifPresent(columnNames::remove);
- return columnNames.indexOf(getShadowColumn());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriter.java
deleted file mode 100644
index 92b5882..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriter.java
+++ /dev/null
@@ -1,53 +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.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.StandardParameterBuilder;
-import org.apache.shardingsphere.shadow.condition.ShadowConditionEngine;
-import org.apache.shardingsphere.shadow.rewrite.parameter.ShadowParameterRewriter;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Predicate parameter rewriter for shadow.
- */
-public final class ShadowPredicateParameterRewriter extends ShadowParameterRewriter<SQLStatementContext> {
-
- @Override
- protected boolean isNeedRewriteForShadow(final SQLStatementContext sqlStatementContext) {
- return true;
- }
-
- @Override
- public void rewrite(final ParameterBuilder parameterBuilder, final SQLStatementContext sqlStatementContext, final List<Object> parameters) {
- new ShadowConditionEngine(getShadowRule()).createShadowCondition(sqlStatementContext).ifPresent(
- shadowCondition -> replaceShadowParameter(parameterBuilder, shadowCondition.getPositionIndexMap()));
- }
-
- private void replaceShadowParameter(final ParameterBuilder parameterBuilder, final Map<Integer, Integer> positionIndexes) {
- if (!positionIndexes.isEmpty()) {
- for (Entry<Integer, Integer> entry : positionIndexes.entrySet()) {
- ((StandardParameterBuilder) parameterBuilder).addRemovedParameters(entry.getValue());
- }
- }
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriter.java
deleted file mode 100644
index cd898fa..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriter.java
+++ /dev/null
@@ -1,65 +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.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.StandardParameterBuilder;
-import org.apache.shardingsphere.shadow.rewrite.parameter.ShadowParameterRewriter;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
-
-import java.util.List;
-
-/**
- * Update value parameter rewriter for shadow.
- */
-public final class ShadowUpdateValueParameterRewriter extends ShadowParameterRewriter<UpdateStatementContext> {
-
- @Override
- protected boolean isNeedRewriteForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof UpdateStatementContext && isContainShadowColumn(((UpdateStatementContext) sqlStatementContext).getSqlStatement());
- }
-
- private boolean isContainShadowColumn(final UpdateStatement updateStatement) {
- return updateStatement.getSetAssignment().getAssignments().stream().anyMatch(each -> each.getColumns().get(0).getIdentifier().getValue().equals(getShadowColumn()));
- }
-
- @Override
- public void rewrite(final ParameterBuilder parameterBuilder, final UpdateStatementContext updateStatementContext, final List<Object> parameters) {
- doShadowRewrite(parameterBuilder, updateStatementContext.getSqlStatement());
- }
-
- private void doShadowRewrite(final ParameterBuilder parameterBuilder, final UpdateStatement sqlStatement) {
- if (parameterBuilder instanceof StandardParameterBuilder) {
- ((StandardParameterBuilder) parameterBuilder).addRemovedParameters(getShadowColumnIndex(sqlStatement));
- }
- }
-
- private int getShadowColumnIndex(final UpdateStatement sqlStatement) {
- int count = 0;
- for (AssignmentSegment each : sqlStatement.getSetAssignment().getAssignments()) {
- if (each.getColumns().get(0).getIdentifier().getValue().equals(getShadowColumn())) {
- return count;
- }
- count++;
- }
- return count;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilder.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilder.java
deleted file mode 100644
index 4791b91..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilder.java
+++ /dev/null
@@ -1,58 +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.shadow.rewrite.token;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.impl.ShadowUpdateColumnTokenGenerator;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.shadow.rewrite.aware.ShadowRuleAware;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.impl.ShadowInsertColumnTokenGenerator;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.impl.ShadowInsertValuesTokenGenerator;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.impl.ShadowPredicateColumnTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.SQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.builder.SQLTokenGeneratorBuilder;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * SQL token generator builder for shadow.
- */
-@RequiredArgsConstructor
-public final class ShadowTokenGenerateBuilder implements SQLTokenGeneratorBuilder {
-
- private final ShadowRule shadowRule;
-
- @Override
- public Collection<SQLTokenGenerator> getSQLTokenGenerators() {
- Collection<SQLTokenGenerator> result = buildSQLTokenGenerators();
- for (SQLTokenGenerator each : result) {
- ((ShadowRuleAware) each).setShadowRule(shadowRule);
- }
- return result;
- }
-
- private Collection<SQLTokenGenerator> buildSQLTokenGenerators() {
- Collection<SQLTokenGenerator> result = new LinkedList<>();
- result.add(new ShadowInsertValuesTokenGenerator());
- result.add(new ShadowInsertColumnTokenGenerator());
- result.add(new ShadowPredicateColumnTokenGenerator());
- result.add(new ShadowUpdateColumnTokenGenerator());
- return result;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/BaseShadowSQLTokenGenerator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/BaseShadowSQLTokenGenerator.java
deleted file mode 100644
index 677da63..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/BaseShadowSQLTokenGenerator.java
+++ /dev/null
@@ -1,46 +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.shadow.rewrite.token.generator;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.rewrite.aware.ShadowRuleAware;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.SQLTokenGenerator;
-
-/**
- * Base SQL token generator for shadow.
- */
-@Getter
-@Setter
-public abstract class BaseShadowSQLTokenGenerator implements SQLTokenGenerator, ShadowRuleAware {
-
- private ShadowRule shadowRule;
-
- @Override
- public final boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return isGenerateSQLTokenForShadow(sqlStatementContext);
- }
-
- protected abstract boolean isGenerateSQLTokenForShadow(SQLStatementContext sqlStatementContext);
-
- protected String getShadowColumn() {
- return shadowRule.getColumn();
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
deleted file mode 100644
index 1e0a3e1..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
+++ /dev/null
@@ -1,77 +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.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.BaseShadowSQLTokenGenerator;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Optional;
-
-/**
- * Remove shadow column token generator.
- */
-public final class ShadowInsertColumnTokenGenerator extends BaseShadowSQLTokenGenerator implements CollectionSQLTokenGenerator<InsertStatementContext> {
-
- @Override
- protected boolean isGenerateSQLTokenForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof InsertStatementContext && isContainShadowColumn(((InsertStatementContext) sqlStatementContext).getSqlStatement());
- }
-
- private boolean isContainShadowColumn(final InsertStatement sqlStatement) {
- Optional<InsertColumnsSegment> insertColumnsSegment = sqlStatement.getInsertColumns();
- return insertColumnsSegment.isPresent() && !insertColumnsSegment.get().getColumns().isEmpty();
- }
-
- @Override
- public Collection<RemoveToken> generateSQLTokens(final InsertStatementContext insertStatementContext) {
- Optional<InsertColumnsSegment> sqlSegment = insertStatementContext.getSqlStatement().getInsertColumns();
- Collection<RemoveToken> result = new LinkedList<>();
- sqlSegment.ifPresent(insertColumnsSegment -> generateRemoveTokenForShadow(insertColumnsSegment, result));
- return result;
- }
-
- private void generateRemoveTokenForShadow(final InsertColumnsSegment insertColumnsSegment, final Collection<RemoveToken> removeTokens) {
- Collection<ColumnSegment> columnSegments = insertColumnsSegment.getColumns();
- String shadowColumn = getShadowColumn();
- int index = 0;
- int previousElementStopIndex = 0;
- Iterator<ColumnSegment> iterator = columnSegments.iterator();
- while (iterator.hasNext()) {
- ColumnSegment each = iterator.next();
- if (shadowColumn.equals(each.getIdentifier().getValue())) {
- removeTokens.add(isFirstElement(index) ? new RemoveToken(each.getStartIndex(), iterator.next().getStartIndex() - 1)
- : new RemoveToken(previousElementStopIndex + 1, each.getStopIndex()));
- }
- previousElementStopIndex = each.getStopIndex();
- index++;
- }
- }
-
- private boolean isFirstElement(final int index) {
- return 0 == index;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGenerator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGenerator.java
deleted file mode 100644
index 76a44fa..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGenerator.java
+++ /dev/null
@@ -1,123 +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.shadow.rewrite.token.generator.impl;
-
-import lombok.Setter;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.PreviousSQLTokensAware;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.BaseShadowSQLTokenGenerator;
-import org.apache.shardingsphere.shadow.rewrite.token.pojo.ShadowInsertValuesToken;
-import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Insert values token generator for shadow.
- */
-@Setter
-public final class ShadowInsertValuesTokenGenerator extends BaseShadowSQLTokenGenerator implements OptionalSQLTokenGenerator<InsertStatementContext>, PreviousSQLTokensAware {
-
- private List<SQLToken> previousSQLTokens;
-
- @Override
- protected boolean isGenerateSQLTokenForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof InsertStatementContext && isContainShadowColumn((InsertStatementContext) sqlStatementContext);
- }
-
- private boolean isContainShadowColumn(final InsertStatementContext insertStatementContext) {
- return insertStatementContext.getInsertColumnNames().contains(getShadowColumn());
- }
-
- @Override
- public InsertValuesToken generateSQLToken(final InsertStatementContext insertStatementContext) {
- Optional<SQLToken> insertValuesToken = findPreviousSQLToken(InsertValuesToken.class);
- if (insertValuesToken.isPresent()) {
- processPreviousSQLToken(insertStatementContext, (InsertValuesToken) insertValuesToken.get());
- return (InsertValuesToken) insertValuesToken.get();
- }
- return generateNewSQLToken(insertStatementContext);
- }
-
- private void processPreviousSQLToken(final InsertStatementContext insertStatementContext, final InsertValuesToken insertValuesToken) {
- for (InsertValue insertValueToken : insertValuesToken.getInsertValues()) {
- Iterator<String> descendingColumnNames = insertStatementContext.getDescendingColumnNames();
- while (descendingColumnNames.hasNext()) {
- String columnName = descendingColumnNames.next();
- if (getShadowRule().getColumn().equals(columnName)) {
- removeValueToken(insertValueToken, insertStatementContext, columnName);
- }
- }
- }
- }
-
- private InsertValuesToken generateNewSQLToken(final InsertStatementContext insertStatementContext) {
- Collection<InsertValuesSegment> insertValuesSegments = insertStatementContext.getSqlStatement().getValues();
- InsertValuesToken result = new ShadowInsertValuesToken(getStartIndex(insertValuesSegments), getStopIndex(insertValuesSegments));
- for (InsertValueContext each : insertStatementContext.getInsertValueContexts()) {
- InsertValue insertValueToken = new InsertValue(each.getValueExpressions());
- Iterator<String> descendingColumnNames = insertStatementContext.getDescendingColumnNames();
- while (descendingColumnNames.hasNext()) {
- String columnName = descendingColumnNames.next();
- if (getShadowRule().getColumn().equals(columnName)) {
- removeValueToken(insertValueToken, insertStatementContext, columnName);
- }
- }
- result.getInsertValues().add(insertValueToken);
- }
- return result;
- }
-
- private Optional<SQLToken> findPreviousSQLToken(final Class<?> sqlToken) {
- for (SQLToken each : previousSQLTokens) {
- if (sqlToken.isAssignableFrom(each.getClass())) {
- return Optional.of(each);
- }
- }
- return Optional.empty();
- }
-
- private void removeValueToken(final InsertValue insertValueToken, final InsertStatementContext insertStatementContext, final String columnName) {
- int columnIndex = insertStatementContext.getColumnNames().indexOf(columnName);
- insertValueToken.getValues().remove(columnIndex);
- }
-
- private int getStartIndex(final Collection<InsertValuesSegment> segments) {
- int result = segments.iterator().next().getStartIndex();
- for (InsertValuesSegment each : segments) {
- result = Math.min(result, each.getStartIndex());
- }
- return result;
- }
-
- private int getStopIndex(final Collection<InsertValuesSegment> segments) {
- int result = segments.iterator().next().getStopIndex();
- for (InsertValuesSegment each : segments) {
- result = Math.max(result, each.getStopIndex());
- }
- return result;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGenerator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGenerator.java
deleted file mode 100644
index 2a6de47..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGenerator.java
+++ /dev/null
@@ -1,93 +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.shadow.rewrite.token.generator.impl;
-
-import com.google.common.base.Preconditions;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.BaseShadowSQLTokenGenerator;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.AndPredicate;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.util.ColumnExtractor;
-import org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Optional;
-
-/**
- * Predicate column token generator for shadow.
- */
-@Setter
-public final class ShadowPredicateColumnTokenGenerator extends BaseShadowSQLTokenGenerator implements CollectionSQLTokenGenerator {
-
- @Override
- protected boolean isGenerateSQLTokenForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof WhereAvailable && ((WhereAvailable) sqlStatementContext).getWhere().isPresent();
- }
-
- @Override
- public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- Optional<WhereSegment> whereOptional = ((WhereAvailable) sqlStatementContext).getWhere();
- Preconditions.checkState(whereOptional.isPresent());
- WhereSegment whereSegment = whereOptional.get();
- ExpressionSegment expression = whereSegment.getExpr();
- Collection<SQLToken> result = new LinkedList<>();
- for (AndPredicate each : ExpressionExtractUtil.getAndPredicates(expression)) {
- result.addAll(generateSQLTokens(whereSegment, each));
- }
- return result;
- }
-
- private Collection<SQLToken> generateSQLTokens(final WhereSegment whereSegment, final AndPredicate andPredicate) {
- Collection<SQLToken> result = new LinkedList<>();
- Collection<ExpressionSegment> predicates = andPredicate.getPredicates();
- int index = 0;
- int previousElementStopIndex = 0;
- Iterator<ExpressionSegment> iterator = predicates.iterator();
- while (iterator.hasNext()) {
- ExpressionSegment each = iterator.next();
- for (ColumnSegment column : ColumnExtractor.extract(each)) {
- if (!getShadowRule().getColumn().equals(column.getIdentifier().getValue())) {
- continue;
- }
- if (1 == predicates.size()) {
- result.add(new RemoveToken(whereSegment.getStartIndex(), whereSegment.getStopIndex()));
- return result;
- }
- result.add(isFirstElement(index) ? new RemoveToken(each.getStartIndex(), iterator.next().getStartIndex() - 1)
- : new RemoveToken(previousElementStopIndex + 1, each.getStopIndex()));
- return result;
- }
- previousElementStopIndex = each.getStopIndex();
- index++;
- }
- return result;
- }
-
- private boolean isFirstElement(final int index) {
- return 0 == index;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGenerator.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGenerator.java
deleted file mode 100644
index cdf281e..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGenerator.java
+++ /dev/null
@@ -1,71 +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.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
-import org.apache.shardingsphere.shadow.rewrite.token.generator.BaseShadowSQLTokenGenerator;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-/**
- * Remove update column token generator for shadow.
- */
-public final class ShadowUpdateColumnTokenGenerator extends BaseShadowSQLTokenGenerator implements CollectionSQLTokenGenerator<UpdateStatementContext> {
-
- @Override
- protected boolean isGenerateSQLTokenForShadow(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof UpdateStatementContext && isContainShadowColumn(((UpdateStatementContext) sqlStatementContext).getSqlStatement().getSetAssignment().getAssignments());
- }
-
- private boolean isContainShadowColumn(final Collection<AssignmentSegment> assignments) {
- return assignments.stream().anyMatch(each -> each.getColumns().get(0).getIdentifier().getValue().equals(getShadowColumn()));
- }
-
- @Override
- public Collection<? extends SQLToken> generateSQLTokens(final UpdateStatementContext sqlStatementContext) {
- return generateRemoveTokenForShadow(sqlStatementContext.getSqlStatement().getSetAssignment().getAssignments());
- }
-
- private Collection<RemoveToken> generateRemoveTokenForShadow(final Collection<AssignmentSegment> assignments) {
- LinkedList<RemoveToken> removeTokens = new LinkedList<>();
- int index = 0;
- int previousElementStopIndex = 0;
- Iterator<AssignmentSegment> iterator = assignments.iterator();
- while (iterator.hasNext()) {
- AssignmentSegment each = iterator.next();
- if (getShadowColumn().equals(each.getColumns().get(0).getIdentifier().getValue())) {
- removeTokens.add(isLastElement(index, assignments.size()) ? new RemoveToken(previousElementStopIndex + 1, each.getStopIndex())
- : new RemoveToken(each.getStartIndex(), iterator.next().getStartIndex() - 1));
- }
- previousElementStopIndex = each.getValue().getStopIndex();
- index++;
- }
- return removeTokens;
- }
-
- private boolean isLastElement(final int index, final int size) {
- return size - 1 == index;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesToken.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesToken.java
deleted file mode 100644
index 44ecc85..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesToken.java
+++ /dev/null
@@ -1,43 +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.shadow.rewrite.token.pojo;
-
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
-
-import java.util.StringJoiner;
-
-/**
- * Insert values token for shadow.
- */
-public final class ShadowInsertValuesToken extends InsertValuesToken {
-
- public ShadowInsertValuesToken(final int startIndex, final int stopIndex) {
- super(startIndex, stopIndex);
- }
-
- @Override
- public String toString() {
- String delimiter = ", ";
- StringJoiner stringJoiner = new StringJoiner(delimiter);
- for (InsertValue each : getInsertValues()) {
- stringJoiner.add(each.toString());
- }
- return stringJoiner.toString();
- }
-}
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 27d56a3..3f1c5f7 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
@@ -18,26 +18,13 @@
package org.apache.shardingsphere.shadow.route;
import org.apache.shardingsphere.infra.binder.LogicSQL;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
-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.judge.ShadowDataSourceJudgeEngine;
-import org.apache.shardingsphere.shadow.route.judge.impl.PreparedShadowDataSourceJudgeEngine;
-import org.apache.shardingsphere.shadow.route.judge.impl.SimpleShadowDataSourceJudgeEngine;
+import org.apache.shardingsphere.shadow.route.engine.ShadowRouteEngineFactory;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
/**
* Shadow SQL router.
@@ -46,74 +33,19 @@ public final class ShadowSQLRouter implements SQLRouter<ShadowRule> {
@Override
public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShadowRule rule, final ConfigurationProperties props) {
- return logicSQL.getSqlStatementContext().getSqlStatement() instanceof DMLStatement ? createRouteContextInDML(logicSQL, rule) : createRouteContextWithoutDML(rule);
- }
-
- private RouteContext createRouteContextWithoutDML(final ShadowRule rule) {
- final RouteContext result = new RouteContext();
- rule.getShadowMappings().forEach((key, value) -> {
- result.getRouteUnits().add(createRouteUnit(key, key));
- result.getRouteUnits().add(createRouteUnit(value, value));
- });
- return result;
- }
-
- private RouteContext createRouteContextInDML(final LogicSQL logicSQL, final ShadowRule rule) {
- final RouteContext result = new RouteContext();
- Map<String, String> shadowMappings = rule.getShadowMappings();
- if (isShadow(logicSQL, rule)) {
- shadowMappings.values().forEach(each -> result.getRouteUnits().add(createRouteUnit(each, each)));
- } else {
- shadowMappings.keySet().forEach(each -> result.getRouteUnits().add(createRouteUnit(each, each)));
- }
- return result;
- }
-
- private boolean isShadow(final LogicSQL logicSQL, final ShadowRule rule) {
- final SQLStatementContext<?> sqlStatementContext = logicSQL.getSqlStatementContext();
- final List<Object> parameters = logicSQL.getParameters();
- ShadowDataSourceJudgeEngine shadowDataSourceRouter = parameters.isEmpty()
- ? new SimpleShadowDataSourceJudgeEngine(rule, sqlStatementContext) : new PreparedShadowDataSourceJudgeEngine(rule, sqlStatementContext, parameters);
- return shadowDataSourceRouter.isShadow();
- }
-
- private RouteUnit createRouteUnit(final String logicName, final String actualName) {
- return new RouteUnit(new RouteMapper(logicName, actualName), Collections.emptyList());
+ // TODO
+ return new RouteContext();
}
@Override
public void decorateRouteContext(final RouteContext routeContext,
final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShadowRule rule, final ConfigurationProperties props) {
if (rule.isEnable()) {
- doShadowDecorateFuture(routeContext, logicSQL, rule);
- } else {
doShadowDecorate(routeContext, logicSQL, rule);
}
}
private void doShadowDecorate(final RouteContext routeContext, final LogicSQL logicSQL, final ShadowRule rule) {
- Collection<RouteUnit> toBeAdded = new LinkedList<>();
- if (!(logicSQL.getSqlStatementContext().getSqlStatement() instanceof DMLStatement)) {
- for (RouteUnit each : routeContext.getRouteUnits()) {
- String shadowDataSourceName = rule.getShadowMappings().get(each.getDataSourceMapper().getActualName());
- toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), shadowDataSourceName), each.getTableMappers()));
- }
- routeContext.getRouteUnits().addAll(toBeAdded);
- return;
- }
- Collection<RouteUnit> toBeRemoved = new LinkedList<>();
- if (isShadow(logicSQL, rule)) {
- for (RouteUnit each : routeContext.getRouteUnits()) {
- toBeRemoved.add(each);
- String shadowDataSourceName = rule.getShadowMappings().get(each.getDataSourceMapper().getActualName());
- toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), shadowDataSourceName), each.getTableMappers()));
- }
- }
- routeContext.getRouteUnits().removeAll(toBeRemoved);
- routeContext.getRouteUnits().addAll(toBeAdded);
- }
-
- private void doShadowDecorateFuture(final RouteContext routeContext, final LogicSQL logicSQL, final ShadowRule rule) {
ShadowRouteEngineFactory.newInstance(logicSQL).route(routeContext, rule);
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java
similarity index 95%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java
index 91e1348..cdefe2f 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine;
+package org.apache.shardingsphere.shadow.route.engine;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactory.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactory.java
similarity index 87%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactory.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactory.java
index 1f03df0..5eaa611 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactory.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactory.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine;
+package org.apache.shardingsphere.shadow.route.engine;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -24,11 +24,11 @@ import org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementConte
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.shadow.route.future.engine.dml.ShadowDeleteStatementRoutingEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.dml.ShadowInsertStatementRoutingEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.dml.ShadowSelectStatementRoutingEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.dml.ShadowUpdateStatementRoutingEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.impl.ShadowNonDMLStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.dml.ShadowDeleteStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.dml.ShadowInsertStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.dml.ShadowSelectStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.dml.ShadowUpdateStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.impl.ShadowNonDMLStatementRoutingEngine;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowAlgorithmDeterminer.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowAlgorithmDeterminer.java
similarity index 90%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowAlgorithmDeterminer.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowAlgorithmDeterminer.java
index de9d13e..822ba5a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowAlgorithmDeterminer.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowAlgorithmDeterminer.java
@@ -15,8 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner;
+package org.apache.shardingsphere.shadow.route.engine.determiner;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
/**
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactory.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
similarity index 87%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactory.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
index 03d2dcd..4e1f2b2 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactory.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner;
+package org.apache.shardingsphere.shadow.route.engine.determiner;
import org.apache.shardingsphere.shadow.algorithm.shadow.ShadowAlgorithmException;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm.ColumnShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm.NoteShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.engine.determiner.algorithm.ColumnShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.engine.determiner.algorithm.NoteShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
/**
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/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
similarity index 87%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
index 6c5b2af..22da406 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/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
@@ -15,15 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
+package org.apache.shardingsphere.shadow.route.engine.determiner.algorithm;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Collection;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java
similarity index 87%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java
index 355a83b..b99fd32 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminer.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
+package org.apache.shardingsphere.shadow.route.engine.determiner.algorithm;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Collection;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/AbstractShadowDMLStatementRouteEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
similarity index 94%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/AbstractShadowDMLStatementRouteEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
index 52f1c85..4328d5d 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/AbstractShadowDMLStatementRouteEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
import lombok.Getter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -23,10 +23,10 @@ import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
-import org.apache.shardingsphere.shadow.route.future.engine.ShadowRouteEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDeterminerFactory;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.ShadowRouteEngine;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowDeterminerFactory;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowDeleteStatementRoutingEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
similarity index 83%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowDeleteStatementRoutingEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
index 9462921..b3507b9 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowDeleteStatementRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementContext;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.util.ShadowExtractor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
@@ -61,9 +61,11 @@ public final class ShadowDeleteStatementRoutingEngine extends AbstractShadowDMLS
}
private void parseExpressionSegment(final ExpressionSegment expressionSegment, final Collection<ShadowColumnCondition> shadowColumnConditions) {
- for (ColumnSegment each : ColumnExtractor.extract(expressionSegment)) {
- ShadowExtractor.extractValues(expressionSegment, parameters).map(optional
- -> new ShadowColumnCondition(getSingleTableName(), each.getIdentifier().getValue(), optional)).ifPresent(shadowColumnConditions::add);
+ Collection<ColumnSegment> columnSegments = ColumnExtractor.extract(expressionSegment);
+ if (1 == columnSegments.size()) {
+ ColumnSegment columnSegment = columnSegments.iterator().next();
+ ShadowExtractor.extractValues(expressionSegment, parameters).ifPresent(values -> shadowColumnConditions.add(new ShadowColumnCondition(getSingleTableName(),
+ columnSegment.getIdentifier().getValue(), values)));
}
}
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/engine/dml/ShadowInsertStatementRoutingEngine.java
similarity index 91%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngine.java
index 5ad1b00..7355a96 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/engine/dml/ShadowInsertStatementRoutingEngine.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
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.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import java.util.Collection;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowSelectStatementRoutingEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
similarity index 87%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowSelectStatementRoutingEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
index 2d3d9b7..8cc3283 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowSelectStatementRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.util.ShadowExtractor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
@@ -63,9 +63,10 @@ public final class ShadowSelectStatementRoutingEngine extends AbstractShadowDMLS
private void parseExpressionSegment(final ExpressionSegment expressionSegment, final Collection<ShadowColumnCondition> shadowColumnConditions) {
Collection<ColumnSegment> columnSegments = ColumnExtractor.extract(expressionSegment);
- for (ColumnSegment each : columnSegments) {
- String columnName = each.getIdentifier().getValue();
- String tableName = extractTableName(each);
+ if (1 == columnSegments.size()) {
+ ColumnSegment columnSegment = columnSegments.iterator().next();
+ String columnName = columnSegment.getIdentifier().getValue();
+ String tableName = extractTableName(columnSegment);
ShadowExtractor.extractValues(expressionSegment, parameters).ifPresent(values -> shadowColumnConditions.add(new ShadowColumnCondition(tableName, columnName, values)));
}
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowUpdateStatementRoutingEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
similarity index 83%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowUpdateStatementRoutingEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
index 47533e8..1f1f236 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowUpdateStatementRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.util.ShadowExtractor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
@@ -61,9 +61,11 @@ public final class ShadowUpdateStatementRoutingEngine extends AbstractShadowDMLS
}
private void parseExpressionSegment(final ExpressionSegment expressionSegment, final Collection<ShadowColumnCondition> shadowColumnConditions) {
- for (ColumnSegment each : ColumnExtractor.extract(expressionSegment)) {
- ShadowExtractor.extractValues(expressionSegment, parameters).map(optional
- -> new ShadowColumnCondition(getSingleTableName(), each.getIdentifier().getValue(), optional)).ifPresent(shadowColumnConditions::add);
+ Collection<ColumnSegment> columnSegments = ColumnExtractor.extract(expressionSegment);
+ if (1 == columnSegments.size()) {
+ ColumnSegment columnSegment = columnSegments.iterator().next();
+ ShadowExtractor.extractValues(expressionSegment, parameters).ifPresent(values -> shadowColumnConditions.add(new ShadowColumnCondition(getSingleTableName(),
+ columnSegment.getIdentifier().getValue(), values)));
}
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/impl/ShadowNonDMLStatementRoutingEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngine.java
similarity index 91%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/impl/ShadowNonDMLStatementRoutingEngine.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngine.java
index 2ecc73f..96a551b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/impl/ShadowNonDMLStatementRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngine.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.impl;
+package org.apache.shardingsphere.shadow.route.engine.impl;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.ShadowRouteEngine;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDeterminerFactory;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.ShadowRouteEngine;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowDeterminerFactory;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/util/ShadowExtractor.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java
similarity index 98%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/util/ShadowExtractor.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java
index d1da98a..7a5c09e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/future/engine/util/ShadowExtractor.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.util;
+package org.apache.shardingsphere.shadow.route.engine.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/ShadowDataSourceJudgeEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/ShadowDataSourceJudgeEngine.java
deleted file mode 100644
index bda1f1c..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/ShadowDataSourceJudgeEngine.java
+++ /dev/null
@@ -1,31 +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.shadow.route.judge;
-
-/**
- * Shadow data source judge engine.
- */
-public interface ShadowDataSourceJudgeEngine {
-
- /**
- * Judge whether shadow.
- *
- * @return is shadow or not
- */
- boolean isShadow();
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceJudgeEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceJudgeEngine.java
deleted file mode 100644
index cf33d8f..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceJudgeEngine.java
+++ /dev/null
@@ -1,110 +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.shadow.route.judge.impl;
-
-import com.google.common.base.Preconditions;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
-import org.apache.shardingsphere.shadow.route.judge.ShadowDataSourceJudgeEngine;
-import org.apache.shardingsphere.shadow.route.judge.util.ShadowValueJudgeUtil;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
-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.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.AndPredicate;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Prepared shadow data source judge engine.
- */
-@RequiredArgsConstructor
-public final class PreparedShadowDataSourceJudgeEngine implements ShadowDataSourceJudgeEngine {
-
- private final ShadowRule shadowRule;
-
- private final SQLStatementContext<?> sqlStatementContext;
-
- private final List<Object> parameters;
-
- @Override
- public boolean isShadow() {
- if (sqlStatementContext instanceof InsertStatementContext) {
- Collection<ColumnSegment> columnSegments = (((InsertStatementContext) sqlStatementContext).getSqlStatement()).getColumns();
- int count = 0;
- for (ColumnSegment each : columnSegments) {
- if (each.getIdentifier().getValue().equals(shadowRule.getColumn())) {
- return ShadowValueJudgeUtil.isShadowValue(parameters.get(count));
- }
- count++;
- }
- return false;
- }
- if (!(sqlStatementContext instanceof WhereAvailable)) {
- return false;
- }
- Optional<WhereSegment> whereSegment = ((WhereAvailable) sqlStatementContext).getWhere();
- if (!whereSegment.isPresent()) {
- return false;
- }
- ExpressionSegment expression = whereSegment.get().getExpr();
- for (AndPredicate andPredicate : ExpressionExtractUtil.getAndPredicates(expression)) {
- if (judgePredicateSegments(andPredicate.getPredicates())) {
- return true;
- }
- }
- return false;
- }
-
- private boolean judgePredicateSegments(final Collection<ExpressionSegment> predicates) {
- for (ExpressionSegment each : predicates) {
- if (!(each instanceof BinaryOperationExpression)) {
- continue;
- }
- BinaryOperationExpression expression = (BinaryOperationExpression) each;
- ColumnSegment column = null;
- ExpressionSegment right = null;
- if (expression.getLeft() instanceof ColumnSegment) {
- column = (ColumnSegment) ((BinaryOperationExpression) each).getLeft();
- right = ((BinaryOperationExpression) each).getRight();
- }
- if (null == column) {
- continue;
- }
- if (column.getIdentifier().getValue().equals(shadowRule.getColumn())) {
- Preconditions.checkArgument(each instanceof BinaryOperationExpression, "must be BinaryOperationExpression");
- if (right instanceof LiteralExpressionSegment) {
- return ShadowValueJudgeUtil.isShadowValue(((LiteralExpressionSegment) right).getLiterals());
- }
- if (right instanceof ParameterMarkerExpressionSegment) {
- int parameterMarkerIndex = ((ParameterMarkerExpressionSegment) right).getParameterMarkerIndex();
- return ShadowValueJudgeUtil.isShadowValue(parameters.get(parameterMarkerIndex));
- }
- }
- }
- return false;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceJudgeEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceJudgeEngine.java
deleted file mode 100644
index ee1b0af..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceJudgeEngine.java
+++ /dev/null
@@ -1,78 +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.shadow.route.judge.impl;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.shadow.condition.ShadowCondition;
-import org.apache.shardingsphere.shadow.condition.ShadowConditionEngine;
-import org.apache.shardingsphere.shadow.route.judge.ShadowDataSourceJudgeEngine;
-import org.apache.shardingsphere.shadow.route.judge.util.ShadowValueJudgeUtil;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Simple shadow data source judge engine.
- */
-@RequiredArgsConstructor
-public final class SimpleShadowDataSourceJudgeEngine implements ShadowDataSourceJudgeEngine {
-
- private final ShadowRule shadowRule;
-
- private final SQLStatementContext<?> sqlStatementContext;
-
- @Override
- public boolean isShadow() {
- if (sqlStatementContext instanceof InsertStatementContext) {
- for (InsertValueContext each : ((InsertStatementContext) sqlStatementContext).getInsertValueContexts()) {
- if (judgeShadowSqlForInsert(each, (InsertStatementContext) sqlStatementContext)) {
- return true;
- }
- }
- return false;
- }
- if (sqlStatementContext instanceof WhereAvailable) {
- Optional<ShadowCondition> shadowCondition = new ShadowConditionEngine(shadowRule).createShadowCondition(sqlStatementContext);
- if (!shadowCondition.isPresent()) {
- return false;
- }
- List<Object> values = shadowCondition.get().getValues(Collections.emptyList());
- return !values.isEmpty() && ShadowValueJudgeUtil.isShadowValue(values.get(0));
- }
- return false;
- }
-
- private boolean judgeShadowSqlForInsert(final InsertValueContext insertValueContext, final InsertStatementContext insertStatementContext) {
- Iterator<String> descendingColumnNames = insertStatementContext.getDescendingColumnNames();
- while (descendingColumnNames.hasNext()) {
- String columnName = descendingColumnNames.next();
- if (shadowRule.getColumn().equals(columnName)) {
- int columnIndex = insertStatementContext.getColumnNames().indexOf(columnName);
- return ShadowValueJudgeUtil.isShadowValue(insertValueContext.getValue(columnIndex));
- }
- }
- return false;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtil.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtil.java
deleted file mode 100644
index c5ad4f3..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtil.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.shadow.route.judge.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Shadow value judge util.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShadowValueJudgeUtil {
-
- /**
- * Judge whether shadow value.
- *
- * @param value value to be judged
- * @return is shadow value ot not
- */
- public static boolean isShadowValue(final Object value) {
- return (value instanceof Boolean && (Boolean) value)
- || (value instanceof Integer && 1 == (Integer) value) || (value instanceof String && Boolean.parseBoolean((String) value));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 36c40b1..d05cb52 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -31,13 +31,12 @@ import org.apache.shardingsphere.shadow.rule.checker.ShadowRuleChecker;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -52,10 +51,6 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
ShardingSphereServiceLoader.register(ShadowAlgorithm.class);
}
- private final Map<String, String> shadowMappings;
-
- private final String column;
-
private final boolean enable;
private final Map<String, ShadowDataSourceRule> shadowDataSourceMappings = new LinkedHashMap<>();
@@ -66,11 +61,6 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
public ShadowRule(final ShadowRuleConfiguration shadowRuleConfig) {
enable = shadowRuleConfig.isEnable();
- column = shadowRuleConfig.getColumn();
- shadowMappings = new HashMap<>(shadowRuleConfig.getShadowDataSourceNames().size(), 1);
- for (int i = 0; i < shadowRuleConfig.getSourceDataSourceNames().size(); i++) {
- shadowMappings.put(shadowRuleConfig.getSourceDataSourceNames().get(i), shadowRuleConfig.getShadowDataSourceNames().get(i));
- }
if (enable) {
initShadowDataSourceMappings(shadowRuleConfig.getDataSources());
initShadowAlgorithmConfigurations(shadowRuleConfig.getShadowAlgorithms());
@@ -80,11 +70,6 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
public ShadowRule(final AlgorithmProvidedShadowRuleConfiguration shadowRuleConfig) {
enable = shadowRuleConfig.isEnable();
- column = shadowRuleConfig.getColumn();
- shadowMappings = new HashMap<>(shadowRuleConfig.getShadowDataSourceNames().size(), 1);
- for (int i = 0; i < shadowRuleConfig.getSourceDataSourceNames().size(); i++) {
- shadowMappings.put(shadowRuleConfig.getSourceDataSourceNames().get(i), shadowRuleConfig.getShadowDataSourceNames().get(i));
- }
if (enable) {
initShadowDataSourceMappings(shadowRuleConfig.getDataSources());
initShadowAlgorithms(shadowRuleConfig.getShadowAlgorithms());
@@ -207,11 +192,8 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>(shadowMappings.size(), 1);
- for (Entry<String, String> entry : shadowMappings.entrySet()) {
- result.put(entry.getKey(), Arrays.asList(entry.getKey(), entry.getValue()));
- }
- return result;
+ return shadowDataSourceMappings.values().stream().collect(Collectors.toMap(ShadowDataSourceRule::getSourceDataSource, each ->
+ Collections.singletonList(each.getShadowDataSource()), (key, value) -> value, () -> new HashMap<>(shadowDataSourceMappings.size(), 1)));
}
@Override
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
index fd04cb7..71b557e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.shadow.rule.checker;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java
index 3827cc9..6f58320 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.shadow.yaml.config.datasource.YamlShadowDataSou
import org.apache.shardingsphere.shadow.yaml.config.table.YamlShadowTableConfiguration;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -36,13 +35,6 @@ import java.util.Map;
@Setter
public final class YamlShadowRuleConfiguration implements YamlRuleConfiguration {
- // fixme remove three fields when the api refactoring is complete
- private String column;
-
- private List<String> sourceDataSourceNames;
-
- private List<String> shadowDataSourceNames;
-
private boolean enable;
private Map<String, YamlShadowDataSourceConfiguration> dataSources = new LinkedHashMap<>();
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapper.java
index dba813b..ca2bb54 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -38,7 +38,6 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapper implement
public YamlShadowRuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedShadowRuleConfiguration dataConfiguration) {
YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
result.setEnable(dataConfiguration.isEnable());
- parseBasicShadowRule(dataConfiguration, result);
parseDataSources(dataConfiguration, result);
parseShadowTables(dataConfiguration, result);
parseShadowAlgorithms(dataConfiguration, result);
@@ -58,16 +57,9 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapper implement
dataConfiguration.getDataSources().forEach((key, value) -> yamlConfiguration.getDataSources().put(key, dataSourceConfigurationSwapper.swapToYamlConfiguration(value)));
}
- // fixme remove method when the api refactoring is complete
- private void parseBasicShadowRule(final AlgorithmProvidedShadowRuleConfiguration dataConfiguration, final YamlShadowRuleConfiguration yamlConfiguration) {
- yamlConfiguration.setColumn(dataConfiguration.getColumn());
- yamlConfiguration.setSourceDataSourceNames(dataConfiguration.getSourceDataSourceNames());
- yamlConfiguration.setShadowDataSourceNames(dataConfiguration.getShadowDataSourceNames());
- }
-
@Override
public AlgorithmProvidedShadowRuleConfiguration swapToObject(final YamlShadowRuleConfiguration yamlConfiguration) {
- AlgorithmProvidedShadowRuleConfiguration result = createBasicAlgorithmProvidedShadowRule(yamlConfiguration);
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(yamlConfiguration.isEnable());
parseYamlDataSources(yamlConfiguration, result);
parseYamlShadowTables(yamlConfiguration, result);
@@ -82,11 +74,6 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapper implement
yamlConfiguration.getDataSources().forEach((key, value) -> dataConfiguration.getDataSources().put(key, dataSourceConfigurationSwapper.swapToObject(value)));
}
- // fixme remove method when the api refactoring is complete
- private AlgorithmProvidedShadowRuleConfiguration createBasicAlgorithmProvidedShadowRule(final YamlShadowRuleConfiguration yamlConfiguration) {
- return new AlgorithmProvidedShadowRuleConfiguration(yamlConfiguration.getColumn(), yamlConfiguration.getSourceDataSourceNames(), yamlConfiguration.getShadowDataSourceNames());
- }
-
@Override
public Class<AlgorithmProvidedShadowRuleConfiguration> getTypeClass() {
return AlgorithmProvidedShadowRuleConfiguration.class;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationYamlSwapper.java
index 2a5f7ac..86d2a34 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationYamlSwapper.java
@@ -40,7 +40,6 @@ public final class ShadowRuleConfigurationYamlSwapper implements YamlRuleConfigu
public YamlShadowRuleConfiguration swapToYamlConfiguration(final ShadowRuleConfiguration dataConfiguration) {
YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
result.setEnable(dataConfiguration.isEnable());
- parseBasicShadowRule(dataConfiguration, result);
parseDataSources(dataConfiguration, result);
parseShadowTables(dataConfiguration, result);
parseShadowAlgorithms(dataConfiguration, result);
@@ -59,16 +58,10 @@ public final class ShadowRuleConfigurationYamlSwapper implements YamlRuleConfigu
dataConfiguration.getDataSources().forEach((key, value) -> yamlConfiguration.getDataSources().put(key, dataSourceConfigurationSwapper.swapToYamlConfiguration(value)));
}
- // fixme remove method when the api refactoring is complete
- private void parseBasicShadowRule(final ShadowRuleConfiguration dataConfiguration, final YamlShadowRuleConfiguration yamlConfiguration) {
- yamlConfiguration.setColumn(dataConfiguration.getColumn());
- yamlConfiguration.setSourceDataSourceNames(dataConfiguration.getSourceDataSourceNames());
- yamlConfiguration.setShadowDataSourceNames(dataConfiguration.getShadowDataSourceNames());
- }
-
@Override
public ShadowRuleConfiguration swapToObject(final YamlShadowRuleConfiguration yamlConfiguration) {
- ShadowRuleConfiguration result = createBasicShadowRule(yamlConfiguration);
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
+ result.setEnable(yamlConfiguration.isEnable());
parseYamlDataSources(yamlConfiguration, result);
parseYamlShadowTables(yamlConfiguration, result);
parseYamlShadowAlgorithms(yamlConfiguration, result);
@@ -87,11 +80,6 @@ public final class ShadowRuleConfigurationYamlSwapper implements YamlRuleConfigu
yamlConfiguration.getDataSources().forEach((key, value) -> dataConfiguration.getDataSources().put(key, dataSourceConfigurationSwapper.swapToObject(value)));
}
- // fixme remove method when the api refactoring is complete
- private ShadowRuleConfiguration createBasicShadowRule(final YamlShadowRuleConfiguration yamlConfiguration) {
- return new ShadowRuleConfiguration(yamlConfiguration.getColumn(), yamlConfiguration.getSourceDataSourceNames(), yamlConfiguration.getShadowDataSourceNames(), yamlConfiguration.isEnable());
- }
-
@Override
public Class<ShadowRuleConfiguration> getTypeClass() {
return ShadowRuleConfiguration.class;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator
deleted file mode 100644
index a66c75d..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator
+++ /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.shadow.rewrite.context.ShadowSQLRewriteContextDecorator
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
index bf40598..6a6d80a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.shadow.algorithm.shadow.column;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
import org.junit.Before;
import org.junit.Test;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
index 8252807..156547f 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.shadow.algorithm.shadow.note;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
import org.junit.Before;
import org.junit.Test;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
index 29f04f7..70627a6 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
@@ -28,7 +28,6 @@ import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class AlgorithmProvidedShadowRuleConfigurationCheckerTest {
@@ -36,37 +35,11 @@ public final class AlgorithmProvidedShadowRuleConfigurationCheckerTest {
ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
}
- @SuppressWarnings({"rawtypes", "unchecked"})
+ @SuppressWarnings("rawtypes")
@Test
public void assertValidCheck() {
- AlgorithmProvidedShadowRuleConfiguration config = createValidConfiguration();
+ AlgorithmProvidedShadowRuleConfiguration config = mock(AlgorithmProvidedShadowRuleConfiguration.class);
RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, Collections.singletonList(config)).get(config);
assertThat(checker, instanceOf(AlgorithmProvidedShadowRuleConfigurationChecker.class));
- checker.check("test", config);
- }
-
- private AlgorithmProvidedShadowRuleConfiguration createValidConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = mock(AlgorithmProvidedShadowRuleConfiguration.class);
- when(result.getColumn()).thenReturn("id");
- when(result.getSourceDataSourceNames()).thenReturn(Collections.singletonList("ds0"));
- when(result.getShadowDataSourceNames()).thenReturn(Collections.singletonList("shadow0"));
- return result;
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test(expected = IllegalStateException.class)
- public void assertInvalidCheck() {
- AlgorithmProvidedShadowRuleConfiguration config = createInvalidConfiguration();
- RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, Collections.singletonList(config)).get(config);
- assertThat(checker, instanceOf(AlgorithmProvidedShadowRuleConfigurationChecker.class));
- checker.check("test", config);
- }
-
- private AlgorithmProvidedShadowRuleConfiguration createInvalidConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = mock(AlgorithmProvidedShadowRuleConfiguration.class);
- when(result.getColumn()).thenReturn("");
- when(result.getSourceDataSourceNames()).thenReturn(Collections.emptyList());
- when(result.getShadowDataSourceNames()).thenReturn(Collections.emptyList());
- return result;
}
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
index feb2b97..9980b88 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
@@ -28,7 +28,6 @@ import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class ShadowRuleConfigurationCheckerTest {
@@ -39,34 +38,9 @@ public final class ShadowRuleConfigurationCheckerTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertValidCheck() {
- ShadowRuleConfiguration config = createValidConfiguration();
+ ShadowRuleConfiguration config = mock(ShadowRuleConfiguration.class);
RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, Collections.singletonList(config)).get(config);
assertThat(checker, instanceOf(ShadowRuleConfigurationChecker.class));
checker.check("test", config);
}
-
- private ShadowRuleConfiguration createValidConfiguration() {
- ShadowRuleConfiguration result = mock(ShadowRuleConfiguration.class);
- when(result.getColumn()).thenReturn("id");
- when(result.getSourceDataSourceNames()).thenReturn(Collections.singletonList("ds0"));
- when(result.getShadowDataSourceNames()).thenReturn(Collections.singletonList("shadow0"));
- return result;
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test(expected = IllegalStateException.class)
- public void assertInvalidCheck() {
- ShadowRuleConfiguration config = createInvalidConfiguration();
- RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, Collections.singletonList(config)).get(config);
- assertThat(checker, instanceOf(ShadowRuleConfigurationChecker.class));
- checker.check("test", config);
- }
-
- private ShadowRuleConfiguration createInvalidConfiguration() {
- ShadowRuleConfiguration result = mock(ShadowRuleConfiguration.class);
- when(result.getColumn()).thenReturn("");
- when(result.getSourceDataSourceNames()).thenReturn(Collections.emptyList());
- when(result.getShadowDataSourceNames()).thenReturn(Collections.emptyList());
- return result;
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngineTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngineTest.java
deleted file mode 100644
index f83308a..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngineTest.java
+++ /dev/null
@@ -1,46 +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.shadow.condition;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-
-public final class ShadowConditionEngineTest {
-
- @Test
- public void assertGetConditionValues() {
- List<Object> actual = new ShadowCondition("col", 0, 0, new LiteralExpressionSegment(0, 0, 1)).getValues(Collections.emptyList());
- assertThat(actual.size(), is(1));
- assertThat(actual.get(0), is(1));
- }
-
- @Test
- public void assertCreateShadowCondition() {
- assertFalse(new ShadowConditionEngine(mock(ShadowRule.class)).createShadowCondition(mock(SQLStatementContext.class)).isPresent());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionTest.java
deleted file mode 100644
index 6c919fe..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/condition/ShadowConditionTest.java
+++ /dev/null
@@ -1,36 +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.shadow.condition;
-
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class ShadowConditionTest {
-
- @Test
- public void assertGetValues() {
- ShadowCondition shadowCondition = new ShadowCondition("a", 0, 10, new LiteralExpressionSegment(0, 10, "result"));
- assertThat(shadowCondition.getValues(Arrays.asList(0, 1, 2)), is(Collections.singletonList("result")));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java
deleted file mode 100644
index ba94d74..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.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.shadow.rewrite.context;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
-public final class ShadowSQLRewriteContextDecoratorTest {
-
- private ShadowSQLRewriteContextDecorator shadowSQLRewriteContextDecorator;
-
- @Before
- public void init() {
- shadowSQLRewriteContextDecorator = new ShadowSQLRewriteContextDecorator();
- }
-
- @Test
- public void assertGetOrder() {
- assertThat(shadowSQLRewriteContextDecorator.getOrder(), is(40));
- }
-
- @Test
- public void assertGetTypeClass() {
- assertNotNull(shadowSQLRewriteContextDecorator.getTypeClass());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilderTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilderTest.java
deleted file mode 100644
index e99086f..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/ShadowParameterRewriterBuilderTest.java
+++ /dev/null
@@ -1,42 +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.shadow.rewrite.parameter;
-
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.Mockito.mock;
-import static org.junit.Assert.assertThat;
-
-public final class ShadowParameterRewriterBuilderTest {
-
- private ShadowParameterRewriterBuilder shadowParameterRewriterBuilder;
-
- @Before
- public void init() {
- shadowParameterRewriterBuilder = new ShadowParameterRewriterBuilder(mock(ShadowRule.class));
- }
-
- @Test
- public void assertGetParameterRewriters() {
- assertThat(shadowParameterRewriterBuilder.getParameterRewriters(mock(ShardingSphereSchema.class)).size(), is(3));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriterTest.java
deleted file mode 100644
index 1ad7a93..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowInsertValueParameterRewriterTest.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.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShadowInsertValueParameterRewriterTest {
-
- private ShadowInsertValueParameterRewriter shadowInsertValueParameterRewriter;
-
- private InsertStatementContext insertStatementContext;
-
- @Before
- public void init() {
- String shadowColumn = "shadow_column";
- initShadowInsertValueParameterRewriter(shadowColumn);
- mockInsertStatementContext(shadowColumn);
- }
-
- private void mockInsertStatementContext(final String shadowColumn) {
- insertStatementContext = mock(InsertStatementContext.class);
- when(insertStatementContext.getInsertColumnNames()).thenReturn(Collections.singletonList(shadowColumn));
- }
-
- private void initShadowInsertValueParameterRewriter(final String shadowColumn) {
- shadowInsertValueParameterRewriter = new ShadowInsertValueParameterRewriter();
- shadowInsertValueParameterRewriter.setShadowRule(mockShadowRule(shadowColumn));
- }
-
- private ShadowRule mockShadowRule(final String shadowColumn) {
- ShadowRule result = mock(ShadowRule.class);
- when(result.getColumn()).thenReturn(shadowColumn);
- return result;
- }
-
- @Test
- public void assertIsNeedRewriteForShadow() {
- assertTrue(shadowInsertValueParameterRewriter.isNeedRewriteForShadow(insertStatementContext));
- }
-
- @Test
- public void assertRewrite() {
- shadowInsertValueParameterRewriter.rewrite(mock(GroupedParameterBuilder.class), insertStatementContext, Collections.emptyList());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriterTest.java
deleted file mode 100644
index 01df2de..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowPredicateParameterRewriterTest.java
+++ /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.
- */
-
-package org.apache.shardingsphere.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.LinkedList;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class ShadowPredicateParameterRewriterTest {
-
- private ShadowPredicateParameterRewriter shadowPredicateParameterRewriter;
-
- @Before
- public void init() {
- shadowPredicateParameterRewriter = new ShadowPredicateParameterRewriter();
- }
-
- @Test
- public void assertIsNeedRewriteForShadow() {
- assertTrue(shadowPredicateParameterRewriter.isNeedRewriteForShadow(mock(SQLStatementContext.class)));
- }
-
- @Test
- public void assertRewrite() {
- shadowPredicateParameterRewriter.rewrite(mock(ParameterBuilder.class), mock(SQLStatementContext.class), new LinkedList<>());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriterTest.java
deleted file mode 100644
index 4552266..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/parameter/impl/ShadowUpdateValueParameterRewriterTest.java
+++ /dev/null
@@ -1,89 +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.shadow.rewrite.parameter.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
-import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShadowUpdateValueParameterRewriterTest {
-
- private ShadowUpdateValueParameterRewriter shadowUpdateValueParameterRewriter;
-
- private UpdateStatementContext updateStatementContext;
-
- @Before
- public void init() {
- String shadowColumn = "shadow_column";
- initShadowUpdateValueParameterRewriter(shadowColumn);
- mockUpdateStatementContext(shadowColumn);
- }
-
- private void mockUpdateStatementContext(final String shadowColumn) {
- UpdateStatement updateStatement = new MySQLUpdateStatement();
- updateStatement.setSetAssignment(createSetAssignmentSegment(shadowColumn));
- updateStatementContext = new UpdateStatementContext(updateStatement, DefaultSchema.LOGIC_NAME);
- }
-
- private SetAssignmentSegment createSetAssignmentSegment(final String shadowColumn) {
- List<ColumnSegment> columns = new LinkedList<>();
- columns.add(new ColumnSegment(0, 15, new IdentifierValue(shadowColumn)));
- AssignmentSegment assignment = new ColumnAssignmentSegment(0, 15, columns, mock(ExpressionSegment.class));
- return new SetAssignmentSegment(0, 20, Collections.singletonList(assignment));
- }
-
- private void initShadowUpdateValueParameterRewriter(final String shadowColumn) {
- shadowUpdateValueParameterRewriter = new ShadowUpdateValueParameterRewriter();
- shadowUpdateValueParameterRewriter.setShadowRule(mockShadowRule(shadowColumn));
- }
-
- private ShadowRule mockShadowRule(final String shadowColumn) {
- ShadowRule result = mock(ShadowRule.class);
- when(result.getColumn()).thenReturn(shadowColumn);
- return result;
- }
-
- @Test
- public void assertIsNeedRewriteForShadow() {
- assertTrue(shadowUpdateValueParameterRewriter.isNeedRewriteForShadow(updateStatementContext));
- }
-
- @Test
- public void assertRewrite() {
- shadowUpdateValueParameterRewriter.rewrite(mock(GroupedParameterBuilder.class), updateStatementContext, Collections.emptyList());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilderTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilderTest.java
deleted file mode 100644
index f9d26f4..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/ShadowTokenGenerateBuilderTest.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.shadow.rewrite.token;
-
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-
-public final class ShadowTokenGenerateBuilderTest {
-
- private ShadowTokenGenerateBuilder shadowTokenGenerateBuilder;
-
- @Before
- public void init() {
- shadowTokenGenerateBuilder = new ShadowTokenGenerateBuilder(mock(ShadowRule.class));
- }
-
- @Test
- public void assertGetSQLTokenGenerators() {
- assertThat(shadowTokenGenerateBuilder.getSQLTokenGenerators().size(), is(4));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGeneratorTest.java
deleted file mode 100644
index abe444f..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGeneratorTest.java
+++ /dev/null
@@ -1,94 +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.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShadowInsertColumnTokenGeneratorTest {
-
- private ShadowInsertColumnTokenGenerator shadowInsertColumnTokenGenerator;
-
- private InsertStatementContext insertStatementContext;
-
- @Before
- public void init() {
- String shadowColumn = "shadow_column";
- initShadowInsertColumnTokenGenerator(shadowColumn);
- mockInsertStatementContext(shadowColumn);
- }
-
- private void mockInsertStatementContext(final String shadowColumn) {
- InsertStatement insertStatement = mock(InsertStatement.class);
- InsertColumnsSegment insertColumnsSegment = mockInsertColumnsSegment(shadowColumn);
- insertStatement.setInsertColumns(insertColumnsSegment);
- when(insertStatement.getInsertColumns()).thenReturn(Optional.of(insertColumnsSegment));
- insertStatementContext = mock(InsertStatementContext.class);
- when(insertStatementContext.getSqlStatement()).thenReturn(insertStatement);
- }
-
- private InsertColumnsSegment mockInsertColumnsSegment(final String shadowColumn) {
- InsertColumnsSegment insertColumnsSegment = mock(InsertColumnsSegment.class);
- when(insertColumnsSegment.getColumns()).thenReturn(initColumns(shadowColumn));
- return insertColumnsSegment;
- }
-
- private Collection<ColumnSegment> initColumns(final String shadowColumn) {
- Collection<ColumnSegment> columns = new LinkedList<>();
- columns.add(new ColumnSegment(1, 6, new IdentifierValue(shadowColumn)));
- columns.add(new ColumnSegment(7, 8, new IdentifierValue("a")));
- return columns;
- }
-
- private void initShadowInsertColumnTokenGenerator(final String shadowColumn) {
- shadowInsertColumnTokenGenerator = new ShadowInsertColumnTokenGenerator();
- shadowInsertColumnTokenGenerator.setShadowRule(mockShadowRule(shadowColumn));
- }
-
- private ShadowRule mockShadowRule(final String shadowColumn) {
- ShadowRule shadowRule = mock(ShadowRule.class);
- when(shadowRule.getColumn()).thenReturn(shadowColumn);
- return shadowRule;
- }
-
- @Test
- public void assertIsGenerateSQLTokenForShadow() {
- assertTrue(shadowInsertColumnTokenGenerator.isGenerateSQLTokenForShadow(insertStatementContext));
- }
-
- @Test
- public void assertGenerateSQLTokens() {
- assertThat(shadowInsertColumnTokenGenerator.generateSQLTokens(insertStatementContext).iterator().next().toString(), is(""));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGeneratorTest.java
deleted file mode 100644
index c9d6d70..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertValuesTokenGeneratorTest.java
+++ /dev/null
@@ -1,91 +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.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShadowInsertValuesTokenGeneratorTest {
-
- private ShadowInsertValuesTokenGenerator shadowInsertValuesTokenGenerator;
-
- private InsertStatementContext insertStatementContext;
-
- @Before
- public void init() {
- String shadowColumn = "shadow_column";
- initShadowInsertValuesTokenGenerator(shadowColumn);
- mockInsertStatementContext(shadowColumn);
- }
-
- private void mockInsertStatementContext(final String shadowColumn) {
- InsertStatement insertStatement = mock(InsertStatement.class);
- when(insertStatement.getValues()).thenReturn(createValues());
- insertStatementContext = mock(InsertStatementContext.class);
- when(insertStatementContext.getSqlStatement()).thenReturn(insertStatement);
- when(insertStatementContext.getInsertColumnNames()).thenReturn(createInsertColumnNames(shadowColumn));
- }
-
- private Collection<InsertValuesSegment> createValues() {
- List<InsertValuesSegment> values = new LinkedList<>();
- values.add(mock(InsertValuesSegment.class));
- return values;
- }
-
- private List<String> createInsertColumnNames(final String shadowColumn) {
- List<String> insertColumnNames = new LinkedList<>();
- insertColumnNames.add(shadowColumn);
- insertColumnNames.add("aaa");
- return insertColumnNames;
- }
-
- private void initShadowInsertValuesTokenGenerator(final String shadowColumn) {
- shadowInsertValuesTokenGenerator = new ShadowInsertValuesTokenGenerator();
- shadowInsertValuesTokenGenerator.setShadowRule(mockShadowRule(shadowColumn));
- shadowInsertValuesTokenGenerator.setPreviousSQLTokens(new LinkedList<>());
- }
-
- private ShadowRule mockShadowRule(final String shadowColumn) {
- ShadowRule shadowRule = mock(ShadowRule.class);
- when(shadowRule.getColumn()).thenReturn(shadowColumn);
- return shadowRule;
- }
-
- @Test
- public void assertIsGenerateSQLTokenForShadow() {
- assertTrue(shadowInsertValuesTokenGenerator.isGenerateSQLTokenForShadow(insertStatementContext));
- }
-
- @Test
- public void assertGenerateSQLToken() {
- assertNotNull(shadowInsertValuesTokenGenerator.generateSQLToken(insertStatementContext));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGeneratorTest.java
deleted file mode 100644
index 330ec0b..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowPredicateColumnTokenGeneratorTest.java
+++ /dev/null
@@ -1,49 +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.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.mock;
-
-public final class ShadowPredicateColumnTokenGeneratorTest {
-
- private ShadowPredicateColumnTokenGenerator shadowPredicateColumnTokenGenerator;
-
- private SQLStatementContext<? extends SQLStatement> sqlStatementContext;
-
- @Before
- public void init() {
- shadowPredicateColumnTokenGenerator = new ShadowPredicateColumnTokenGenerator();
- sqlStatementContext = mock(SQLStatementContext.class);
- }
-
- @Test
- public void assertIsGenerateSQLTokenForShadow() {
- assertFalse(shadowPredicateColumnTokenGenerator.isGenerateSQLTokenForShadow(sqlStatementContext));
- }
-
- @Test(expected = ClassCastException.class)
- public void assertGenerateSQLTokens() {
- shadowPredicateColumnTokenGenerator.generateSQLTokens(sqlStatementContext);
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGeneratorTest.java
deleted file mode 100644
index 7722f1d..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowUpdateColumnTokenGeneratorTest.java
+++ /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.
- */
-
-package org.apache.shardingsphere.shadow.rewrite.token.generator.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShadowUpdateColumnTokenGeneratorTest {
-
- private ShadowUpdateColumnTokenGenerator shadowUpdateColumnTokenGenerator;
-
- private UpdateStatementContext updateStatementContext;
-
- @Before
- public void init() {
- String shadowColumn = "shadow_column";
- initShadowUpdateColumnTokenGenerator(shadowColumn);
- mockUpdateStatementContext(shadowColumn);
- }
-
- private void mockUpdateStatementContext(final String shadowColumn) {
- UpdateStatement updateStatement = new MySQLUpdateStatement();
- updateStatement.setSetAssignment(createSetAssignmentSegment(shadowColumn));
- updateStatementContext = new UpdateStatementContext(updateStatement, DefaultSchema.LOGIC_NAME);
- }
-
- private SetAssignmentSegment createSetAssignmentSegment(final String shadowColumn) {
- Collection<AssignmentSegment> assignmentSegments = new LinkedList<>();
- assignmentSegments.add(createAssignmentSegment(0, 15, new IdentifierValue(shadowColumn)));
- assignmentSegments.add(createAssignmentSegment(16, 30, new IdentifierValue("column")));
- return new SetAssignmentSegment(0, 30, assignmentSegments);
- }
-
- private AssignmentSegment createAssignmentSegment(final int startIndex, final int stopIndex, final IdentifierValue identifierValue) {
- List<ColumnSegment> columns = new LinkedList<>();
- columns.add(new ColumnSegment(startIndex, stopIndex, identifierValue));
- AssignmentSegment result = new ColumnAssignmentSegment(startIndex, stopIndex, columns, mock(ExpressionSegment.class));
- return result;
- }
-
- private void initShadowUpdateColumnTokenGenerator(final String shadowColumn) {
- shadowUpdateColumnTokenGenerator = new ShadowUpdateColumnTokenGenerator();
- shadowUpdateColumnTokenGenerator.setShadowRule(mockShadowRule(shadowColumn));
- }
-
- private ShadowRule mockShadowRule(final String shadowColumn) {
- ShadowRule shadowRule = mock(ShadowRule.class);
- when(shadowRule.getColumn()).thenReturn(shadowColumn);
- return shadowRule;
- }
-
- @Test
- public void assertIsGenerateSQLTokenForShadow() {
- assertTrue(shadowUpdateColumnTokenGenerator.isGenerateSQLTokenForShadow(updateStatementContext));
- }
-
- @Test
- public void assertGenerateSQLTokens() {
- assertThat(shadowUpdateColumnTokenGenerator.generateSQLTokens(updateStatementContext).iterator().next().toString(), is(""));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesTokenTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesTokenTest.java
deleted file mode 100644
index 7116b1e..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/token/pojo/ShadowInsertValuesTokenTest.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.shadow.rewrite.token.pojo;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class ShadowInsertValuesTokenTest {
-
- private ShadowInsertValuesToken shadowInsertValuesToken;
-
- @Before
- public void init() {
- shadowInsertValuesToken = new ShadowInsertValuesToken(0, 10);
- }
-
- @Test
- public void assertToString() {
- assertThat(shadowInsertValuesToken.toString(), is(""));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java
deleted file mode 100644
index 9c0fe4c..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java
+++ /dev/null
@@ -1,191 +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.shadow.route;
-
-import org.apache.shardingsphere.infra.binder.LogicSQL;
-import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
-import org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.route.SQLRouter;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.infra.route.context.RouteMapper;
-import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateTableStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class ShadowSQLRouterTest {
-
- private static final String SHADOW_COLUMN = "is_shadow";
-
- private static final String ACTUAL_DATASOURCE = "ds";
-
- private static final String SHADOW_DATASOURCE = "shadow_ds";
-
- private ShadowSQLRouter sqlRouter;
-
- private ShadowRule rule;
-
- static {
- ShardingSphereServiceLoader.register(SQLRouter.class);
- }
-
- @Before
- public void setUp() {
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration(SHADOW_COLUMN, Collections.singletonList(ACTUAL_DATASOURCE), Collections.singletonList(SHADOW_DATASOURCE));
- rule = new ShadowRule(shadowRuleConfig);
- sqlRouter = (ShadowSQLRouter) OrderedSPIRegistry.getRegisteredServices(SQLRouter.class, Collections.singleton(rule)).get(rule);
- }
-
- @Test
- public void assertCreateRouteContextToShadowDataSource() {
- LogicSQL logicSQL = new LogicSQL(mockSQLStatementContextForShadow(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(SHADOW_DATASOURCE));
- }
-
- @Test
- public void assertCreateRouteContextToActualDataSource() {
- LogicSQL logicSQL = new LogicSQL(mockSQLStatementContext(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(ACTUAL_DATASOURCE));
- }
-
- @Test
- public void assertCreateRouteContextForNonDMLStatement() {
- LogicSQL logicSQL = new LogicSQL(mockNonDMLSQLStatementContext(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- assertThat(actual.getRouteUnits().size(), is(2));
- assertTrue(actual.getActualDataSourceNames().contains(SHADOW_DATASOURCE));
- assertTrue(actual.getActualDataSourceNames().contains(ACTUAL_DATASOURCE));
- }
-
- @Test
- public void assertDecorateRouteContextToShadowDataSource() {
- RouteContext actual = new RouteContext();
- actual.getRouteUnits().add(mockRouteUnit());
- LogicSQL logicSQL = new LogicSQL(mockSQLStatementContextForShadow(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(
- "logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- assertThat(actual.getRouteUnits().size(), is(1));
- assertTrue(actual.getActualDataSourceNames().contains(SHADOW_DATASOURCE));
- }
-
- @Test
- public void assertDecorateRouteContextToActualDataSource() {
- RouteContext actual = new RouteContext();
- actual.getRouteUnits().add(mockRouteUnit());
- LogicSQL logicSQL = new LogicSQL(mockSQLStatementContext(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(ACTUAL_DATASOURCE));
- }
-
- @Test
- public void assertDecorateRouteContextNonDMLStatement() {
- RouteContext actual = new RouteContext();
- actual.getRouteUnits().add(mockRouteUnit());
- LogicSQL logicSQL = new LogicSQL(mockNonDMLSQLStatementContext(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- assertThat(actual.getRouteUnits().size(), is(2));
- assertTrue(actual.getActualDataSourceNames().contains(SHADOW_DATASOURCE));
- assertTrue(actual.getActualDataSourceNames().contains(ACTUAL_DATASOURCE));
- }
-
- @Test
- public void assertDecorateRouteContextWithTableMapper() {
- RouteContext actual = new RouteContext();
- actual.getRouteUnits().add(mockRouteUnit());
- LogicSQL logicSQL = new LogicSQL(mockSQLStatementContextForShadow(), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, mock(ShardingSphereSchema.class));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
- assertThat(actual.getRouteUnits().size(), is(1));
- assertTrue(actual.getActualDataSourceNames().contains(SHADOW_DATASOURCE));
- Collection<RouteMapper> tableMappers = actual.getRouteUnits().iterator().next().getTableMappers();
- assertThat(tableMappers.size(), is(1));
- assertThat(tableMappers.iterator().next().getActualName(), is("table_0"));
- assertThat(tableMappers.iterator().next().getLogicName(), is("table"));
- }
-
- private InsertStatementContext mockSQLStatementContextForShadow() {
- InsertStatementContext result = mock(InsertStatementContext.class);
- when(result.getSqlStatement()).thenReturn(mock(MySQLInsertStatement.class));
- when(result.getDescendingColumnNames()).thenReturn(Collections.singletonList(SHADOW_COLUMN).iterator());
- when(result.getColumnNames()).thenReturn(Collections.singletonList(SHADOW_COLUMN));
- InsertValueContext insertValueContext = mock(InsertValueContext.class);
- when(insertValueContext.getValue(0)).thenReturn(true);
- when(result.getInsertValueContexts()).thenReturn(Collections.singletonList(insertValueContext));
- return result;
- }
-
- private InsertStatementContext mockSQLStatementContext() {
- InsertStatementContext result = mock(InsertStatementContext.class);
- when(result.getSqlStatement()).thenReturn(mock(MySQLInsertStatement.class));
- return result;
- }
-
- private CreateTableStatementContext mockNonDMLSQLStatementContext() {
- CreateTableStatementContext result = mock(CreateTableStatementContext.class);
- when(result.getSqlStatement()).thenReturn(mock(MySQLCreateTableStatement.class));
- return result;
- }
-
- private RouteUnit mockRouteUnit() {
- return new RouteUnit(new RouteMapper(ACTUAL_DATASOURCE, ACTUAL_DATASOURCE), Collections.singletonList(new RouteMapper("table", "table_0")));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactoryTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java
similarity index 92%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactoryTest.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java
index 7802c51..afbc37e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/ShadowRouteEngineFactoryTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine;
+package org.apache.shardingsphere.shadow.route.engine;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.infra.binder.LogicSQL;
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.dml.ShadowInsertStatementRoutingEngine;
+import org.apache.shardingsphere.shadow.route.engine.dml.ShadowInsertStatementRoutingEngine;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
import org.junit.Test;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactoryTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactoryTest.java
similarity index 83%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactoryTest.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactoryTest.java
index d9ede2a..ed2ceea 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/ShadowDeterminerFactoryTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactoryTest.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner;
+package org.apache.shardingsphere.shadow.route.engine.determiner;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm.ColumnShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm.NoteShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.engine.determiner.algorithm.ColumnShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.engine.determiner.algorithm.NoteShadowAlgorithmDeterminer;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
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/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
similarity index 89%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
index 2c4ef64..4a12c82 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/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
@@ -15,23 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
+package org.apache.shardingsphere.shadow.route.engine.determiner.algorithm;
import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Before;
import org.junit.Test;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -72,7 +71,7 @@ public final class ColumnShadowAlgorithmDeterminerTest {
}
private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("ds_shadow", "ds1_shadow"));
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(true);
result.setDataSources(createDataSources());
result.setTables(createTables());
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
similarity index 90%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
index a791f1b..edfc16d 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
@@ -15,22 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.determiner.algorithm;
+package org.apache.shardingsphere.shadow.route.engine.determiner.algorithm;
import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.route.engine.determiner.ShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Before;
import org.junit.Test;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -71,7 +70,7 @@ public final class NoteShadowAlgorithmDeterminerTest {
}
private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("ds1_shadow", "ds1_shadow"));
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(true);
result.setDataSources(createDataSources());
result.setTables(createTables());
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngineTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
similarity index 96%
rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngineTest.java
rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
index 60aaf9b..7fc9631 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/dml/ShadowInsertStatementRoutingEngineTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.route.future.engine.dml;
+package org.apache.shardingsphere.shadow.route.engine.dml;
import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
@@ -26,8 +26,8 @@ import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadow
import org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
-import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowColumnCondition;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
@@ -121,7 +121,7 @@ public final class ShadowInsertStatementRoutingEngineTest {
}
private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("shadow_ds", "shadow_ds1"));
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(true);
result.setDataSources(createDataSources());
result.setTables(createTables());
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceRouterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceRouterTest.java
deleted file mode 100644
index 9507b25..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/PreparedShadowDataSourceRouterTest.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.shadow.route.judge.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dml.PostgreSQLSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.dml.SQL92SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerSelectStatement;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class PreparedShadowDataSourceRouterTest {
-
- @Test
- public void isShadowSQL() {
- ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "shadow"));
- InsertStatement insertStatement = new MySQLInsertStatement();
- insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
- InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0,
- Arrays.asList(new ColumnSegment(0, 0, new IdentifierValue("id")), new ColumnSegment(0, 0, new IdentifierValue("name")), new ColumnSegment(0, 0, new IdentifierValue("shadow"))));
- insertStatement.setInsertColumns(insertColumnsSegment);
- InsertStatementContext insertStatementContext = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry", 3, true), insertStatement, schema);
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("shadow_ds"));
- ShadowRule shadowRule = new ShadowRule(shadowRuleConfig);
- PreparedShadowDataSourceJudgeEngine preparedShadowDataSourceRouter = new PreparedShadowDataSourceJudgeEngine(shadowRule, insertStatementContext, Arrays.asList(1, "Tom", true));
- assertTrue("should be shadow", preparedShadowDataSourceRouter.isShadow());
- }
-
- private InsertStatementContext createInsertStatementContext(final List<Object> parameters, final InsertStatement insertStatement, final ShardingSphereSchema schema) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaData.getSchema()).thenReturn(schema);
- return new InsertStatementContext(Collections.singletonMap(DefaultSchema.LOGIC_NAME, metaData), parameters, insertStatement, DefaultSchema.LOGIC_NAME);
- }
-
- @Test
- public void isShadowSQLInLiteralExpressionForMySQL() {
- isShadowSQLInLiteralExpression(new MySQLSelectStatement());
- }
-
- @Test
- public void isShadowSQLInLiteralExpressionForOracle() {
- isShadowSQLInLiteralExpression(new OracleSelectStatement());
- }
-
- @Test
- public void isShadowSQLInLiteralExpressionForPostgreSQL() {
- isShadowSQLInLiteralExpression(new PostgreSQLSelectStatement());
- }
-
- @Test
- public void isShadowSQLInLiteralExpressionForSQL92() {
- isShadowSQLInLiteralExpression(new SQL92SelectStatement());
- }
-
- @Test
- public void isShadowSQLInLiteralExpressionForSQLServer() {
- isShadowSQLInLiteralExpression(new SQLServerSelectStatement());
- }
-
- private void isShadowSQLInLiteralExpression(final SelectStatement selectStatement) {
- ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "shadow"));
- ShadowRuleConfiguration shadowRuleConfig = new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("shadow_ds"));
- ShadowRule shadowRule = new ShadowRule(shadowRuleConfig);
- PreparedShadowDataSourceJudgeEngine preparedShadowDataSourceRouter = new PreparedShadowDataSourceJudgeEngine(shadowRule,
- selectStatementContext(selectStatement), Arrays.asList(1, "Tom", true));
- assertTrue("should be shadow", preparedShadowDataSourceRouter.isShadow());
- }
-
- private SelectStatementContext selectStatementContext(final SelectStatement selectStatement) {
- BinaryOperationExpression left = new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("id")), new ParameterMarkerExpressionSegment(0, 0, 0), "=", "id=?");
- BinaryOperationExpression right = new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("shadow")), new LiteralExpressionSegment(45, 48, "true"), "=", "shadow=true");
- BinaryOperationExpression binaryOperationExpression = new BinaryOperationExpression(0, 0, left, right, "and", "id=? and shadow=true");
- WhereSegment whereSegment = new WhereSegment(0, 0, binaryOperationExpression);
- selectStatement.setWhere(whereSegment);
- ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaData.getSchema()).thenReturn(schema);
- selectStatement.setProjections(new ProjectionsSegment(0, 0));
- return new SelectStatementContext(Collections.singletonMap(DefaultSchema.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultSchema.LOGIC_NAME);
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceRouterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceRouterTest.java
deleted file mode 100644
index 52701b9..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/impl/SimpleShadowDataSourceRouterTest.java
+++ /dev/null
@@ -1,174 +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.shadow.route.judge.impl;
-
-import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleInsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dml.PostgreSQLInsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dml.PostgreSQLSelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.dml.SQL92InsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.dml.SQL92SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerInsertStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerSelectStatement;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class SimpleShadowDataSourceRouterTest {
-
- private ShardingSphereSchema schema;
-
- private ShadowRule shadowRule;
-
- @Before
- public void setUp() {
- schema = mock(ShardingSphereSchema.class);
- when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "shadow"));
- shadowRule = new ShadowRule(new ShadowRuleConfiguration("shadow", Collections.singletonList("ds"), Collections.singletonList("shadow_ds")));
- }
-
- @Test
- public void judgeForMySQLInsert() {
- judgeForInsert(new MySQLInsertStatement());
- }
-
- @Test
- public void judgeForOracleInsert() {
- judgeForInsert(new OracleInsertStatement());
- }
-
- @Test
- public void judgeForPostgreSQLInsert() {
- judgeForInsert(new PostgreSQLInsertStatement());
- }
-
- @Test
- public void judgeForSQL92Insert() {
- judgeForInsert(new SQL92InsertStatement());
- }
-
- @Test
- public void judgeForSQLServerInsert() {
- judgeForInsert(new SQLServerInsertStatement());
- }
-
- private void judgeForInsert(final InsertStatement insertStatement) {
- insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
- InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0,
- Arrays.asList(new ColumnSegment(0, 0, new IdentifierValue("id")), new ColumnSegment(0, 0, new IdentifierValue("name")), new ColumnSegment(0, 0, new IdentifierValue("shadow"))));
- insertStatement.setInsertColumns(insertColumnsSegment);
- insertStatement.getValues().addAll(Collections.singletonList(new InsertValuesSegment(
- 0, 0, Arrays.asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, "name"), new LiteralExpressionSegment(0, 0, true)))));
- InsertStatementContext insertStatementContext = createInsertStatementContext(insertStatement);
- SimpleShadowDataSourceJudgeEngine simpleShadowDataSourceRouter = new SimpleShadowDataSourceJudgeEngine(shadowRule, insertStatementContext);
- assertTrue("should be shadow", simpleShadowDataSourceRouter.isShadow());
- insertStatement.getValues().clear();
- insertStatement.getValues().addAll(Collections.singletonList(
- new InsertValuesSegment(0, 0, Arrays.asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, "name"), new LiteralExpressionSegment(0, 0, false)))));
- insertStatementContext = createInsertStatementContext(insertStatement);
- simpleShadowDataSourceRouter = new SimpleShadowDataSourceJudgeEngine(shadowRule, insertStatementContext);
- assertFalse("should not be shadow", simpleShadowDataSourceRouter.isShadow());
- }
-
- private InsertStatementContext createInsertStatementContext(final InsertStatement insertStatement) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaData.getSchema()).thenReturn(schema);
- return new InsertStatementContext(Collections.singletonMap(DefaultSchema.LOGIC_NAME, metaData), Collections.emptyList(), insertStatement, DefaultSchema.LOGIC_NAME);
- }
-
- @Test
- public void judgeForWhereSegmentForMySQL() {
- judgeForWhereSegment(new MySQLSelectStatement());
- }
-
- @Test
- public void judgeForWhereSegmentForOracle() {
- judgeForWhereSegment(new OracleSelectStatement());
- }
-
- @Test
- public void judgeForWhereSegmentForPostgreSQL() {
- judgeForWhereSegment(new PostgreSQLSelectStatement());
- }
-
- @Test
- public void judgeForWhereSegmentForSQL92() {
- judgeForWhereSegment(new SQL92SelectStatement());
- }
-
- @Test
- public void judgeForWhereSegmentForSQLServer() {
- judgeForWhereSegment(new SQLServerSelectStatement());
- }
-
- private void judgeForWhereSegment(final SelectStatement selectStatement) {
- ColumnSegment left = new ColumnSegment(0, 0, new IdentifierValue("shadow"));
- LiteralExpressionSegment right = new LiteralExpressionSegment(0, 0, true);
- BinaryOperationExpression expression = new BinaryOperationExpression(0, 0, left, right, "=", null);
- WhereSegment whereSegment = new WhereSegment(0, 0, expression);
- selectStatement.setWhere(whereSegment);
- ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
- projectionsSegment.setDistinctRow(true);
- projectionsSegment.getProjections().addAll(Collections.singletonList(new ExpressionProjectionSegment(0, 0, "true")));
- selectStatement.setProjections(projectionsSegment);
- SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
- SimpleShadowDataSourceJudgeEngine simpleShadowDataSourceRouter = new SimpleShadowDataSourceJudgeEngine(shadowRule, selectStatementContext);
- assertTrue("should be shadow", simpleShadowDataSourceRouter.isShadow());
- expression = new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("shadow")), new LiteralExpressionSegment(0, 0, false), "=", null);
- whereSegment = new WhereSegment(0, 0, expression);
- selectStatement.setWhere(whereSegment);
- projectionsSegment.getProjections().clear();
- projectionsSegment.getProjections().addAll(Collections.singletonList(new ExpressionProjectionSegment(0, 0, "false")));
- assertFalse("should not be shadow", simpleShadowDataSourceRouter.isShadow());
- }
-
- private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaData.getSchema()).thenReturn(schema);
- return new SelectStatementContext(Collections.singletonMap(DefaultSchema.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultSchema.LOGIC_NAME);
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtilTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtilTest.java
deleted file mode 100644
index 17424cf..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/judge/util/ShadowValueJudgeUtilTest.java
+++ /dev/null
@@ -1,77 +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.shadow.route.judge.util;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public final class ShadowValueJudgeUtilTest {
-
- @Test
- public void assertShadowValueWhenBooleanAndTrue() {
- assertTrue(ShadowValueJudgeUtil.isShadowValue(Boolean.TRUE));
- assertTrue(ShadowValueJudgeUtil.isShadowValue(true));
- }
-
- @Test
- public void assertShadowValueWhenBooleanAndFalse() {
- assertFalse(ShadowValueJudgeUtil.isShadowValue(Boolean.FALSE));
- assertFalse(ShadowValueJudgeUtil.isShadowValue(false));
- }
-
- @Test
- public void assertShadowValueWhenIntegerAndOne() {
- assertTrue(ShadowValueJudgeUtil.isShadowValue(1));
- }
-
- @Test
- public void assertShadowValueWhenIntegerAndOther() {
- assertFalse(ShadowValueJudgeUtil.isShadowValue(-1));
- assertFalse(ShadowValueJudgeUtil.isShadowValue(0));
- assertFalse(ShadowValueJudgeUtil.isShadowValue(2));
- }
-
- @Test
- public void assertShadowValueWhenStringAndTrue() {
- assertTrue(ShadowValueJudgeUtil.isShadowValue("true"));
- assertTrue(ShadowValueJudgeUtil.isShadowValue("True"));
- assertTrue(ShadowValueJudgeUtil.isShadowValue("TRUE"));
- }
-
- @Test
- public void assertShadowValueWhenStringAndFalse() {
- assertFalse(ShadowValueJudgeUtil.isShadowValue("false"));
- assertFalse(ShadowValueJudgeUtil.isShadowValue("False"));
- assertFalse(ShadowValueJudgeUtil.isShadowValue("FALSE"));
- }
-
- @Test
- public void assertShadowValueWhenStringAndOther() {
- assertFalse(ShadowValueJudgeUtil.isShadowValue("tru"));
- assertFalse(ShadowValueJudgeUtil.isShadowValue("rue"));
- assertFalse(ShadowValueJudgeUtil.isShadowValue("als"));
- assertFalse(ShadowValueJudgeUtil.isShadowValue("other"));
- }
-
- @Test
- public void assertShadowValueWhenOtherObj() {
- assertFalse(ShadowValueJudgeUtil.isShadowValue(new Object()));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
index a8bc675..0c2980b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Before;
import org.junit.Test;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -51,7 +50,7 @@ public final class ShadowRuleTest {
}
private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("ds_shadow", "ds1_shadow"));
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(true);
result.setDataSources(createDataSources());
result.setTables(createTables());
@@ -124,27 +123,13 @@ public final class ShadowRuleTest {
@Test
public void assertNewShadowRulSuccessByShadowRuleConfiguration() {
- ShadowRule shadowRule = new ShadowRule(new ShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("ds_shadow", "ds1_shadow")));
+ ShadowRule shadowRule = new ShadowRule(new ShadowRuleConfiguration());
assertThat(shadowRule.isEnable(), is(false));
- assertBasicShadowRule(shadowRule);
- }
-
- private void assertBasicShadowRule(final ShadowRule shadowRule) {
- assertThat(shadowRule.getColumn(), is("shadow"));
- Map<String, String> shadowMappings = shadowRule.getShadowMappings();
- assertThat(shadowMappings.get("ds"), is("ds_shadow"));
- assertThat(shadowMappings.get("ds1"), is("ds1_shadow"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertNewShadowRuleByShadowRuleConfiguration() {
- new ShadowRule(new ShadowRuleConfiguration("shadow", Collections.emptyList(), Collections.emptyList()));
}
@Test
public void assertNewShadowRulSuccessByAlgorithmProvidedShadowRuleConfiguration() {
assertThat(shadowRuleWithAlgorithm.isEnable(), is(true));
- assertBasicShadowRule(shadowRuleWithAlgorithm);
assertShadowDataSourceMappings(shadowRuleWithAlgorithm.getShadowDataSourceMappings());
assertShadowTableRules(shadowRuleWithAlgorithm.getShadowTableRules());
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
index 8d2f4c4..7c74ec7 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -51,7 +51,6 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
AlgorithmProvidedShadowRuleConfiguration expectedConfiguration = buildAlgorithmProvidedShadowRuleConfiguration();
YamlShadowRuleConfiguration actualConfiguration = swapper.swapToYamlConfiguration(expectedConfiguration);
assertThat(actualConfiguration.isEnable(), is(expectedConfiguration.isEnable()));
- assertBasicYamlShadowRule(actualConfiguration, expectedConfiguration);
actualConfiguration.getDataSources().forEach((key, value) -> {
ShadowDataSourceConfiguration dataSourceConfiguration = expectedConfiguration.getDataSources().get(key);
assertNotNull(dataSourceConfiguration);
@@ -71,7 +70,7 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
}
private AlgorithmProvidedShadowRuleConfiguration buildAlgorithmProvidedShadowRuleConfiguration() {
- AlgorithmProvidedShadowRuleConfiguration result = createAlgorithmProvidedShadowRuleConfiguration();
+ AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration();
result.setEnable(true);
result.getDataSources().put("shadow-data-source", new ShadowDataSourceConfiguration("ds", "ds-shadow"));
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.singletonList("shadow-data-source"), Arrays.asList("user-id-match-algorithm", "note-algorithm")));
@@ -79,23 +78,10 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
return result;
}
- // fixme remove method when the api refactoring is complete
- private void assertBasicYamlShadowRule(final YamlShadowRuleConfiguration actualConfiguration, final AlgorithmProvidedShadowRuleConfiguration expectedConfiguration) {
- assertThat(actualConfiguration.getColumn(), is(expectedConfiguration.getColumn()));
- assertThat(actualConfiguration.getShadowDataSourceNames(), is(expectedConfiguration.getShadowDataSourceNames()));
- assertThat(actualConfiguration.getSourceDataSourceNames(), is(expectedConfiguration.getSourceDataSourceNames()));
- }
-
- // fixme remove method when the api refactoring is complete
- private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
- return new AlgorithmProvidedShadowRuleConfiguration("id", Collections.singletonList("ds"), Collections.singletonList("ds-shadow"));
- }
-
@Test
public void assertSwapToObject() {
YamlShadowRuleConfiguration expectedConfiguration = buildYamlShadowRuleConfiguration();
AlgorithmProvidedShadowRuleConfiguration actualConfiguration = swapper.swapToObject(expectedConfiguration);
- assertBasicAlgorithmShadowRule(actualConfiguration, expectedConfiguration);
assertThat(actualConfiguration.isEnable(), is(expectedConfiguration.isEnable()));
actualConfiguration.getDataSources().forEach((key, value) -> {
YamlShadowDataSourceConfiguration yamlShadowDataSourceConfiguration = expectedConfiguration.getDataSources().get(key);
@@ -117,7 +103,6 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
private YamlShadowRuleConfiguration buildYamlShadowRuleConfiguration() {
YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
- buildBasicYamlShadowRule(result);
result.setEnable(true);
YamlShadowDataSourceConfiguration yamlShadowDataSourceConfiguration = new YamlShadowDataSourceConfiguration();
yamlShadowDataSourceConfiguration.setSourceDataSourceName("ds");
@@ -131,18 +116,4 @@ public final class ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
result.getShadowAlgorithms().put("user-id-match-algorithm", yamlShardingSphereAlgorithmConfiguration);
return result;
}
-
- // fixme remove method when the api refactoring is complete
- private void buildBasicYamlShadowRule(final YamlShadowRuleConfiguration yamlShadowRuleConfiguration) {
- yamlShadowRuleConfiguration.setColumn("id");
- yamlShadowRuleConfiguration.setSourceDataSourceNames(Collections.singletonList("ds"));
- yamlShadowRuleConfiguration.setShadowDataSourceNames(Collections.singletonList("ds-shadow"));
- }
-
- // fixme remove method when the api refactoring is complete
- private void assertBasicAlgorithmShadowRule(final AlgorithmProvidedShadowRuleConfiguration actualConfiguration, final YamlShadowRuleConfiguration expectedConfiguration) {
- assertThat(actualConfiguration.getColumn(), is(expectedConfiguration.getColumn()));
- assertThat(actualConfiguration.getShadowDataSourceNames(), is(expectedConfiguration.getShadowDataSourceNames()));
- assertThat(actualConfiguration.getSourceDataSourceNames(), is(expectedConfiguration.getSourceDataSourceNames()));
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleConfigurationYamlSwapperTest.java
index 6c31f0f..0ef6a08 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleConfigurationYamlSwapperTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleConfigurationYamlSwapperTest.java
@@ -23,8 +23,6 @@ import org.apache.shardingsphere.shadow.yaml.swapper.ShadowRuleConfigurationYaml
import org.junit.Before;
import org.junit.Test;
-import java.util.Arrays;
-
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -39,16 +37,10 @@ public final class ShadowRuleConfigurationYamlSwapperTest {
@Test
public void assertSwapToYamlConfiguration() {
- ShadowRuleConfiguration expectedConfiguration = createShadowRuleConfiguration();
+ ShadowRuleConfiguration expectedConfiguration = new ShadowRuleConfiguration();
+ expectedConfiguration.setEnable(true);
YamlShadowRuleConfiguration actualConfiguration = swapper.swapToYamlConfiguration(expectedConfiguration);
assertThat(actualConfiguration.isEnable(), is(expectedConfiguration.isEnable()));
- assertThat(actualConfiguration.getColumn(), is(expectedConfiguration.getColumn()));
- assertThat(actualConfiguration.getSourceDataSourceNames(), is(expectedConfiguration.getSourceDataSourceNames()));
- assertThat(actualConfiguration.getShadowDataSourceNames(), is(expectedConfiguration.getShadowDataSourceNames()));
- }
-
- private ShadowRuleConfiguration createShadowRuleConfiguration() {
- return new ShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("shadow_ds", "shadow_ds1"));
}
@Test
@@ -56,16 +48,11 @@ public final class ShadowRuleConfigurationYamlSwapperTest {
YamlShadowRuleConfiguration expectedConfiguration = createYamlShadowRuleConfiguration();
ShadowRuleConfiguration actualConfiguration = swapper.swapToObject(expectedConfiguration);
assertThat(actualConfiguration.isEnable(), is(expectedConfiguration.isEnable()));
- assertThat(actualConfiguration.getColumn(), is(expectedConfiguration.getColumn()));
- assertThat(actualConfiguration.getSourceDataSourceNames(), is(expectedConfiguration.getSourceDataSourceNames()));
- assertThat(actualConfiguration.getShadowDataSourceNames(), is(expectedConfiguration.getShadowDataSourceNames()));
}
private YamlShadowRuleConfiguration createYamlShadowRuleConfiguration() {
YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
- result.setColumn("shadow");
- result.setSourceDataSourceNames(Arrays.asList("ds", "ds1"));
- result.setShadowDataSourceNames(Arrays.asList("shadow_ds", "shadow_ds1"));
+ result.setEnable(true);
return result;
}
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest.java
index ed705e3..443810d 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.shadow.swapper;
-import org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.junit.Test;
@@ -27,7 +26,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
-import java.util.Arrays;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
@@ -41,7 +39,6 @@ public final class YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest
assertNotNull(url);
YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new File(url.getFile()), YamlRootConfiguration.class);
assertThat(rootConfig.getRules().size(), is(1));
- assertShadowRule((YamlShadowRuleConfiguration) rootConfig.getRules().iterator().next());
}
@Test
@@ -59,13 +56,5 @@ public final class YamlRootRuleConfigurationsForYamlShadowRuleConfigurationTest
}
YamlRootConfiguration rootConfig = YamlEngine.unmarshal(yamlContent.toString().getBytes(), YamlRootConfiguration.class);
assertThat(rootConfig.getRules().size(), is(1));
- assertShadowRule((YamlShadowRuleConfiguration) rootConfig.getRules().iterator().next());
- }
-
- private void assertShadowRule(final YamlShadowRuleConfiguration actual) {
- assertThat(actual.getColumn(), is("shadow"));
- assertThat(actual.getSourceDataSourceNames().size(), is(actual.getShadowDataSourceNames().size()));
- assertThat(actual.getSourceDataSourceNames(), is(Arrays.asList("ds", "ds1")));
- assertThat(actual.getShadowDataSourceNames(), is(Arrays.asList("shadow_ds", "shadow_ds1")));
}
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/resources/yaml/shadow-rule.yaml b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/resources/yaml/shadow-rule.yaml
index 8c32546..4ed7b30 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/resources/yaml/shadow-rule.yaml
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/resources/yaml/shadow-rule.yaml
@@ -31,11 +31,53 @@ dataSources:
rules:
- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - ds
- - ds1
- shadowDataSourceNames:
- - shadow_ds
- - shadow_ds1
-
+ enable: true
+ dataSources:
+ shadowDataSource:
+ sourceDataSourceName: ds
+ shadowDataSourceName: ds_shadow
+ tables:
+ t_order:
+ dataSourceNames:
+ - shadowDataSource
+ shadowAlgorithmNames:
+ - user-id-insert-match-algorithm
+ - user-id-select-match-algorithm
+ t_order_item:
+ dataSourceNames:
+ - shadowDataSource
+ shadowAlgorithmNames:
+ - user-id-insert-match-algorithm
+ - user-id-update-match-algorithm
+ - user-id-select-match-algorithm
+ t_address:
+ dataSourceNames:
+ - shadowDataSource
+ shadowAlgorithmNames:
+ - user-id-insert-match-algorithm
+ - user-id-select-match-algorithm
+ - simple-note-algorithm
+ shadowAlgorithms:
+ user-id-insert-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: insert
+ column: user_id
+ regex: "[1]"
+ user-id-update-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: update
+ column: user_id
+ regex: "[1]"
+ user-id-select-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: select
+ column: user_id
+ regex: "[1]"
+ simple-note-algorithm:
+ type: SIMPLE_NOTE
+ props:
+ shadow: true
+ foo: bar
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleStatementConverter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleStatementConverter.java
index e266b12..57f5688 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleStatementConverter.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleStatementConverter.java
@@ -49,7 +49,7 @@ public final class ShadowRuleStatementConverter {
*/
public static ShadowRuleConfiguration convert(final Collection<ShadowRuleSegment> rules) {
// FIXME because the defined final attribute will be removed, here is just for the new object
- ShadowRuleConfiguration shadowRuleConfiguration = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ ShadowRuleConfiguration shadowRuleConfiguration = new ShadowRuleConfiguration();
shadowRuleConfiguration.setShadowAlgorithms(getShadowAlgorithms(rules));
shadowRuleConfiguration.setDataSources(getDataSource(rules));
shadowRuleConfiguration.setTables(getTables(rules));
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java
index 6a0c50f..7d9f1eb 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatem
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowAlgorithmStatement;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -44,7 +43,7 @@ public final class AlterShadowAlgorithmStatementUpdater implements RuleDefinitio
@Override
public RuleConfiguration buildToBeAlteredRuleConfiguration(final AlterShadowAlgorithmStatement sqlStatement) {
// FIXME because the defined final attribute will be removed, here is just for the new object
- ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.setShadowAlgorithms(buildAlgorithmMap(sqlStatement));
return result;
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java
index cd0b15d..f45a72a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java
@@ -55,7 +55,7 @@ public final class ShadowAlgorithmQueryResultSetTest {
private RuleConfiguration createRuleConfiguration() {
// FIXME because the defined final attribute will be removed, here is just for the new object
- ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
Properties properties = new Properties();
properties.setProperty("foo", "bar");
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.emptyList(), Collections.singletonList("shadowAlgorithmName")));
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java
index 2cb1bc9..3529b9c 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java
@@ -55,7 +55,7 @@ public final class ShadowRuleQueryResultSetTest {
private RuleConfiguration createRuleConfiguration() {
// FIXME because the defined final attribute will be removed, here is just for the new object
- ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getDataSources().put("shadow_rule", new ShadowDataSourceConfiguration("source", "shadow"));
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.singletonList("shadow_rule"), Collections.emptyList()));
result.getTables().put("t_order_1", new ShadowTableConfiguration(Collections.singletonList("shadow_rule"), Collections.emptyList()));
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java
index 7910e97..071f2fd 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java
@@ -55,7 +55,7 @@ public final class ShadowTableRuleQueryResultSetTest {
private RuleConfiguration createRuleConfiguration() {
// FIXME because the defined final attribute will be removed, here is just for the new object
- ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
Properties properties = new Properties();
properties.setProperty("foo", "bar");
result.getTables().put("t_order", new ShadowTableConfiguration(Collections.emptyList(), Arrays.asList("shadowAlgorithmName_1", "shadowAlgorithmName_2")));
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
index c7fa3c1..d88dc66 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
@@ -33,7 +33,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -51,7 +50,6 @@ public class PropertiesShadowSpringBootStarterTest {
@Test
public void assertShadowRuleConfiguration() {
assertThat(shadowRuleConfiguration.isEnable(), is(false));
- assertBasicShadowRule(shadowRuleConfiguration.getColumn(), shadowRuleConfiguration.getSourceDataSourceNames(), shadowRuleConfiguration.getShadowDataSourceNames());
assertShadowDataSources(shadowRuleConfiguration.getDataSources());
assertShadowTables(shadowRuleConfiguration.getTables());
assertShadowAlgorithms(shadowRuleConfiguration.getShadowAlgorithms());
@@ -86,11 +84,4 @@ public class PropertiesShadowSpringBootStarterTest {
assertThat(dataSources.get("shadow-data-source-1").getSourceDataSourceName(), is("ds1"));
assertThat(dataSources.get("shadow-data-source-1").getShadowDataSourceName(), is("ds1-shadow"));
}
-
- // fixme remove method when the api refactoring is complete
- private void assertBasicShadowRule(final String column, final List<String> sourceDataSourceNames, final List<String> shadowDataSourceNames) {
- assertThat(column, is("shadow"));
- assertThat(sourceDataSourceNames, is(Arrays.asList("ds", "ds1")));
- assertThat(shadowDataSourceNames, is(Arrays.asList("shadow_ds", "shadow_ds1")));
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
index 5294955..86e8cb1 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
@@ -33,7 +33,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -51,7 +50,6 @@ public class YmlShadowSpringBootStarterTest {
@Test
public void assertShadowRuleConfiguration() {
assertThat(shadowRuleConfiguration.isEnable(), is(true));
- assertBasicShadowRule(shadowRuleConfiguration.getColumn(), shadowRuleConfiguration.getSourceDataSourceNames(), shadowRuleConfiguration.getShadowDataSourceNames());
assertShadowDataSources(shadowRuleConfiguration.getDataSources());
assertShadowTables(shadowRuleConfiguration.getTables());
assertShadowAlgorithms(shadowRuleConfiguration.getShadowAlgorithms());
@@ -86,11 +84,4 @@ public class YmlShadowSpringBootStarterTest {
assertThat(dataSources.get("shadow-data-source-1").getSourceDataSourceName(), is("ds1"));
assertThat(dataSources.get("shadow-data-source-1").getShadowDataSourceName(), is("ds1-shadow"));
}
-
- // fixme remove method when the api refactoring is complete
- private void assertBasicShadowRule(final String column, final List<String> sourceDataSourceNames, final List<String> shadowDataSourceNames) {
- assertThat(column, is("shadow"));
- assertThat(sourceDataSourceNames, is(Arrays.asList("ds", "ds1")));
- assertThat(shadowDataSourceNames, is(Arrays.asList("shadow_ds", "shadow_ds1")));
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
index b7a13bb..8f1c94d 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
@@ -15,10 +15,6 @@
# limitations under the License.
#
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds,ds1
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow_ds,shadow_ds1
-
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.source-data-source-name=ds
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-0.shadow-data-source-name=ds-shadow
spring.shardingsphere.rules.shadow.data-sources.shadow-data-source-1.source-data-source-name=ds1
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
index 3b4301a..527385a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
@@ -19,10 +19,6 @@ spring:
shardingsphere:
rules:
shadow:
- column: shadow
- source-data-source-names: ds,ds1
- shadow-data-source-names: shadow_ds,shadow_ds1
-
enable: true
data-sources:
shadow-data-source-0:
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/parser/ShadowRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/parser/ShadowRuleBeanDefinitionParser.java
index 4538c27..78c5032 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/parser/ShadowRuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/java/org/apache/shardingsphere/shadow/spring/namespace/parser/ShadowRuleBeanDefinitionParser.java
@@ -54,7 +54,6 @@ public final class ShadowRuleBeanDefinitionParser extends AbstractBeanDefinition
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedShadowRuleConfiguration.class);
- addConstructorArgValue(element, factory);
factory.addPropertyValue("enable", parseShadowEnableConfiguration(element));
factory.addPropertyValue("dataSources", parseDataSourcesConfiguration(element));
factory.addPropertyValue("tables", parseShadowTablesConfiguration(element));
@@ -111,11 +110,4 @@ public final class ShadowRuleBeanDefinitionParser extends AbstractBeanDefinition
factory.addConstructorArgValue(element.getAttribute(ShadowRuleBeanDefinitionTag.SHADOW_DATA_SOURCE_NAME_ATTRIBUTE));
return factory.getBeanDefinition();
}
-
- // fixme remove method when the api refactoring is complete
- private void addConstructorArgValue(final Element element, final BeanDefinitionBuilder factory) {
- factory.addConstructorArgValue(element.getAttribute(ShadowRuleBeanDefinitionTag.COLUMN_CONFIG_TAG));
- factory.addConstructorArgValue(element.getAttribute(ShadowRuleBeanDefinitionTag.SOURCE_DATASOURCE_NAMES_TAG).split(","));
- factory.addConstructorArgValue(element.getAttribute(ShadowRuleBeanDefinitionTag.SHADOW_DATASOURCE_NAMES_TAG).split(","));
- }
}
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 006ba91..22c9ee5 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
@@ -28,13 +28,6 @@ public final class ShadowRuleBeanDefinitionTag {
public static final String ROOT_TAG = "rule";
- // fixme remove three fields when the api refactoring is complete
- public static final String COLUMN_CONFIG_TAG = "column";
-
- public static final String SHADOW_DATASOURCE_NAMES_TAG = "shadowDataSourceNames";
-
- public static final String SOURCE_DATASOURCE_NAMES_TAG = "sourceDataSourceNames";
-
public static final String SHADOW_ENABLE_TAG = "enable";
public static final String DATA_SOURCE_TAG = "data-source";
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 0e5e3f9..1b68788 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
@@ -32,11 +32,6 @@
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="enable" type="xsd:boolean"/>
- <!-- fixme remove when the api refactoring is complete start -->
- <xsd:attribute name="column" type="xsd:string" use="required"/>
- <xsd:attribute name="sourceDataSourceNames" type="list" use="required"/>
- <xsd:attribute name="shadowDataSourceNames" type="list" use="required"/>
- <!-- fixme remove when the api refactoring is complete end -->
</xsd:complexType>
</xsd:element>
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
index 165a2d9..126513b 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
@@ -30,7 +30,6 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -45,7 +44,6 @@ public final class ShadowAlgorithmSpringNamespaceTest extends AbstractJUnit4Spri
@Test
public void assertDataSource() {
assertThat(shadowRule.isEnable(), is(true));
- assertBasicShadowRule(shadowRule.getColumn(), shadowRule.getSourceDataSourceNames(), shadowRule.getShadowDataSourceNames());
assertShadowDataSources(shadowRule.getDataSources());
assertShadowTables(shadowRule.getTables());
assertShadowAlgorithms(shadowRule.getShadowAlgorithms());
@@ -80,11 +78,4 @@ public final class ShadowAlgorithmSpringNamespaceTest extends AbstractJUnit4Spri
assertThat(dataSources.get("shadow-data-source-1").getSourceDataSourceName(), is("ds1"));
assertThat(dataSources.get("shadow-data-source-1").getShadowDataSourceName(), is("ds1-shadow"));
}
-
- // fixme remove method when the api refactoring is complete
- private void assertBasicShadowRule(final String column, final List<String> sourceDataSourceNames, final List<String> shadowDataSourceNames) {
- assertThat(column, is("shadow"));
- assertThat(sourceDataSourceNames, is(Arrays.asList("ds0", "ds1")));
- assertThat(shadowDataSourceNames, is(Arrays.asList("shadow_ds0", "shadow_ds1")));
- }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowSpringNamespaceTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowSpringNamespaceTest.java
deleted file mode 100644
index adb0d70..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowSpringNamespaceTest.java
+++ /dev/null
@@ -1,54 +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.shadow.spring.namespace;
-
-import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
-import org.junit.Test;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-
-import javax.annotation.Resource;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-@ContextConfiguration(locations = "classpath:META-INF/spring/shadow-application-context.xml")
-public final class ShadowSpringNamespaceTest extends AbstractJUnit4SpringContextTests {
-
- @Resource
- private AlgorithmProvidedShadowRuleConfiguration shadowRule;
-
- @Test
- public void assertDataSource() {
- assertThat(shadowRule.isEnable(), is(false));
- assertBasicShadowRule(shadowRule.getColumn(), shadowRule.getSourceDataSourceNames(), shadowRule.getShadowDataSourceNames());
- assertTrue(shadowRule.getDataSources().isEmpty());
- assertTrue(shadowRule.getTables().isEmpty());
- assertTrue(shadowRule.getShadowAlgorithms().isEmpty());
- }
-
- // fixme remove method when the api refactoring is complete
- private void assertBasicShadowRule(final String column, final List<String> sourceDataSourceNames, final List<String> shadowDataSourceNames) {
- assertThat(column, is("shadow"));
- assertThat(sourceDataSourceNames, is(Arrays.asList("ds", "ds1")));
- assertThat(shadowDataSourceNames, is(Arrays.asList("shadow_ds", "shadow_ds1")));
- }
-}
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 e2fad38..6f8b5b0 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
@@ -24,7 +24,6 @@
http://shardingsphere.apache.org/schema/shardingsphere/shadow
http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow.xsd
">
-
<shadow:shadow-algorithm id="user-id-match-algorithm" type="COLUMN_REGEX_MATCH">
<props>
<prop key="operation">insert</prop>
@@ -39,7 +38,7 @@
</props>
</shadow:shadow-algorithm>
- <shadow:rule id="shadowRule" enable="true" column="shadow" sourceDataSourceNames="ds0,ds1" shadowDataSourceNames="shadow_ds0,shadow_ds1">
+ <shadow:rule id="shadowRule" enable="true">
<shadow:data-source id="shadow-data-source-0" source-data-source-name="ds" shadow-data-source-name="ds-shadow"/>
<shadow:data-source id="shadow-data-source-1" source-data-source-name="ds1" shadow-data-source-name="ds1-shadow"/>
<shadow:shadow-table name="t_order" data-sources="shadow-data-source-0,shadow-data-source-1">
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-application-context.xml b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-application-context.xml
deleted file mode 100644
index adf7186..0000000
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-application-context.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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: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://shardingsphere.apache.org/schema/shardingsphere/shadow
- http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow.xsd
- ">
- <shadow:rule id="shadowRule" column="shadow" sourceDataSourceNames="ds,ds1" shadowDataSourceNames="shadow_ds,shadow_ds1"/>
-</beans>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFutureShadowTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFutureShadowTest.java
deleted file mode 100644
index 273b752..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFutureShadowTest.java
+++ /dev/null
@@ -1,72 +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.driver.jdbc.base;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-import javax.sql.DataSource;
-import java.io.File;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractShardingSphereDataSourceForFutureShadowTest extends AbstractSQLTest {
-
- private static ShardingSphereDataSource dataSource;
-
- private static final String CONFIG_SHADOW = "config/config-future-shadow.yaml";
-
- private static final List<String> ACTUAL_DATA_SOURCE_NAMES = Arrays.asList("shadow_jdbc_0", "shadow_jdbc_1");
-
- @BeforeClass
- public static void initShadowDataSource() throws SQLException, IOException {
- if (null != dataSource) {
- return;
- }
- dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSources(), getFile(CONFIG_SHADOW));
- }
-
- private static Map<String, DataSource> getDataSources() {
- return Maps.filterKeys(getActualDataSources(), ACTUAL_DATA_SOURCE_NAMES::contains);
- }
-
- private static File getFile(final String fileName) {
- return new File(Preconditions.checkNotNull(
- AbstractShardingSphereDataSourceForShadowTest.class.getClassLoader().getResource(fileName), "file resource `%s` must not be null.", fileName).getFile());
- }
-
- protected final ShardingSphereDataSource getShadowDataSource() {
- return dataSource;
- }
-
- @AfterClass
- public static void close() throws Exception {
- if (null == dataSource) {
- return;
- }
- dataSource.close();
- dataSource = null;
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowPreparedStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowPreparedStatementTest.java
deleted file mode 100644
index 59640c8..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowPreparedStatementTest.java
+++ /dev/null
@@ -1,228 +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.driver.jdbc.core.statement;
-
-import org.apache.shardingsphere.driver.jdbc.base.AbstractShardingSphereDataSourceForFutureShadowTest;
-import org.junit.After;
-import org.junit.Test;
-
-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 static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class FutureShadowPreparedStatementTest extends AbstractShardingSphereDataSourceForFutureShadowTest {
-
- private static final String CLEAN_SQL = "DELETE FROM t_encrypt";
-
- private static final String RESULT_SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt";
-
- private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (?, ?, ?)";
-
- private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd =? WHERE id = ?";
-
- private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE id = ?";
-
- private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = ?";
-
- @Test
- public void assertInsertNativeCase() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
- statement.setObject(1, 2);
- statement.setString(2, "cipher");
- statement.setString(3, "plain");
- statement.execute();
- }
- assertResultSet(true, 0, "cipher");
- assertResultSet(false, 1, "cipher");
- }
-
- private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
- DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
- try (Statement statement = dataSource.getConnection().createStatement()) {
- ResultSet resultSet = statement.executeQuery(RESULT_SELECT_SQL);
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
- count += 1;
- }
- assertThat(count, is(resultSetCount));
- }
- }
-
- @Test
- public void assertInsertShadowCase() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
- statement.setObject(1, 1);
- statement.setString(2, "cipher");
- statement.setString(3, "plain");
- statement.execute();
- }
- assertResultSet(true, 1, "cipher");
- assertResultSet(false, 0, "cipher");
- }
-
- @Test
- public void assertUpdateNativeCase() throws SQLException {
- int result;
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement.setObject(1, 2);
- insertPreparedStatement.setString(2, "cipher");
- insertPreparedStatement.setString(3, "plain");
- insertPreparedStatement.execute();
- PreparedStatement updatePreparedStatement = connection.prepareStatement(UPDATE_SQL);
- updatePreparedStatement.setString(1, "cipher_pwd");
- updatePreparedStatement.setObject(2, 2);
- result = updatePreparedStatement.executeUpdate();
- }
- assertThat(result, is(1));
- assertResultSet(true, 0, "cipher_pwd");
- assertResultSet(false, 1, "cipher_pwd");
- }
-
- @Test
- public void assertUpdateShadowCase() throws SQLException {
- int result;
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement.setObject(1, 1);
- insertPreparedStatement.setString(2, "cipher");
- insertPreparedStatement.setString(3, "plain");
- insertPreparedStatement.execute();
- PreparedStatement updatePreparedStatement = connection.prepareStatement(UPDATE_SQL);
- updatePreparedStatement.setString(1, "cipher_pwd");
- updatePreparedStatement.setObject(2, 1);
- result = updatePreparedStatement.executeUpdate();
- }
- assertThat(result, is(1));
- assertResultSet(true, 1, "cipher_pwd");
- assertResultSet(false, 0, "cipher_pwd");
- }
-
- @Test
- public void assertDeleteNativeCase() throws SQLException {
- int result;
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement1 = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement1.setObject(1, 2);
- insertPreparedStatement1.setString(2, "cipher");
- insertPreparedStatement1.setString(3, "plain");
- insertPreparedStatement1.execute();
- PreparedStatement insertPreparedStatement2 = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement2.setObject(1, 1);
- insertPreparedStatement2.setString(2, "cipher_pwd");
- insertPreparedStatement2.setString(3, "plain");
- insertPreparedStatement2.execute();
- PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
- deletePreparedStatement.setObject(1, 2);
- result = deletePreparedStatement.executeUpdate();
- }
- assertThat(result, is(1));
- assertResultSet(true, 1, "cipher_pwd");
- assertResultSet(false, 0, "cipher_pwd");
- }
-
- @Test
- public void assertDeleteShadowCase() throws SQLException {
- int result;
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement1 = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement1.setObject(1, 1);
- insertPreparedStatement1.setString(2, "cipher_pwd");
- insertPreparedStatement1.setString(3, "plain");
- insertPreparedStatement1.execute();
- PreparedStatement insertPreparedStatement2 = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement2.setObject(1, 2);
- insertPreparedStatement2.setString(2, "cipher");
- insertPreparedStatement2.setString(3, "plain");
- insertPreparedStatement2.execute();
- PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
- deletePreparedStatement.setObject(1, 1);
- result = deletePreparedStatement.executeUpdate();
- }
- assertThat(result, is(1));
- assertResultSet(true, 0, "cipher_pwd");
- assertResultSet(false, 1, "cipher");
- }
-
- @Test
- public void assertSelectNativeCase() throws SQLException {
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement.setObject(1, 2);
- insertPreparedStatement.setString(2, "cipher");
- insertPreparedStatement.setString(3, "plain");
- insertPreparedStatement.execute();
- PreparedStatement selectPreparedStatement = connection.prepareStatement(SELECT_SQL);
- selectPreparedStatement.setObject(1, 2);
- ResultSet resultSet = selectPreparedStatement.executeQuery();
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
- count += 1;
- }
- assertThat(count, is(1));
- PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
- deletePreparedStatement.setObject(1, 2);
- deletePreparedStatement.executeUpdate();
- }
- assertResultSet(true, 0, "cipher");
- assertResultSet(false, 0, "cipher");
- }
-
- @Test
- public void assertSelectShadowCase() throws SQLException {
- try (Connection connection = getShadowDataSource().getConnection()) {
- PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
- insertPreparedStatement.setObject(1, 1);
- insertPreparedStatement.setString(2, "cipher_pwd");
- insertPreparedStatement.setString(3, "plain");
- insertPreparedStatement.execute();
- PreparedStatement selectPreparedStatement = connection.prepareStatement(SELECT_SQL);
- selectPreparedStatement.setObject(1, 1);
- ResultSet resultSet = selectPreparedStatement.executeQuery();
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is("cipher_pwd"));
- count += 1;
- }
- assertThat(count, is(1));
- PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
- deletePreparedStatement.setObject(1, 1);
- deletePreparedStatement.executeUpdate();
- }
- assertResultSet(true, 0, "cipher_pwd");
- assertResultSet(false, 0, "cipher_pwd");
- }
-
- @After
- public void clean() throws SQLException {
- try (Statement statement = getActualDataSources().get("shadow_jdbc_0").getConnection().createStatement()) {
- statement.execute(CLEAN_SQL);
- }
- try (Statement statement = getActualDataSources().get("shadow_jdbc_1").getConnection().createStatement()) {
- statement.execute(CLEAN_SQL);
- }
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowStatementTest.java
deleted file mode 100644
index 09faa3f..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FutureShadowStatementTest.java
+++ /dev/null
@@ -1,175 +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.driver.jdbc.core.statement;
-
-import org.apache.shardingsphere.driver.jdbc.base.AbstractShardingSphereDataSourceForFutureShadowTest;
-import org.junit.After;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class FutureShadowStatementTest extends AbstractShardingSphereDataSourceForFutureShadowTest {
-
- private static final String CLEAN_SQL = "DELETE FROM t_encrypt";
-
- private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (2, 'cipher', 'plain')";
-
- private static final String INSERT_SHADOW_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (1, 'cipher', 'plain')";
-
- private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 2";
-
- private static final String UPDATE_SHADOW_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 1";
-
- private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE id = 2";
-
- private static final String DELETE_SHADOW_SQL = "DELETE FROM t_encrypt WHERE id = 1";
-
- private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = 2";
-
- private static final String SELECT_SHADOW_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = 1";
-
- private static final String RESULT_SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt";
-
- @Test
- public void assertInsertNativeCase() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SQL);
- }
- assertResultSet(true, 0, "cipher");
- assertResultSet(false, 1, "cipher");
- }
-
- private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
- DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
- try (Statement statement = dataSource.getConnection().createStatement()) {
- ResultSet resultSet = statement.executeQuery(RESULT_SELECT_SQL);
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
- count += 1;
- }
- assertThat(count, is(resultSetCount));
- }
- }
-
- @Test
- public void assertInsertShadowCase() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SHADOW_SQL);
- }
- assertResultSet(true, 1, "cipher");
- assertResultSet(false, 0, "cipher");
- }
-
- @Test
- public void assertUpdateNativeCase() throws SQLException {
- int result;
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SQL);
- result = statement.executeUpdate(UPDATE_SQL);
- }
- assertThat(result, is(1));
- assertResultSet(true, 0, "cipher_pwd");
- assertResultSet(false, 1, "cipher_pwd");
-
- }
-
- @Test
- public void assertUpdateShadowCase() throws SQLException {
- int result;
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SHADOW_SQL);
- result = statement.executeUpdate(UPDATE_SHADOW_SQL);
- }
- assertThat(result, is(1));
- assertResultSet(true, 1, "cipher_pwd");
- assertResultSet(false, 0, "cipher_pwd");
- }
-
- @Test
- public void assertDeleteNativeCase() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SQL);
- statement.execute(INSERT_SHADOW_SQL);
- statement.execute(DELETE_SQL);
- }
- assertResultSet(true, 1, "cipher");
- assertResultSet(false, 0, "cipher");
- }
-
- @Test
- public void assertDeleteShadowCase() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SQL);
- statement.execute(INSERT_SHADOW_SQL);
- statement.execute(DELETE_SHADOW_SQL);
- }
- assertResultSet(true, 0, "cipher");
- assertResultSet(false, 1, "cipher");
- }
-
- @Test
- public void assertSelectNativeCase() throws SQLException {
- ResultSet resultSet;
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SQL);
- resultSet = statement.executeQuery(SELECT_SQL);
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
- count += 1;
- }
- assertThat(count, is(1));
- statement.execute(DELETE_SQL);
- }
- assertResultSet(false, 0, "cipher");
- }
-
- @Test
- public void assertSelectShadowCase() throws SQLException {
- ResultSet resultSet;
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(INSERT_SHADOW_SQL);
- resultSet = statement.executeQuery(SELECT_SHADOW_SQL);
- int count = 0;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
- count += 1;
- }
- assertThat(count, is(1));
- statement.execute(DELETE_SHADOW_SQL);
- }
- assertResultSet(true, 0, "cipher");
- }
-
- @After
- public void clean() throws SQLException {
- try (Statement statement = getActualDataSources().get("shadow_jdbc_0").getConnection().createStatement()) {
- statement.execute(CLEAN_SQL);
- }
- try (Statement statement = getActualDataSources().get("shadow_jdbc_1").getConnection().createStatement()) {
- statement.execute(CLEAN_SQL);
- }
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowPreparedStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowPreparedStatementTest.java
index 1f8a1f8..9bf890d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowPreparedStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowPreparedStatementTest.java
@@ -19,10 +19,10 @@ package org.apache.shardingsphere.driver.jdbc.core.statement;
import org.apache.shardingsphere.driver.jdbc.base.AbstractShardingSphereDataSourceForShadowTest;
import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import javax.sql.DataSource;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -33,160 +33,196 @@ import static org.junit.Assert.assertThat;
public final class ShadowPreparedStatementTest extends AbstractShardingSphereDataSourceForShadowTest {
- private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd, shadow) VALUES (?, ?, ?, ?)";
+ private static final String CLEAN_SQL = "DELETE FROM t_encrypt";
- private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE plain_pwd = ?";
+ private static final String RESULT_SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt";
- private static final String SHADOW_DELETE_SQL = "DELETE FROM t_encrypt WHERE plain_pwd = ? AND shadow = ?";
+ private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (?, ?, ?)";
- private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt";
+ private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd =? WHERE id = ?";
- private static final String SELECT_SQL_BY_ID = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = ?";
+ private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE id = ?";
- private static final String CLEAN_SQL = "DELETE FROM t_encrypt WHERE shadow = ?";
-
- private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd = ? WHERE id = ?";
-
- private static final String SHADOW_UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd = ? WHERE id = ? AND shadow = ?";
-
- private static final String SHADOW_UPDATE_SQL_WITH_CONDITION = "UPDATE t_encrypt SET cipher_pwd = ? WHERE id = ? AND shadow = true";
+ private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = ?";
@Test
- public void assertInsertWithExecute() throws SQLException {
+ public void assertInsertNativeCase() throws SQLException {
try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
statement.setObject(1, 2);
statement.setString(2, "cipher");
statement.setString(3, "plain");
- statement.setBoolean(4, false);
statement.execute();
}
- assertResultSet(false, 2, "cipher");
- assertResultSet(true, 1, "cipher");
+ assertResultSet(true, 0, "cipher");
+ assertResultSet(false, 1, "cipher");
+ }
+
+ private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
+ DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
+ try (Statement statement = dataSource.getConnection().createStatement()) {
+ ResultSet resultSet = statement.executeQuery(RESULT_SELECT_SQL);
+ int count = 0;
+ while (resultSet.next()) {
+ assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
+ count += 1;
+ }
+ assertThat(count, is(resultSetCount));
+ }
}
@Test
- public void assertShadowInsertWithExecute() throws SQLException {
+ public void assertInsertShadowCase() throws SQLException {
try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
statement.setObject(1, 1);
statement.setString(2, "cipher");
statement.setString(3, "plain");
- statement.setBoolean(4, true);
statement.execute();
}
- assertResultSet(false, 1, "cipher");
- assertResultSet(true, 2, "cipher");
- }
-
- @Test
- public void assertDeleteWithExecute() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(DELETE_SQL)) {
- statement.setObject(1, "plain");
- statement.executeUpdate();
- }
+ assertResultSet(true, 1, "cipher");
assertResultSet(false, 0, "cipher");
}
@Test
- public void assertShadowDeleteWithExecute() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(SHADOW_DELETE_SQL)) {
- statement.setObject(1, "plain");
- statement.setBoolean(2, true);
- statement.executeUpdate();
+ public void assertUpdateNativeCase() throws SQLException {
+ int result;
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement.setObject(1, 2);
+ insertPreparedStatement.setString(2, "cipher");
+ insertPreparedStatement.setString(3, "plain");
+ insertPreparedStatement.execute();
+ PreparedStatement updatePreparedStatement = connection.prepareStatement(UPDATE_SQL);
+ updatePreparedStatement.setString(1, "cipher_pwd");
+ updatePreparedStatement.setObject(2, 2);
+ result = updatePreparedStatement.executeUpdate();
}
- assertResultSet(true, 0, "cipher");
+ assertThat(result, is(1));
+ assertResultSet(true, 0, "cipher_pwd");
+ assertResultSet(false, 1, "cipher_pwd");
}
@Test
- public void assertUpdateWithExecuteUpdate() throws SQLException {
+ public void assertUpdateShadowCase() throws SQLException {
int result;
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(UPDATE_SQL)) {
- statement.setString(1, "cipher_pwd");
- statement.setInt(2, 99);
- result = statement.executeUpdate();
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement.setObject(1, 1);
+ insertPreparedStatement.setString(2, "cipher");
+ insertPreparedStatement.setString(3, "plain");
+ insertPreparedStatement.execute();
+ PreparedStatement updatePreparedStatement = connection.prepareStatement(UPDATE_SQL);
+ updatePreparedStatement.setString(1, "cipher_pwd");
+ updatePreparedStatement.setObject(2, 1);
+ result = updatePreparedStatement.executeUpdate();
}
assertThat(result, is(1));
- assertResultSet(false, 99, 1, "cipher_pwd");
+ assertResultSet(true, 1, "cipher_pwd");
+ assertResultSet(false, 0, "cipher_pwd");
}
@Test
- public void assertShadowUpdateWithExecuteUpdate() throws SQLException {
+ public void assertDeleteNativeCase() throws SQLException {
int result;
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(SHADOW_UPDATE_SQL)) {
- statement.setString(1, "cipher_pwd");
- statement.setInt(2, 99);
- statement.setBoolean(3, true);
- result = statement.executeUpdate();
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement1 = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement1.setObject(1, 2);
+ insertPreparedStatement1.setString(2, "cipher");
+ insertPreparedStatement1.setString(3, "plain");
+ insertPreparedStatement1.execute();
+ PreparedStatement insertPreparedStatement2 = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement2.setObject(1, 1);
+ insertPreparedStatement2.setString(2, "cipher_pwd");
+ insertPreparedStatement2.setString(3, "plain");
+ insertPreparedStatement2.execute();
+ PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
+ deletePreparedStatement.setObject(1, 2);
+ result = deletePreparedStatement.executeUpdate();
}
assertThat(result, is(1));
- assertResultSet(true, 99, 1, "cipher_pwd");
+ assertResultSet(true, 1, "cipher_pwd");
+ assertResultSet(false, 0, "cipher_pwd");
}
@Test
- public void assertShadowUpdateConditionWithExecuteUpdate() throws SQLException {
+ public void assertDeleteShadowCase() throws SQLException {
int result;
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(SHADOW_UPDATE_SQL_WITH_CONDITION)) {
- statement.setString(1, "cipher_pwd");
- statement.setInt(2, 99);
- result = statement.executeUpdate();
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement1 = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement1.setObject(1, 1);
+ insertPreparedStatement1.setString(2, "cipher_pwd");
+ insertPreparedStatement1.setString(3, "plain");
+ insertPreparedStatement1.execute();
+ PreparedStatement insertPreparedStatement2 = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement2.setObject(1, 2);
+ insertPreparedStatement2.setString(2, "cipher");
+ insertPreparedStatement2.setString(3, "plain");
+ insertPreparedStatement2.execute();
+ PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
+ deletePreparedStatement.setObject(1, 1);
+ result = deletePreparedStatement.executeUpdate();
}
assertThat(result, is(1));
- assertResultSet(true, 99, 1, "cipher_pwd");
+ assertResultSet(true, 0, "cipher_pwd");
+ assertResultSet(false, 1, "cipher");
}
- private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
- DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
- try (Statement statement = dataSource.getConnection().createStatement()) {
- ResultSet resultSet = statement.executeQuery(SELECT_SQL);
- int count = 1;
+ @Test
+ public void assertSelectNativeCase() throws SQLException {
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement.setObject(1, 2);
+ insertPreparedStatement.setString(2, "cipher");
+ insertPreparedStatement.setString(3, "plain");
+ insertPreparedStatement.execute();
+ PreparedStatement selectPreparedStatement = connection.prepareStatement(SELECT_SQL);
+ selectPreparedStatement.setObject(1, 2);
+ ResultSet resultSet = selectPreparedStatement.executeQuery();
+ int count = 0;
while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
+ assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
count += 1;
}
- assertThat(count - 1, is(resultSetCount));
+ assertThat(count, is(1));
+ PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
+ deletePreparedStatement.setObject(1, 2);
+ deletePreparedStatement.executeUpdate();
}
+ assertResultSet(true, 0, "cipher");
+ assertResultSet(false, 0, "cipher");
}
- private void assertResultSet(final boolean isShadow, final int id, final int resultSetCount, final Object cipherPwd) throws SQLException {
- DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
- try (PreparedStatement statement = dataSource.getConnection().prepareStatement(SELECT_SQL_BY_ID)) {
- statement.setObject(1, id);
- ResultSet resultSet = statement.executeQuery();
- int count = 1;
+ @Test
+ public void assertSelectShadowCase() throws SQLException {
+ try (Connection connection = getShadowDataSource().getConnection()) {
+ PreparedStatement insertPreparedStatement = connection.prepareStatement(INSERT_SQL);
+ insertPreparedStatement.setObject(1, 1);
+ insertPreparedStatement.setString(2, "cipher_pwd");
+ insertPreparedStatement.setString(3, "plain");
+ insertPreparedStatement.execute();
+ PreparedStatement selectPreparedStatement = connection.prepareStatement(SELECT_SQL);
+ selectPreparedStatement.setObject(1, 1);
+ ResultSet resultSet = selectPreparedStatement.executeQuery();
+ int count = 0;
while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
+ assertThat(resultSet.getObject("cipher_pwd"), is("cipher_pwd"));
count += 1;
}
- assertThat(count - 1, is(resultSetCount));
- }
- }
-
- @Before
- public void init() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
- statement.setObject(1, 99);
- statement.setString(2, "cipher");
- statement.setString(3, "plain");
- statement.setBoolean(4, false);
- statement.execute();
- }
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
- statement.setObject(1, 99);
- statement.setString(2, "cipher");
- statement.setString(3, "plain");
- statement.setBoolean(4, true);
- statement.execute();
+ assertThat(count, is(1));
+ PreparedStatement deletePreparedStatement = connection.prepareStatement(DELETE_SQL);
+ deletePreparedStatement.setObject(1, 1);
+ deletePreparedStatement.executeUpdate();
}
+ assertResultSet(true, 0, "cipher_pwd");
+ assertResultSet(false, 0, "cipher_pwd");
}
@After
public void clean() throws SQLException {
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(CLEAN_SQL)) {
- statement.setBoolean(1, false);
- statement.execute();
+ try (Statement statement = getActualDataSources().get("shadow_jdbc_0").getConnection().createStatement()) {
+ statement.execute(CLEAN_SQL);
}
- try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(CLEAN_SQL)) {
- statement.setBoolean(1, true);
- statement.execute();
+ try (Statement statement = getActualDataSources().get("shadow_jdbc_1").getConnection().createStatement()) {
+ statement.execute(CLEAN_SQL);
}
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowStatementTest.java
index 83d45b0..eae9dd7 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShadowStatementTest.java
@@ -27,122 +27,149 @@ import java.sql.SQLException;
import java.sql.Statement;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class ShadowStatementTest extends AbstractShardingSphereDataSourceForShadowTest {
- private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (1, 'cipher', 'plain')";
+ private static final String CLEAN_SQL = "DELETE FROM t_encrypt";
- private static final String SHADOW_INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd, shadow) VALUES (1, 'cipher', 'plain', TRUE)";
+ private static final String INSERT_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (2, 'cipher', 'plain')";
- private static final String INSERT_GENERATED_KEY_SQL = "INSERT INTO t_encrypt (cipher_pwd, plain_pwd) VALUES ('cipher', 'plain')";
+ private static final String INSERT_SHADOW_SQL = "INSERT INTO t_encrypt (id, cipher_pwd, plain_pwd) VALUES (1, 'cipher', 'plain')";
- private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE plain_pwd = 'plain'";
+ private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 2";
- private static final String SHADOW_DELETE_SQL = "DELETE FROM t_encrypt WHERE plain_pwd = 'plain' AND shadow = TRUE";
+ private static final String UPDATE_SHADOW_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 1";
- private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = 1";
+ private static final String DELETE_SQL = "DELETE FROM t_encrypt WHERE id = 2";
- private static final String CLEAN_SHADOW_SQL = "DELETE FROM t_encrypt WHERE shadow = TRUE";
+ private static final String DELETE_SHADOW_SQL = "DELETE FROM t_encrypt WHERE id = 1";
- private static final String CLEAN_SQL = "DELETE FROM t_encrypt";
+ private static final String SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = 2";
- private static final String UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 1";
+ private static final String SELECT_SHADOW_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt WHERE id = 1";
- private static final String SHADOW_UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd ='cipher_pwd' WHERE id = 1 AND shadow = TRUE";
+ private static final String RESULT_SELECT_SQL = "SELECT id, cipher_pwd, plain_pwd FROM t_encrypt";
@Test
- public void assertInsertWithExecute() throws SQLException {
+ public void assertInsertNativeCase() throws SQLException {
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
statement.execute(INSERT_SQL);
}
- assertResultSet(false, 1, "cipher");
assertResultSet(true, 0, "cipher");
+ assertResultSet(false, 1, "cipher");
+ }
+
+ private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
+ DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
+ try (Statement statement = dataSource.getConnection().createStatement()) {
+ ResultSet resultSet = statement.executeQuery(RESULT_SELECT_SQL);
+ int count = 0;
+ while (resultSet.next()) {
+ assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
+ count += 1;
+ }
+ assertThat(count, is(resultSetCount));
+ }
}
@Test
- public void assertShadowInsertWithExecute() throws SQLException {
+ public void assertInsertShadowCase() throws SQLException {
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(SHADOW_INSERT_SQL);
+ statement.execute(INSERT_SHADOW_SQL);
}
- assertResultSet(false, 0, "cipher");
assertResultSet(true, 1, "cipher");
+ assertResultSet(false, 0, "cipher");
}
@Test
- public void assertInsertWithExecuteWithGeneratedKey() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
- statement.execute(INSERT_GENERATED_KEY_SQL, Statement.RETURN_GENERATED_KEYS);
- ResultSet resultSet = statement.getGeneratedKeys();
- assertTrue(resultSet.next());
- assertTrue(resultSet.getInt(1) > 0);
- assertFalse(resultSet.next());
+ public void assertUpdateNativeCase() throws SQLException {
+ int result;
+ try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
+ statement.execute(INSERT_SQL);
+ result = statement.executeUpdate(UPDATE_SQL);
}
- assertResultSet(true, 0, "cipher");
+ assertThat(result, is(1));
+ assertResultSet(true, 0, "cipher_pwd");
+ assertResultSet(false, 1, "cipher_pwd");
+
}
- private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
- DataSource dataSource = isShadow ? getActualDataSources().get("shadow_jdbc_1") : getActualDataSources().get("shadow_jdbc_0");
- try (Statement statement = dataSource.getConnection().createStatement()) {
- ResultSet resultSet = statement.executeQuery(SELECT_SQL);
- int count = 1;
- while (resultSet.next()) {
- assertThat(resultSet.getObject("cipher_pwd"), is(cipherPwd));
- count += 1;
- }
- assertThat(count - 1, is(resultSetCount));
+ @Test
+ public void assertUpdateShadowCase() throws SQLException {
+ int result;
+ try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
+ statement.execute(INSERT_SHADOW_SQL);
+ result = statement.executeUpdate(UPDATE_SHADOW_SQL);
}
+ assertThat(result, is(1));
+ assertResultSet(true, 1, "cipher_pwd");
+ assertResultSet(false, 0, "cipher_pwd");
}
@Test
- public void assertDeleteWithExecute() throws SQLException {
+ public void assertDeleteNativeCase() throws SQLException {
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
statement.execute(INSERT_SQL);
+ statement.execute(INSERT_SHADOW_SQL);
statement.execute(DELETE_SQL);
}
+ assertResultSet(true, 1, "cipher");
assertResultSet(false, 0, "cipher");
}
@Test
- public void assertShadowDeleteWithExecute() throws SQLException {
+ public void assertDeleteShadowCase() throws SQLException {
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(SHADOW_INSERT_SQL);
- statement.execute(SHADOW_DELETE_SQL);
+ statement.execute(INSERT_SQL);
+ statement.execute(INSERT_SHADOW_SQL);
+ statement.execute(DELETE_SHADOW_SQL);
}
assertResultSet(true, 0, "cipher");
+ assertResultSet(false, 1, "cipher");
}
@Test
- public void assertUpdateWithExecuteUpdate() throws SQLException {
- int result;
+ public void assertSelectNativeCase() throws SQLException {
+ ResultSet resultSet;
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
statement.execute(INSERT_SQL);
- result = statement.executeUpdate(UPDATE_SQL);
+ resultSet = statement.executeQuery(SELECT_SQL);
+ int count = 0;
+ while (resultSet.next()) {
+ assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
+ count += 1;
+ }
+ assertThat(count, is(1));
+ statement.execute(DELETE_SQL);
}
- assertThat(result, is(1));
- assertResultSet(false, 1, "cipher_pwd");
+ assertResultSet(false, 0, "cipher");
}
@Test
- public void assertShadowUpdateWithExecuteUpdate() throws SQLException {
- int result;
+ public void assertSelectShadowCase() throws SQLException {
+ ResultSet resultSet;
try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(SHADOW_INSERT_SQL);
- result = statement.executeUpdate(SHADOW_UPDATE_SQL);
+ statement.execute(INSERT_SHADOW_SQL);
+ resultSet = statement.executeQuery(SELECT_SHADOW_SQL);
+ int count = 0;
+ while (resultSet.next()) {
+ assertThat(resultSet.getObject("cipher_pwd"), is("cipher"));
+ count += 1;
+ }
+ assertThat(count, is(1));
+ statement.execute(DELETE_SHADOW_SQL);
}
- assertThat(result, is(1));
- assertResultSet(true, 1, "cipher_pwd");
+ assertResultSet(true, 0, "cipher");
}
@After
public void clean() throws SQLException {
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
+ try (Statement statement = getActualDataSources().get("shadow_jdbc_0").getConnection().createStatement()) {
statement.execute(CLEAN_SQL);
}
- try (Statement statement = getShadowDataSource().getConnection().createStatement()) {
- statement.execute(CLEAN_SHADOW_SQL);
+ try (Statement statement = getActualDataSources().get("shadow_jdbc_1").getConnection().createStatement()) {
+ statement.execute(CLEAN_SQL);
}
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-future-shadow.yaml b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-future-shadow.yaml
deleted file mode 100644
index de5545d..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-future-shadow.yaml
+++ /dev/null
@@ -1,69 +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.
-#
-
-schemaName: logic_db
-
-props:
- sql-show: true
-
-rules:
-- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - shadow_jdbc_0
- shadowDataSourceNames:
- - shadow_jdbc_1
-
- enable: true
- dataSources:
- shadowDataSource0:
- sourceDataSourceName: shadow_jdbc_0
- shadowDataSourceName: shadow_jdbc_1
- tables:
- t_encrypt:
- dataSourceNames:
- - shadowDataSource0
- shadowAlgorithmNames:
- - id-insert-match-algorithm
- - id-update-match-algorithm
- - id-delete-match-algorithm
- - id-select-match-algorithm
- shadowAlgorithms:
- id-insert-match-algorithm:
- type: COLUMN_REGEX_MATCH
- props:
- operation: insert
- column: id
- regex: "[1]"
- id-update-match-algorithm:
- type: COLUMN_REGEX_MATCH
- props:
- operation: update
- column: id
- regex: "[1]"
- id-delete-match-algorithm:
- type: COLUMN_REGEX_MATCH
- props:
- operation: delete
- column: id
- regex: "[1]"
- id-select-match-algorithm:
- type: COLUMN_REGEX_MATCH
- props:
- operation: select
- column: id
- regex: "[1]"
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-shadow.yaml b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-shadow.yaml
index aa74be2..a4b5b12 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-shadow.yaml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config/config-shadow.yaml
@@ -17,10 +17,47 @@
schemaName: logic_db
+props:
+ sql-show: true
+
rules:
- !SHADOW
- column: shadow
- sourceDataSourceNames:
- - shadow_jdbc_0
- shadowDataSourceNames:
- - shadow_jdbc_1
\ No newline at end of file
+ enable: true
+ dataSources:
+ shadowDataSource0:
+ sourceDataSourceName: shadow_jdbc_0
+ shadowDataSourceName: shadow_jdbc_1
+ tables:
+ t_encrypt:
+ dataSourceNames:
+ - shadowDataSource0
+ shadowAlgorithmNames:
+ - id-insert-match-algorithm
+ - id-update-match-algorithm
+ - id-delete-match-algorithm
+ - id-select-match-algorithm
+ shadowAlgorithms:
+ id-insert-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: insert
+ column: id
+ regex: "[1]"
+ id-update-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: update
+ column: id
+ regex: "[1]"
+ id-delete-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: delete
+ column: id
+ regex: "[1]"
+ id-select-match-algorithm:
+ type: COLUMN_REGEX_MATCH
+ props:
+ operation: select
+ column: id
+ regex: "[1]"
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
index 5aa5ed7..b042435 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
@@ -30,7 +30,12 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.readwritesplitting.algorithm.RandomReplicaLoadBalanceAlgorithm;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.rule.ShadowDataSourceRule;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.shadow.rule.ShadowTableRule;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -138,8 +143,32 @@ public class SpringBootStarterTest {
}
private void assertShadowRule(final ShadowRule rule) {
- assertThat(rule.getColumn(), is("shadow"));
- assertThat(rule.getShadowMappings(), is(Collections.singletonMap("ds", "shadow_ds")));
+ assertThat(rule.isEnable(), is(true));
+ assertShadowDataSourceMappings(rule.getShadowDataSourceMappings());
+ assertShadowAlgorithms(rule.getShadowAlgorithms());
+ assertShadowTableRules(rule.getShadowTableRules());
+ }
+
+ private void assertShadowTableRules(final Map<String, ShadowTableRule> shadowTableRules) {
+ assertThat(shadowTableRules.size(), is(2));
+ assertThat(shadowTableRules.get("t_order").getTableName(), is("t_order"));
+ assertThat(shadowTableRules.get("t_order").getShadowDataSources().size(), is(1));
+ assertThat(shadowTableRules.get("t_order").getShadowAlgorithmNames().size(), is(2));
+ assertThat(shadowTableRules.get("t_user").getTableName(), is("t_user"));
+ assertThat(shadowTableRules.get("t_user").getShadowDataSources().size(), is(1));
+ assertThat(shadowTableRules.get("t_user").getShadowAlgorithmNames().size(), is(1));
+ }
+
+ private void assertShadowAlgorithms(final Map<String, ShadowAlgorithm> shadowAlgorithms) {
+ assertThat(shadowAlgorithms.size(), is(2));
+ assertThat(shadowAlgorithms.get("user-id-match-algorithm") instanceof ColumnShadowAlgorithm, is(true));
+ assertThat(shadowAlgorithms.get("simple-note-algorithm") instanceof NoteShadowAlgorithm, is(true));
+ }
+
+ private void assertShadowDataSourceMappings(final Map<String, ShadowDataSourceRule> shadowDataSourceMappings) {
+ assertThat(shadowDataSourceMappings.size(), is(1));
+ assertThat(shadowDataSourceMappings.get("shadow-data-source").getSourceDataSource(), is("ds"));
+ assertThat(shadowDataSourceMappings.get("shadow-data-source").getShadowDataSource(), is("ds-shadow"));
}
@Test
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-common.properties b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-common.properties
index 7bc00cd..f1ee8f4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-common.properties
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-common.properties
@@ -51,9 +51,23 @@ spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.assisted-query-co
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.plain-column=pwd_plain
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.encryptor-name=aesEncryptor
-spring.shardingsphere.rules.shadow.column=shadow
-spring.shardingsphere.rules.shadow.sourceDataSourceNames=ds
-spring.shardingsphere.rules.shadow.shadowDataSourceNames=shadow_ds
+spring.shardingsphere.rules.shadow.enable=true
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.source-data-source-name=ds
+spring.shardingsphere.rules.shadow.data-sources.shadow-data-source.shadow-data-source-name=ds-shadow
+
+spring.shardingsphere.rules.shadow.tables.t_order.data-source-names=shadow-data-source
+spring.shardingsphere.rules.shadow.tables.t_order.shadow-algorithm-names=user-id-match-algorithm,simple-note-algorithm
+spring.shardingsphere.rules.shadow.tables.t_user.data-source-names=shadow-data-source
+spring.shardingsphere.rules.shadow.tables.t_user.shadow-algorithm-names=simple-note-algorithm
+
+spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-match-algorithm.type=COLUMN_REGEX_MATCH
+spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-match-algorithm.props.operation=insert
+spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-match-algorithm.props.column=user_id
+spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-match-algorithm.props.regex=[1]
+
+spring.shardingsphere.rules.shadow.shadow-algorithms.simple-note-algorithm.type=SIMPLE_NOTE
+spring.shardingsphere.rules.shadow.shadow-algorithms.simple-note-algorithm.props.shadow=true
+spring.shardingsphere.rules.shadow.shadow-algorithms.simple-note-algorithm.props.foo=bar
spring.shardingsphere.props.sql-show=true
spring.shardingsphere.props.kernel-executor-size=10
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-shadow.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-shadow.yaml
index 25c08a8..958ad72 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-shadow.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-shadow.yaml
@@ -46,13 +46,57 @@
#
#rules:
#- !SHADOW
-# column: shadow
-# sourceDataSourceNames:
-# - ds
-# shadowDataSourceNames:
-# - shadow_ds
-#
-#
+# enable: true
+# dataSources:
+# shadowDataSource:
+# sourceDataSourceName: ds
+# shadowDataSourceName: shadow_ds
+# tables:
+# t_order:
+# dataSourceNames:
+# - shadowDataSource
+# shadowAlgorithmNames:
+# - user-id-insert-match-algorithm
+# - user-id-select-match-algorithm
+# t_order_item:
+# dataSourceNames:
... 99 lines suppressed ...