Skip to content

Commit

Permalink
Refactor MaskAlgorithmMetaData (#28546)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojinchao95 authored Sep 22, 2023
1 parent 00e4ffb commit 8187db6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class MaskResultDecoratorEngine implements ResultDecoratorEngine<Ma
public Optional<ResultDecorator<MaskRule>> newInstance(final ShardingSphereDatabase database,
final MaskRule maskRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof SelectStatementContext
? Optional.of(new MaskDQLResultDecorator(new MaskAlgorithmMetaData(database, maskRule, (SelectStatementContext) sqlStatementContext)))
? Optional.of(new MaskDQLResultDecorator(new MaskAlgorithmMetaData(maskRule, (SelectStatementContext) sqlStatementContext)))
: Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;

Expand All @@ -35,8 +34,6 @@
@RequiredArgsConstructor
public final class MaskAlgorithmMetaData {

private final ShardingSphereDatabase database;

private final MaskRule maskRule;

private final SelectStatementContext selectStatementContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
Expand All @@ -43,9 +42,6 @@
@ExtendWith(MockitoExtension.class)
class MaskAlgorithmMetaDataTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;

@Mock
private MaskRule maskRule;

Expand All @@ -61,7 +57,7 @@ void assertFindMaskAlgorithmByColumnIndex() {
columnProjection.setOriginalTable(new IdentifierValue("t_order"));
when(selectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Collections.singletonList(columnProjection));
when(selectStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_order"));
Optional<MaskAlgorithm> actual = new MaskAlgorithmMetaData(database, maskRule, selectStatementContext).findMaskAlgorithmByColumnIndex(1);
Optional<MaskAlgorithm> actual = new MaskAlgorithmMetaData(maskRule, selectStatementContext).findMaskAlgorithmByColumnIndex(1);
assertTrue(actual.isPresent());
assertThat(actual.get().getType(), is("MD5"));
}
Expand Down

0 comments on commit 8187db6

Please sign in to comment.