Skip to content

Commit

Permalink
Remove useless codes on ColumnReviseEngine (#33999)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 10, 2024
1 parent fac2bb6 commit 7181440
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
package org.apache.shardingsphere.infra.metadata.database.schema.reviser;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.schema.SchemaMetaDataReviseEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -49,10 +46,7 @@ public final class MetaDataReviseEngine {
public Map<String, SchemaMetaData> revise(final Map<String, SchemaMetaData> schemaMetaDataMap, final GenericSchemaBuilderMaterial material) {
Map<String, SchemaMetaData> result = new LinkedHashMap<>(schemaMetaDataMap.size(), 1F);
for (Entry<String, SchemaMetaData> entry : schemaMetaDataMap.entrySet()) {
// TODO establish a corresponding relationship between tables and data sources
DatabaseType databaseType = material.getStorageUnits().values().stream().map(StorageUnit::getStorageType).findFirst().orElse(null);
DataSource dataSource = material.getStorageUnits().values().stream().map(StorageUnit::getDataSource).findFirst().orElse(null);
result.put(entry.getKey(), new SchemaMetaDataReviseEngine(rules, material.getProps(), databaseType, dataSource).revise(entry.getValue()));
result.put(entry.getKey(), new SchemaMetaDataReviseEngine(rules, material.getProps()).revise(entry.getValue()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Optional;
Expand All @@ -38,10 +36,6 @@ public final class ColumnReviseEngine<T extends ShardingSphereRule> {

private final T rule;

private final DatabaseType databaseType;

private final DataSource dataSource;

private final MetaDataReviseEntry<T> reviseEntry;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.table.TableMetaDataReviseEngine;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.table.TableMetaDataReviseEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Optional;
Expand All @@ -43,10 +41,6 @@ public final class SchemaMetaDataReviseEngine {

private final ConfigurationProperties props;

private final DatabaseType databaseType;

private final DataSource dataSource;

/**
* Revise schema meta data.
*
Expand All @@ -63,7 +57,7 @@ public SchemaMetaData revise(final SchemaMetaData originalMetaData) {
}

private <T extends ShardingSphereRule> SchemaMetaData revise(final SchemaMetaData originalMetaData, final T rule, final MetaDataReviseEntry<T> reviseEntry) {
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<>(rule, databaseType, dataSource, reviseEntry);
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<>(rule, reviseEntry);
Optional<? extends SchemaTableAggregationReviser<T>> aggregationReviser = reviseEntry.getSchemaTableAggregationReviser(props);
if (!aggregationReviser.isPresent()) {
return new SchemaMetaData(originalMetaData.getName(), originalMetaData.getTables().stream().map(tableMetaDataReviseEngine::revise).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.reviser.table;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.column.ColumnReviseEngine;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.constraint.ConstraintReviseEngine;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.index.IndexReviseEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;

import javax.sql.DataSource;
import java.util.Optional;

/**
Expand All @@ -39,10 +37,6 @@ public final class TableMetaDataReviseEngine<T extends ShardingSphereRule> {

private final T rule;

private final DatabaseType databaseType;

private final DataSource dataSource;

private final MetaDataReviseEntry<T> reviseEntry;

/**
Expand All @@ -54,7 +48,7 @@ public final class TableMetaDataReviseEngine<T extends ShardingSphereRule> {
public TableMetaData revise(final TableMetaData originalMetaData) {
Optional<? extends TableNameReviser<T>> tableNameReviser = reviseEntry.getTableNameReviser();
String revisedTableName = tableNameReviser.map(optional -> optional.revise(originalMetaData.getName(), rule)).orElse(originalMetaData.getName());
return new TableMetaData(revisedTableName, new ColumnReviseEngine<>(rule, databaseType, dataSource, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getColumns()),
return new TableMetaData(revisedTableName, new ColumnReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getColumns()),
new IndexReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getIndexes()),
new ConstraintReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getConstraints()), originalMetaData.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRule;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -45,7 +43,7 @@ class SchemaMetaDataReviseEngineTest {
void assertReviseWithoutMetaDataReviseEntry() {
SchemaMetaData schemaMetaData = new SchemaMetaData("expected", Collections.singleton(mock(TableMetaData.class)));
SchemaMetaData actual = new SchemaMetaDataReviseEngine(
Collections.emptyList(), new ConfigurationProperties(new Properties()), mock(DatabaseType.class), mock(DataSource.class)).revise(schemaMetaData);
Collections.emptyList(), new ConfigurationProperties(new Properties())).revise(schemaMetaData);
assertThat(actual.getName(), is(schemaMetaData.getName()));
assertThat(actual.getTables(), is(schemaMetaData.getTables()));
}
Expand All @@ -54,7 +52,7 @@ void assertReviseWithoutMetaDataReviseEntry() {
void assertReviseWithMetaDataReviseEntry() {
SchemaMetaData schemaMetaData = new SchemaMetaData("expected", Collections.singletonList(createTableMetaData()));
SchemaMetaData actual = new SchemaMetaDataReviseEngine(
Collections.singleton(new FixtureGlobalRule()), new ConfigurationProperties(new Properties()), mock(DatabaseType.class), mock(DataSource.class)).revise(schemaMetaData);
Collections.singleton(new FixtureGlobalRule()), new ConfigurationProperties(new Properties())).revise(schemaMetaData);
assertThat(actual.getName(), is(schemaMetaData.getName()));
assertThat(actual.getTables(), is(schemaMetaData.getTables()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
Expand All @@ -31,7 +30,6 @@
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Optional;
Expand All @@ -52,12 +50,6 @@ class TableMetadataReviseEngineTest<T extends ShardingSphereRule> {
@Mock
private T rule;

@Mock
private DatabaseType databaseType;

@Mock
private DataSource dataSource;

@SuppressWarnings("rawtypes")
@Mock
private MetaDataReviseEntry metaDataReviseEntry;
Expand All @@ -67,7 +59,7 @@ class TableMetadataReviseEngineTest<T extends ShardingSphereRule> {
void assertGetRevisedTableName() {
TableNameReviser tableNameReviser = mock(TableNameReviser.class);
TableMetaData originalMetaData = new TableMetaData("originalTableName", new LinkedList<>(), null, null);
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<T>(rule, databaseType, dataSource, metaDataReviseEntry);
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<T>(rule, metaDataReviseEntry);
doReturn(Optional.of(tableNameReviser)).when(metaDataReviseEntry).getTableNameReviser();
when(tableNameReviser.revise(anyString(), eq(rule))).thenReturn("revisedTableName");
TableMetaData revisedMetaData = tableMetaDataReviseEngine.revise(originalMetaData);
Expand All @@ -82,7 +74,7 @@ void assertGetOriginalTableName() {
Collection<IndexMetaData> indexes = new LinkedList<>();
indexes.add(new IndexMetaData("index1"));
TableMetaData tableMetaData = new TableMetaData("originalTableName", columns, indexes, null);
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<T>(rule, databaseType, dataSource, metaDataReviseEntry);
TableMetaDataReviseEngine<T> tableMetaDataReviseEngine = new TableMetaDataReviseEngine<T>(rule, metaDataReviseEntry);
when(metaDataReviseEntry.getTableNameReviser()).thenReturn(Optional.empty());
TableMetaData revisedMetaData = tableMetaDataReviseEngine.revise(tableMetaData);
assertThat(revisedMetaData.getName(), is("originalTableName"));
Expand Down

0 comments on commit 7181440

Please sign in to comment.