diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java index 703879d0ee510..cc5751aa89c86 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java @@ -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; @@ -78,7 +79,7 @@ public static Map build(final GenericSchemaBuilder */ public static Map build(final Collection tableNames, final GenericSchemaBuilderMaterial material) throws SQLException { Map result = loadSchemas(tableNames, material); - if (!material.isSameProtocolAndStorageTypes()) { + if (!isSameProtocolAndStorageTypes(material.getProtocolType(), material.getStorageUnits())) { result = translate(result, material); } return revise(result, material); @@ -98,6 +99,10 @@ private static Map loadSchemas(final Collection return materials.isEmpty() ? Collections.emptyMap() : MetaDataLoader.load(materials); } + private static boolean isSameProtocolAndStorageTypes(final DatabaseType protocolType, final Map storageUnits) { + return storageUnits.values().stream().map(StorageUnit::getStorageType).allMatch(protocolType::equals); + } + private static Map translate(final Map schemaMetaDataMap, final GenericSchemaBuilderMaterial material) { Collection tableMetaDataList = new LinkedList<>(); for (StorageUnit each : material.getStorageUnits().values()) { diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java index d1a05c2124a8d..f77db09a9c3f1 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java @@ -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); - } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterialTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterialTest.java deleted file mode 100644 index d7cfd74d98647..0000000000000 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterialTest.java +++ /dev/null @@ -1,48 +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.infra.metadata.database.schema.builder; - -import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.Properties; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; - -class GenericSchemaBuilderMaterialTest { - - private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); - - @Test - void assertIsSameProtocolAndStorageTypes() { - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(databaseType, Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties()), ""); - assertTrue(material.isSameProtocolAndStorageTypes()); - } - - @Test - void assertIsDifferentProtocolAndStorageTypes() { - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(databaseType, - Collections.singletonMap("foo", mock()), Collections.emptyList(), new ConfigurationProperties(new Properties()), ""); - assertFalse(material.isSameProtocolAndStorageTypes()); - } -}