Skip to content

Commit

Permalink
Move GenericSchemaBuilderMaterial.isSameProtocolAndStorageTypes() to …
Browse files Browse the repository at this point in the history
…GenericSchemaBuilder (#33995)

* Move GenericSchemaBuilderMaterial.isSameProtocolAndStorageTypes() to GenericSchemaBuilder

* Move GenericSchemaBuilderMaterial.isSameProtocolAndStorageTypes() to GenericSchemaBuilder
  • Loading branch information
terrymanu authored Dec 10, 2024
1 parent ffce9b2 commit 11c1c95
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static Map<String, ShardingSphereSchema> build(final GenericSchemaBuilder
*/
public static Map<String, ShardingSphereSchema> build(final Collection<String> tableNames, final GenericSchemaBuilderMaterial material) throws SQLException {
Map<String, SchemaMetaData> result = loadSchemas(tableNames, material);
if (!material.isSameProtocolAndStorageTypes()) {
if (!isSameProtocolAndStorageTypes(material.getProtocolType(), material.getStorageUnits())) {
result = translate(result, material);
}
return revise(result, material);
Expand All @@ -98,6 +99,10 @@ private static Map<String, SchemaMetaData> loadSchemas(final Collection<String>
return materials.isEmpty() ? Collections.emptyMap() : MetaDataLoader.load(materials);
}

private static boolean isSameProtocolAndStorageTypes(final DatabaseType protocolType, final Map<String, StorageUnit> storageUnits) {
return storageUnits.values().stream().map(StorageUnit::getStorageType).allMatch(protocolType::equals);
}

private static Map<String, SchemaMetaData> translate(final Map<String, SchemaMetaData> schemaMetaDataMap, final GenericSchemaBuilderMaterial material) {
Collection<TableMetaData> tableMetaDataList = new LinkedList<>();
for (StorageUnit each : material.getStorageUnits().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,4 @@ public final class GenericSchemaBuilderMaterial {
private final ConfigurationProperties props;

private final String defaultSchemaName;

/**
* Judge whether same protocol and storage database types.
*
* @return is same or not
*/
public boolean isSameProtocolAndStorageTypes() {
return storageUnits.values().stream().map(StorageUnit::getStorageType).allMatch(protocolType::equals);
}
}

This file was deleted.

0 comments on commit 11c1c95

Please sign in to comment.