Skip to content

Commit

Permalink
Rename ShadowDataSourceMappingsRetriever (#33551)
Browse files Browse the repository at this point in the history
* Rename ShadowDataSourceMappingsRetriever

* Rename ShadowDataSourceMappingsRetriever
  • Loading branch information
terrymanu authored Nov 5, 2024
1 parent 30f538e commit 479d4e7
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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.finder.ShadowDataSourceMappingsFinderFactory;
import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetrieverFactory;
import org.apache.shardingsphere.shadow.rule.ShadowRule;

import java.util.Collection;
Expand All @@ -45,7 +45,7 @@ public void decorateRouteContext(final RouteContext routeContext, final QueryCon
final ShadowRule rule, final ConfigurationProperties props) {
Collection<RouteUnit> toBeRemovedRouteUnit = new LinkedList<>();
Collection<RouteUnit> toBeAddedRouteUnit = new LinkedList<>();
Map<String, String> shadowDataSourceMappings = ShadowDataSourceMappingsFinderFactory.newInstance(queryContext).find(rule);
Map<String, String> shadowDataSourceMappings = ShadowDataSourceMappingsRetrieverFactory.newInstance(queryContext).retrieve(rule);
for (RouteUnit each : routeContext.getRouteUnits()) {
String logicName = each.getDataSourceMapper().getLogicName();
String actualName = each.getDataSourceMapper().getActualName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder;
package org.apache.shardingsphere.shadow.route.retriever;

import org.apache.shardingsphere.shadow.rule.ShadowRule;

import java.util.Map;

/**
* Shadow data source mappings finder.
* Shadow data source mappings retriever.
*/
public interface ShadowDataSourceMappingsFinder {
public interface ShadowDataSourceMappingsRetriever {

/**
* Find shadow data source mappings.
* Retrieve shadow data source mappings.
*
* @param rule shadow rule
* @return found shadow data source mappings
* @return retrieved shadow data source mappings
*/
Map<String, String> find(ShadowRule rule);
Map<String, String> retrieve(ShadowRule rule);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder;
package org.apache.shardingsphere.shadow.route.retriever;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -24,37 +24,41 @@
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.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.hint.ShadowHintDataSourceMappingsFinder;
import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowDeleteStatementDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowInsertStatementDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowSelectStatementDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowUpdateStatementDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.route.retriever.hint.ShadowHintDataSourceMappingsRetriever;

/**
* Shadow data source mappings finder factory.
* Shadow data source mappings retriever factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ShadowDataSourceMappingsFinderFactory {
public final class ShadowDataSourceMappingsRetrieverFactory {

/**
* Create new instance of shadow data source mappings finder.
* Create new instance of shadow data source mappings retriever.
*
* @param queryContext query context
* @return created instance
*/
public static ShadowDataSourceMappingsFinder newInstance(final QueryContext queryContext) {
public static ShadowDataSourceMappingsRetriever newInstance(final QueryContext queryContext) {
if (queryContext.getSqlStatementContext() instanceof InsertStatementContext) {
return new ShadowInsertStatementDataSourceMappingsFinder((InsertStatementContext) queryContext.getSqlStatementContext(), queryContext.getHintValueContext());
return new ShadowInsertStatementDataSourceMappingsRetriever(
(InsertStatementContext) queryContext.getSqlStatementContext(), queryContext.getHintValueContext());
}
if (queryContext.getSqlStatementContext() instanceof DeleteStatementContext) {
return new ShadowDeleteStatementDataSourceMappingsFinder((DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
return new ShadowDeleteStatementDataSourceMappingsRetriever(
(DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
}
if (queryContext.getSqlStatementContext() instanceof UpdateStatementContext) {
return new ShadowUpdateStatementDataSourceMappingsFinder((UpdateStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
return new ShadowUpdateStatementDataSourceMappingsRetriever(
(UpdateStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
}
if (queryContext.getSqlStatementContext() instanceof SelectStatementContext) {
return new ShadowSelectStatementDataSourceMappingsFinder((SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
return new ShadowSelectStatementDataSourceMappingsRetriever(
(SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext());
}
return new ShadowHintDataSourceMappingsFinder(queryContext.getHintValueContext());
return new ShadowHintDataSourceMappingsRetriever(queryContext.getHintValueContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.dml;
package org.apache.shardingsphere.shadow.route.retriever.dml;

import lombok.Getter;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
Expand All @@ -26,7 +26,7 @@
import org.apache.shardingsphere.shadow.condition.ShadowCondition;
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.route.retriever.ShadowDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
Expand All @@ -41,10 +41,10 @@
import java.util.Optional;

/**
* Abstract shadow DML statement data source mappings finder.
* Abstract shadow DML statement data source mappings retriever.
*/
@HighFrequencyInvocation
public abstract class AbstractShadowDMLStatementDataSourceMappingsFinder implements ShadowDataSourceMappingsFinder {
public abstract class AbstractShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever {

private final ShadowOperationType operationType;

Expand All @@ -53,7 +53,7 @@ public abstract class AbstractShadowDMLStatementDataSourceMappingsFinder impleme
@Getter
private final Map<String, String> tableAliasAndNameMappings;

protected AbstractShadowDMLStatementDataSourceMappingsFinder(final SQLStatementContext sqlStatementContext, final HintValueContext hintValueContext, final ShadowOperationType operationType) {
protected AbstractShadowDMLStatementDataSourceMappingsRetriever(final SQLStatementContext sqlStatementContext, final HintValueContext hintValueContext, final ShadowOperationType operationType) {
this.operationType = operationType;
isShadow = hintValueContext.isShadow();
tableAliasAndNameMappings = getTableAliasAndNameMappings(((TableAvailable) sqlStatementContext).getTablesContext().getSimpleTables());
Expand All @@ -70,7 +70,7 @@ private Map<String, String> getTableAliasAndNameMappings(final Collection<Simple
}

@Override
public Map<String, String> find(final ShadowRule rule) {
public Map<String, String> retrieve(final ShadowRule rule) {
Collection<String> shadowTables = rule.filterShadowTables(tableAliasAndNameMappings.values());
if (shadowTables.isEmpty() && isMatchDefaultAlgorithm(rule)) {
return rule.getAllShadowDataSourceMappings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.dml;
package org.apache.shardingsphere.shadow.route.retriever.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand All @@ -32,15 +32,15 @@
import java.util.List;

/**
* Shadow delete statement data source mappings finder.
* Shadow delete statement data source mappings retriever.
*/
public final class ShadowDeleteStatementDataSourceMappingsFinder extends AbstractShadowDMLStatementDataSourceMappingsFinder {
public final class ShadowDeleteStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever {

private final DeleteStatementContext sqlStatementContext;

private final List<Object> parameters;

public ShadowDeleteStatementDataSourceMappingsFinder(final DeleteStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
public ShadowDeleteStatementDataSourceMappingsRetriever(final DeleteStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
super(sqlStatementContext, hintValueContext, ShadowOperationType.DELETE);
this.sqlStatementContext = sqlStatementContext;
this.parameters = parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.dml;
package org.apache.shardingsphere.shadow.route.retriever.dml;

import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
Expand All @@ -30,13 +30,13 @@
import java.util.List;

/**
* Shadow insert statement data source mappings finder.
* Shadow insert statement data source mappings retriever.
*/
public final class ShadowInsertStatementDataSourceMappingsFinder extends AbstractShadowDMLStatementDataSourceMappingsFinder {
public final class ShadowInsertStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever {

private final InsertStatementContext sqlStatementContext;

public ShadowInsertStatementDataSourceMappingsFinder(final InsertStatementContext sqlStatementContext, final HintValueContext hintValueContext) {
public ShadowInsertStatementDataSourceMappingsRetriever(final InsertStatementContext sqlStatementContext, final HintValueContext hintValueContext) {
super(sqlStatementContext, hintValueContext, ShadowOperationType.INSERT);
this.sqlStatementContext = sqlStatementContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.dml;
package org.apache.shardingsphere.shadow.route.retriever.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand All @@ -36,15 +36,15 @@
import java.util.Optional;

/**
* Shadow select statement data source mappings finder.
* Shadow select statement data source mappings retriever.
*/
public final class ShadowSelectStatementDataSourceMappingsFinder extends AbstractShadowDMLStatementDataSourceMappingsFinder {
public final class ShadowSelectStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever {

private final SelectStatementContext sqlStatementContext;

private final List<Object> parameters;

public ShadowSelectStatementDataSourceMappingsFinder(final SelectStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
public ShadowSelectStatementDataSourceMappingsRetriever(final SelectStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
super(sqlStatementContext, hintValueContext, ShadowOperationType.SELECT);
this.sqlStatementContext = sqlStatementContext;
this.parameters = parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.dml;
package org.apache.shardingsphere.shadow.route.retriever.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand All @@ -34,15 +34,15 @@
import java.util.List;

/**
* Shadow update statement data source mappings finder.
* Shadow update statement data source mappings retriever.
*/
public final class ShadowUpdateStatementDataSourceMappingsFinder extends AbstractShadowDMLStatementDataSourceMappingsFinder {
public final class ShadowUpdateStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever {

private final UpdateStatementContext sqlStatementContext;

private final List<Object> parameters;

public ShadowUpdateStatementDataSourceMappingsFinder(final UpdateStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
public ShadowUpdateStatementDataSourceMappingsRetriever(final UpdateStatementContext sqlStatementContext, final List<Object> parameters, final HintValueContext hintValueContext) {
super(sqlStatementContext, hintValueContext, ShadowOperationType.UPDATE);
this.sqlStatementContext = sqlStatementContext;
this.parameters = parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
* limitations under the License.
*/

package org.apache.shardingsphere.shadow.route.finder.hint;
package org.apache.shardingsphere.shadow.route.retriever.hint;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer;
import org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinder;
import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.rule.ShadowRule;

import java.util.Collections;
import java.util.Map;

/**
* Shadow hint data source mappings finder.
* Shadow hint data source mappings retriever.
*/
@RequiredArgsConstructor
public final class ShadowHintDataSourceMappingsFinder implements ShadowDataSourceMappingsFinder {
public final class ShadowHintDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever {

private final HintValueContext hintValueContext;

@Override
public Map<String, String> find(final ShadowRule rule) {
public Map<String, String> retrieve(final ShadowRule rule) {
ShadowCondition shadowCondition = new ShadowCondition();
return rule.getAllHintShadowAlgorithms().stream().anyMatch(each -> HintShadowAlgorithmDeterminer.isShadow(each, shadowCondition, rule, hintValueContext.isShadow()))
? rule.getAllShadowDataSourceMappings()
Expand Down
Loading

0 comments on commit 479d4e7

Please sign in to comment.