1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.metadata.database.schema.builder;
19
20 import lombok.Getter;
21 import lombok.RequiredArgsConstructor;
22 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
23 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
24 import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
25 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
26
27 import javax.sql.DataSource;
28 import java.util.Collection;
29 import java.util.LinkedHashMap;
30 import java.util.Map;
31 import java.util.Map.Entry;
32 import java.util.stream.Collectors;
33
34
35
36
37 @RequiredArgsConstructor
38 @Getter
39 public final class GenericSchemaBuilderMaterial {
40
41 private final DatabaseType protocolType;
42
43 private final Map<String, DatabaseType> storageTypes;
44
45 private final Map<String, DataSource> dataSourceMap;
46
47 private final Collection<ShardingSphereRule> rules;
48
49 private final ConfigurationProperties props;
50
51 private final String defaultSchemaName;
52
53 public GenericSchemaBuilderMaterial(final DatabaseType protocolType, final Map<String, StorageUnit> storageUnits,
54 final Collection<ShardingSphereRule> rules, final ConfigurationProperties props, final String defaultSchemaName) {
55 this(protocolType, storageUnits.entrySet().stream()
56 .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageType(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)),
57 storageUnits.entrySet().stream()
58 .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)),
59 rules, props, defaultSchemaName);
60 }
61
62
63
64
65
66
67 public boolean isSameProtocolAndStorageTypes() {
68 return storageTypes.values().stream().allMatch(protocolType::equals);
69 }
70 }