From abc97fb777b0fb0ad3e8c268aa2290735cd7ab7f Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 4 Nov 2024 00:54:01 +0800 Subject: [PATCH] Refactor ShadowDataSourceMappingsFinderFactory (#33522) * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add test cases on ShadowRuleConfigurationChecker * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory * Refactor ShadowDataSourceMappingsFinderFactory --- .../shadow/route/ShadowSQLRouter.java | 27 +++++++- .../ColumnShadowAlgorithmDeterminer.java | 2 +- .../HintShadowAlgorithmDeterminer.java | 6 +- .../route/engine/ShadowRouteEngine.java | 63 ------------------- .../ShadowDataSourceMappingsFinder.java | 2 +- ...ShadowDataSourceMappingsFinderFactory.java | 43 +++++++------ ...wDMLStatementDataSourceMappingsFinder.java | 8 +-- ...leteStatementDataSourceMappingsFinder.java | 4 +- ...sertStatementDataSourceMappingsFinder.java | 2 +- ...lectStatementDataSourceMappingsFinder.java | 4 +- ...dateStatementDataSourceMappingsFinder.java | 4 +- ...nDMLStatementDataSourceMappingsFinder.java | 10 +-- .../{engine => }/util/ShadowExtractor.java | 2 +- .../ColumnShadowAlgorithmDeterminerTest.java | 6 +- .../HintShadowAlgorithmDeterminerTest.java | 2 +- ...wDataSourceMappingsFinderFactoryTest.java} | 13 ++-- .../ShadowNonDMLStatementRouteEngineTest.java | 2 +- .../util/ShadowExtractorTest.java | 2 +- 18 files changed, 79 insertions(+), 123 deletions(-) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/determiner/ColumnShadowAlgorithmDeterminer.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/determiner/HintShadowAlgorithmDeterminer.java (90%) delete mode 100644 features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/ShadowDataSourceMappingsFinder.java (95%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => finder}/ShadowDataSourceMappingsFinderFactory.java (72%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java (95%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java (95%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java (96%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java (96%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java (83%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/{engine => }/util/ShadowExtractor.java (98%) rename features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/{engine => }/determiner/ColumnShadowAlgorithmDeterminerTest.java (97%) rename features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/{engine => }/determiner/HintShadowAlgorithmDeterminerTest.java (98%) rename features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/{engine/ShadowRouteEngineFactoryTest.java => finder/ShadowDataSourceMappingsFinderFactoryTest.java} (90%) rename features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/{engine => }/finder/other/ShadowNonDMLStatementRouteEngineTest.java (97%) rename features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/{engine => }/util/ShadowExtractorTest.java (98%) diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java index 2143efaecf742..1b8ff3be53ed1 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java @@ -22,12 +22,18 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.route.DecorateSQLRouter; 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.infra.session.query.QueryContext; import org.apache.shardingsphere.shadow.constant.ShadowOrder; -import org.apache.shardingsphere.shadow.route.engine.ShadowDataSourceMappingsFinderFactory; -import org.apache.shardingsphere.shadow.route.engine.ShadowRouteEngine; +import org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinderFactory; import org.apache.shardingsphere.shadow.rule.ShadowRule; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Map; +import java.util.Optional; + /** * Shadow SQL router. */ @@ -37,7 +43,22 @@ public final class ShadowSQLRouter implements DecorateSQLRouter { @Override public void decorateRouteContext(final RouteContext routeContext, final QueryContext queryContext, final ShardingSphereDatabase database, final ShadowRule rule, final ConfigurationProperties props) { - new ShadowRouteEngine().route(routeContext, rule, ShadowDataSourceMappingsFinderFactory.newInstance(queryContext)); + Collection toBeRemovedRouteUnit = new LinkedList<>(); + Collection toBeAddedRouteUnit = new LinkedList<>(); + Map shadowDataSourceMappings = ShadowDataSourceMappingsFinderFactory.newInstance(queryContext).find(rule); + for (RouteUnit each : routeContext.getRouteUnits()) { + String logicName = each.getDataSourceMapper().getLogicName(); + String actualName = each.getDataSourceMapper().getActualName(); + Optional productionDataSourceName = rule.findProductionDataSourceName(actualName); + if (productionDataSourceName.isPresent()) { + String shadowDataSourceName = shadowDataSourceMappings.get(productionDataSourceName.get()); + toBeRemovedRouteUnit.add(each); + String dataSourceName = null == shadowDataSourceName ? productionDataSourceName.get() : shadowDataSourceName; + toBeAddedRouteUnit.add(new RouteUnit(new RouteMapper(logicName, dataSourceName), each.getTableMappers())); + } + } + routeContext.getRouteUnits().removeAll(toBeRemovedRouteUnit); + routeContext.getRouteUnits().addAll(toBeAddedRouteUnit); } @Override diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminer.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminer.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java index ce48e9d13ee88..f1ffac30c7cf7 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminer.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.determiner; +package org.apache.shardingsphere.shadow.route.determiner; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminer.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java similarity index 90% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminer.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java index 107020c2caf9f..037bea3c3d2b7 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminer.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.determiner; +package org.apache.shardingsphere.shadow.route.determiner; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -41,11 +41,11 @@ public final class HintShadowAlgorithmDeterminer { * @return is shadow or not */ public static boolean isShadow(final HintShadowAlgorithm> shadowAlgorithm, final ShadowDetermineCondition shadowCondition, final ShadowRule shadowRule, final boolean useShadow) { - PreciseHintShadowValue> shadowValue = createNoteShadowValues(shadowCondition, useShadow); + PreciseHintShadowValue> shadowValue = createHintShadowValues(shadowCondition, useShadow); return shadowAlgorithm.isShadow(shadowRule.getAllShadowTableNames(), shadowValue); } - private static PreciseHintShadowValue> createNoteShadowValues(final ShadowDetermineCondition shadowDetermineCondition, final boolean useShadow) { + private static PreciseHintShadowValue> createHintShadowValues(final ShadowDetermineCondition shadowDetermineCondition, final boolean useShadow) { ShadowOperationType shadowOperationType = shadowDetermineCondition.getShadowOperationType(); String tableName = shadowDetermineCondition.getTableName(); return new PreciseHintShadowValue<>(tableName, shadowOperationType, useShadow); diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java deleted file mode 100644 index 1dae3f8a86725..0000000000000 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngine.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.shadow.route.engine; - -import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; -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.route.engine.finder.ShadowDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.rule.ShadowRule; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; -import java.util.Optional; - -/** - * Shadow route engine. - */ -@HighFrequencyInvocation -public final class ShadowRouteEngine { - - /** - * Route. - * - * @param routeContext route context - * @param rule shadow rule - * @param finder finder - */ - public void route(final RouteContext routeContext, final ShadowRule rule, final ShadowDataSourceMappingsFinder finder) { - Collection toBeRemovedRouteUnit = new LinkedList<>(); - Collection toBeAddedRouteUnit = new LinkedList<>(); - Map shadowDataSourceMappings = finder.find(rule); - for (RouteUnit each : routeContext.getRouteUnits()) { - String logicName = each.getDataSourceMapper().getLogicName(); - String actualName = each.getDataSourceMapper().getActualName(); - Optional productionDataSourceName = rule.findProductionDataSourceName(actualName); - if (productionDataSourceName.isPresent()) { - String shadowDataSourceName = shadowDataSourceMappings.get(productionDataSourceName.get()); - toBeRemovedRouteUnit.add(each); - String dataSourceName = null == shadowDataSourceName ? productionDataSourceName.get() : shadowDataSourceName; - toBeAddedRouteUnit.add(new RouteUnit(new RouteMapper(logicName, dataSourceName), each.getTableMappers())); - } - } - routeContext.getRouteUnits().removeAll(toBeRemovedRouteUnit); - routeContext.getRouteUnits().addAll(toBeAddedRouteUnit); - } -} diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/ShadowDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinder.java similarity index 95% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/ShadowDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinder.java index 3bd42e20e3f12..4fe987b35ffe8 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/ShadowDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder; +package org.apache.shardingsphere.shadow.route.finder; import org.apache.shardingsphere.shadow.rule.ShadowRule; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowDataSourceMappingsFinderFactory.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactory.java similarity index 72% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowDataSourceMappingsFinderFactory.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactory.java index 52eb12f96b064..7d18d579388b6 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/ShadowDataSourceMappingsFinderFactory.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine; +package org.apache.shardingsphere.shadow.route.finder; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -24,12 +24,11 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.shadow.route.engine.finder.ShadowDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowDeleteStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowInsertStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowSelectStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowUpdateStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.other.ShadowNonDMLStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowDeleteStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowInsertStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowSelectStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowUpdateStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.other.ShadowNonDMLStatementDataSourceMappingsFinder; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; @@ -37,7 +36,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; /** - * Shadow data source mappings finder. + * Shadow data source mappings finder factory. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ShadowDataSourceMappingsFinderFactory { @@ -51,37 +50,37 @@ public final class ShadowDataSourceMappingsFinderFactory { public static ShadowDataSourceMappingsFinder newInstance(final QueryContext queryContext) { SQLStatement sqlStatement = queryContext.getSqlStatementContext().getSqlStatement(); if (sqlStatement instanceof InsertStatement) { - return createShadowInsertStatementRouteEngine(queryContext); + return createShadowInsertStatementDataSourceMappingsFinder(queryContext); } if (sqlStatement instanceof DeleteStatement) { - return createShadowDeleteStatementRouteEngine(queryContext); + return createShadowDeleteStatementDataSourceMappingsFinder(queryContext); } if (sqlStatement instanceof UpdateStatement) { - return createShadowUpdateStatementRouteEngine(queryContext); + return createShadowUpdateStatementDataSourceMappingsFinder(queryContext); } if (sqlStatement instanceof SelectStatement) { - return createShadowSelectStatementRouteEngine(queryContext); + return createShadowSelectStatementDataSourceMappingsFinder(queryContext); } - return createShadowNonMDLStatementRouteEngine(queryContext); + return createShadowNonMDLStatementDataSourceMappingsFinder(queryContext); } - private static ShadowDataSourceMappingsFinder createShadowNonMDLStatementRouteEngine(final QueryContext queryContext) { - return new ShadowNonDMLStatementDataSourceMappingsFinder(queryContext.getHintValueContext()); + private static ShadowDataSourceMappingsFinder createShadowInsertStatementDataSourceMappingsFinder(final QueryContext queryContext) { + return new ShadowInsertStatementDataSourceMappingsFinder((InsertStatementContext) queryContext.getSqlStatementContext(), queryContext.getHintValueContext()); } - private static ShadowDataSourceMappingsFinder createShadowSelectStatementRouteEngine(final QueryContext queryContext) { - return new ShadowSelectStatementDataSourceMappingsFinder((SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); + private static ShadowDataSourceMappingsFinder createShadowDeleteStatementDataSourceMappingsFinder(final QueryContext queryContext) { + return new ShadowDeleteStatementDataSourceMappingsFinder((DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); } - private static ShadowDataSourceMappingsFinder createShadowUpdateStatementRouteEngine(final QueryContext queryContext) { + private static ShadowDataSourceMappingsFinder createShadowUpdateStatementDataSourceMappingsFinder(final QueryContext queryContext) { return new ShadowUpdateStatementDataSourceMappingsFinder((UpdateStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); } - private static ShadowDataSourceMappingsFinder createShadowDeleteStatementRouteEngine(final QueryContext queryContext) { - return new ShadowDeleteStatementDataSourceMappingsFinder((DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); + private static ShadowDataSourceMappingsFinder createShadowSelectStatementDataSourceMappingsFinder(final QueryContext queryContext) { + return new ShadowSelectStatementDataSourceMappingsFinder((SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); } - private static ShadowDataSourceMappingsFinder createShadowInsertStatementRouteEngine(final QueryContext queryContext) { - return new ShadowInsertStatementDataSourceMappingsFinder((InsertStatementContext) queryContext.getSqlStatementContext(), queryContext.getHintValueContext()); + private static ShadowDataSourceMappingsFinder createShadowNonMDLStatementDataSourceMappingsFinder(final QueryContext queryContext) { + return new ShadowNonDMLStatementDataSourceMappingsFinder(queryContext.getHintValueContext()); } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java similarity index 95% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java index 0af9b1c0a80b2..35df01ab9b8d3 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.dml; +package org.apache.shardingsphere.shadow.route.finder.dml; import lombok.Getter; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; @@ -24,9 +24,9 @@ import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition; -import org.apache.shardingsphere.shadow.route.engine.determiner.ColumnShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.engine.determiner.HintShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.engine.finder.ShadowDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.determiner.ColumnShadowAlgorithmDeterminer; +import org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer; +import org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinder; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java similarity index 95% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java index 9c956cb7837f0..6c86f6d8cb86f 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowDeleteStatementDataSourceMappingsFinder.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.dml; +package org.apache.shardingsphere.shadow.route.finder.dml; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; -import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor; +import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java index 1abc47c5a8d3d..3cb306f42b56c 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowInsertStatementDataSourceMappingsFinder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.dml; +package org.apache.shardingsphere.shadow.route.finder.dml; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java similarity index 96% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java index 6dd87aae7432f..5c1aa683cbf53 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowSelectStatementDataSourceMappingsFinder.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.dml; +package org.apache.shardingsphere.shadow.route.finder.dml; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.hint.HintValueContext; +import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; -import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java similarity index 96% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java index 8bcf3358e9451..052c6fcde7e9a 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/ShadowUpdateStatementDataSourceMappingsFinder.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.dml; +package org.apache.shardingsphere.shadow.route.finder.dml; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.infra.hint.HintValueContext; +import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; -import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java similarity index 83% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java index 68ce6113566c9..f055cc1dbf197 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.other; +package org.apache.shardingsphere.shadow.route.finder.other; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition; -import org.apache.shardingsphere.shadow.route.engine.determiner.HintShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.engine.finder.ShadowDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer; +import org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinder; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; @@ -41,13 +41,13 @@ public Map find(final ShadowRule rule) { if (!hintValueContext.isShadow()) { return Collections.emptyMap(); } - if (isMatchAnyNoteShadowAlgorithms(rule, new ShadowDetermineCondition("", ShadowOperationType.HINT_MATCH))) { + if (isMatchAnyHintShadowAlgorithms(rule, new ShadowDetermineCondition("", ShadowOperationType.HINT_MATCH))) { return rule.getAllShadowDataSourceMappings(); } return Collections.emptyMap(); } - private boolean isMatchAnyNoteShadowAlgorithms(final ShadowRule rule, final ShadowDetermineCondition shadowCondition) { + private boolean isMatchAnyHintShadowAlgorithms(final ShadowRule rule, final ShadowDetermineCondition shadowCondition) { return rule.getAllHintShadowAlgorithms().stream().anyMatch(each -> HintShadowAlgorithmDeterminer.isShadow(each, shadowCondition, rule, hintValueContext.isShadow())); } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractor.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractor.java index 34a464268df05..acabd477e2a41 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.util; +package org.apache.shardingsphere.shadow.route.util; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java similarity index 97% rename from features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java rename to features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java index b9caa6ad88def..ae733e38c7f3c 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.determiner; +package org.apache.shardingsphere.shadow.route.determiner; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.shadow.spi.ShadowOperationType; -import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition; import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm; +import org.apache.shardingsphere.shadow.spi.ShadowOperationType; +import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.jupiter.api.Test; diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java similarity index 98% rename from features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java rename to features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java index 3a0a77061c69f..b51d023c45572 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.determiner; +package org.apache.shardingsphere.shadow.route.determiner; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.hint.HintValueContext; diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactoryTest.java similarity index 90% rename from features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java rename to features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactoryTest.java index a6ed9cce16134..4c5d960a6ed66 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/ShadowRouteEngineFactoryTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/ShadowDataSourceMappingsFinderFactoryTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine; +package org.apache.shardingsphere.shadow.route.finder; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; @@ -27,11 +27,10 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.shadow.route.engine.finder.ShadowDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowDeleteStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowInsertStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowSelectStatementDataSourceMappingsFinder; -import org.apache.shardingsphere.shadow.route.engine.finder.dml.ShadowUpdateStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowDeleteStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowInsertStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowSelectStatementDataSourceMappingsFinder; +import org.apache.shardingsphere.shadow.route.finder.dml.ShadowUpdateStatementDataSourceMappingsFinder; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; @@ -47,7 +46,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class ShadowRouteEngineFactoryTest { +class ShadowDataSourceMappingsFinderFactoryTest { @Test void assertNewInstance() { diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementRouteEngineTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementRouteEngineTest.java similarity index 97% rename from features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementRouteEngineTest.java rename to features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementRouteEngineTest.java index 5a70f58bad27e..82760b410bc38 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/finder/other/ShadowNonDMLStatementRouteEngineTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementRouteEngineTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.finder.other; +package org.apache.shardingsphere.shadow.route.finder.other; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.hint.HintValueContext; diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractorTest.java similarity index 98% rename from features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java rename to features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractorTest.java index da0b789234ebf..8abb63126f9e3 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/util/ShadowExtractorTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.engine.util; +package org.apache.shardingsphere.shadow.route.util; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;