Skip to content

Commit

Permalink
Merge StorageUnitUtils and RuleMetaData
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Oct 8, 2023
1 parent 2ea2c7e commit c22b105
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ public <T extends ShardingSphereRule> T getSingleRule(final Class<T> clazz) {
*/
public Map<String, Collection<Class<? extends ShardingSphereRule>>> getInUsedStorageUnitNameAndRulesMap() {
Map<String, Collection<Class<? extends ShardingSphereRule>>> result = new LinkedHashMap<>();
for (DataSourceContainedRule each : findRules(DataSourceContainedRule.class)) {
result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(each)));
}
for (DataNodeContainedRule each : findRules(DataNodeContainedRule.class)) {
result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(each)));
for (ShardingSphereRule each : rules) {
if (each instanceof DataSourceContainedRule) {
result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames((DataSourceContainedRule) each)));
} else if (each instanceof DataNodeContainedRule) {
result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames((DataNodeContainedRule) each)));
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(fin
if (usageCount.isPresent()) {
Map<String, Collection<Class<? extends ShardingSphereRule>>> inUsedStorageUnits = database.getRuleMetaData().getInUsedStorageUnitNameAndRulesMap();
for (Entry<String, StorageUnit> entry : database.getResourceMetaData().getStorageUnits().entrySet()) {
Integer currentUsageCount = inUsedStorageUnits.containsKey(entry.getKey()) ? inUsedStorageUnits.get(entry.getKey()).size() : 0;
int currentUsageCount = inUsedStorageUnits.containsKey(entry.getKey()) ? inUsedStorageUnits.get(entry.getKey()).size() : 0;
if (usageCount.get().equals(currentUsageCount)) {
result.put(entry.getKey(), getDataSourcePoolProperties(
propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource()));
result.put(entry.getKey(), getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource()));
}
}
} else {
for (Entry<String, StorageUnit> entry : storageUnits.entrySet()) {
result.put(entry.getKey(),
getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource()));
result.put(entry.getKey(), getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource()));
}
}
return result;
Expand Down

0 comments on commit c22b105

Please sign in to comment.