You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/06/28 04:53:50 UTC
(shardingsphere) branch master updated: Refactor DatabaseTypeEngine (#31911)
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 cc35c49ba7a Refactor DatabaseTypeEngine (#31911)
cc35c49ba7a is described below
commit cc35c49ba7aee9131774f0573c5480e8e76f0aea
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jun 28 12:53:45 2024 +0800
Refactor DatabaseTypeEngine (#31911)
* Add @HighFrequencyInvocation on MaskTable.findAlgorithm
* Refactor DatabaseTypeEngine
---
.../shardingsphere/infra/database/DatabaseTypeEngine.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
index a973e47d5f7..c33be3bdaee 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
@@ -59,8 +59,7 @@ public final class DatabaseTypeEngine {
if (configuredDatabaseType.isPresent()) {
return configuredDatabaseType.get();
}
- Collection<DataSource> dataSources = databaseConfig.getStorageUnits().entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)).values();
+ Collection<DataSource> dataSources = getDataSources(databaseConfig).values();
return dataSources.isEmpty() ? getDefaultStorageType() : getStorageType(dataSources.iterator().next());
}
@@ -88,13 +87,16 @@ public final class DatabaseTypeEngine {
private static Map<String, DataSource> getDataSources(final Map<String, ? extends DatabaseConfiguration> databaseConfigs) {
Map<String, DataSource> result = new LinkedHashMap<>();
for (Entry<String, ? extends DatabaseConfiguration> entry : databaseConfigs.entrySet()) {
- Map<String, DataSource> dataSources = entry.getValue().getStorageUnits().entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, storageUnit -> storageUnit.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
- result.putAll(dataSources);
+ result.putAll(getDataSources(entry.getValue()));
}
return result;
}
+ private static Map<String, DataSource> getDataSources(final DatabaseConfiguration databaseConfig) {
+ return databaseConfig.getStorageUnits().entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+ }
+
/**
* Get storage types.
*
@@ -103,8 +105,7 @@ public final class DatabaseTypeEngine {
*/
public static Map<String, DatabaseType> getStorageTypes(final DatabaseConfiguration databaseConfig) {
Map<String, DatabaseType> result = new LinkedHashMap<>(databaseConfig.getStorageUnits().size(), 1F);
- Map<String, DataSource> dataSources = databaseConfig.getStorageUnits().entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+ Map<String, DataSource> dataSources = getDataSources(databaseConfig);
for (Entry<String, DataSource> entry : dataSources.entrySet()) {
result.put(entry.getKey(), getStorageType(entry.getValue()));
}