This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 758e106ac06 Add
GenericSchemaBuilderMaterial.isSameProtocolAndStorageTypes() (#28190)
758e106ac06 is described below
commit 758e106ac06399234e010fcb3a6b24b037dda4d4
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 20 23:50:48 2023 +0800
Add GenericSchemaBuilderMaterial.isSameProtocolAndStorageTypes() (#28190)
---
.../schema/builder/GenericSchemaBuilder.java | 11 +----
.../builder/GenericSchemaBuilderMaterial.java | 9 ++++
.../builder/GenericSchemaBuilderMaterialTest.java | 48 ++++++++++++++++++++++
3 files changed, 58 insertions(+), 10 deletions(-)
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 50c513a2e6f..856e1c69773 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
@@ -77,21 +77,12 @@ public final class GenericSchemaBuilder {
*/
public static Map<String, ShardingSphereSchema> build(final
Collection<String> tableNames, final GenericSchemaBuilderMaterial material)
throws SQLException {
Map<String, SchemaMetaData> result = loadSchemas(tableNames, material);
- if (!isProtocolTypeSameWithStorageType(material)) {
+ if (!material.isSameProtocolAndStorageTypes()) {
result = translate(result, material);
}
return revise(result, material);
}
- private static boolean isProtocolTypeSameWithStorageType(final
GenericSchemaBuilderMaterial material) {
- for (DatabaseType each : material.getStorageTypes().values()) {
- if (!material.getProtocolType().equals(each)) {
- return false;
- }
- }
- return true;
- }
-
private static Collection<String> getAllTableNames(final
Collection<ShardingSphereRule> rules) {
return
rules.stream().filter(TableContainedRule.class::isInstance).flatMap(each ->
((TableContainedRule)
each).getLogicTableMapper().getTableNames().stream()).collect(Collectors.toSet());
}
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 bbb6f3ed387..409ed751e81 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
@@ -51,4 +51,13 @@ public final class GenericSchemaBuilderMaterial {
final Collection<ShardingSphereRule>
rules, final ConfigurationProperties props, final String defaultSchemaName) {
this(protocolType, storageUnitMetaData.getStorageTypes(),
storageUnitMetaData.getDataSources(), rules, props, defaultSchemaName);
}
+
+ /**
+ * Judge whether same protocol and storage database types.
+ *
+ * @return is same or not
+ */
+ public boolean isSameProtocolAndStorageTypes() {
+ return storageTypes.values().stream().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
new file mode 100644
index 00000000000..3b3237496fa
--- /dev/null
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterialTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+class GenericSchemaBuilderMaterialTest {
+
+ @Test
+ void assertIsSameProtocolAndStorageTypes() {
+ GenericSchemaBuilderMaterial material = new
GenericSchemaBuilderMaterial(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"),
+ Collections.singletonMap("foo",
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")),
+ Collections.emptyMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()), "");
+ assertTrue(material.isSameProtocolAndStorageTypes());
+ }
+
+ @Test
+ void assertIsDifferentProtocolAndStorageTypes() {
+ GenericSchemaBuilderMaterial material = new
GenericSchemaBuilderMaterial(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"),
+ Collections.singletonMap("foo", null),
+ Collections.emptyMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()), "");
+ assertFalse(material.isSameProtocolAndStorageTypes());
+ }
+}