This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 93a0e3358e1 Refactor DatabaseTypeEngine (#37160)
93a0e3358e1 is described below
commit 93a0e3358e197742337c1406a85b1c4e00741f98
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 22 17:41:35 2025 +0800
Refactor DatabaseTypeEngine (#37160)
---
.../infra/database/DatabaseTypeEngine.java | 19 ++++++-------------
.../shardingsphere/infra/instance/util/IpUtils.java | 9 ++-------
.../shardingsphere/infra/rule/scope/GlobalRule.java | 2 +-
3 files changed, 9 insertions(+), 21 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 4d641ee08c8..8eedaeafd03 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
@@ -33,7 +33,6 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
-import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -56,12 +55,7 @@ public final class DatabaseTypeEngine {
* @return protocol type
*/
public static DatabaseType getProtocolType(final DatabaseConfiguration
databaseConfig, final ConfigurationProperties props) {
- Optional<DatabaseType> configuredDatabaseType =
findConfiguredDatabaseType(props);
- if (configuredDatabaseType.isPresent()) {
- return configuredDatabaseType.get();
- }
- Collection<DataSource> dataSources =
getDataSources(databaseConfig).values();
- return dataSources.isEmpty() ? getDefaultStorageType() :
getStorageType(dataSources.iterator().next());
+ return getDatabaseType(getDataSources(databaseConfig), props);
}
/**
@@ -72,12 +66,11 @@ public final class DatabaseTypeEngine {
* @return protocol type
*/
public static DatabaseType getProtocolType(final Map<String,
DatabaseConfiguration> databaseConfigs, final ConfigurationProperties props) {
- Optional<DatabaseType> configuredDatabaseType =
findConfiguredDatabaseType(props);
- if (configuredDatabaseType.isPresent()) {
- return configuredDatabaseType.get();
- }
- Collection<DataSource> dataSources =
getDataSources(databaseConfigs).values();
- return dataSources.isEmpty() ? getDefaultStorageType() :
getStorageType(dataSources.iterator().next());
+ return getDatabaseType(getDataSources(databaseConfigs), props);
+ }
+
+ private static DatabaseType getDatabaseType(final Map<String, DataSource>
dataSources, final ConfigurationProperties props) {
+ return findConfiguredDatabaseType(props).orElseGet(() ->
dataSources.isEmpty() ? getDefaultStorageType() :
getStorageType(dataSources.values().iterator().next()));
}
private static Optional<DatabaseType> findConfiguredDatabaseType(final
ConfigurationProperties props) {
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/util/IpUtils.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/util/IpUtils.java
index 63586ee4f17..a82aa76e360 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/util/IpUtils.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/util/IpUtils.java
@@ -34,14 +34,9 @@ public final class IpUtils {
private static volatile String cachedIpAddress;
/**
- * Get localhost IP address.
+ * Get localhost IP address, maybe get of router.
*
- * <p>
- * It maybe get IP address of router.
- * Return unknown IP if exception occur.
- * </p>
- *
- * @return IP address of localhost
+ * @return IP address of localhost, return unknown if exception occur.
*/
public static String getIp() {
if (null != cachedIpAddress) {
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
index 3f361db212f..d7af2f16227 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
@@ -33,7 +33,7 @@ public interface GlobalRule extends ShardingSphereRule {
* @param databases changed databases
* @param changedType changed type
*/
- default void refresh(final Collection<ShardingSphereDatabase> databases,
GlobalRuleChangedType changedType) {
+ default void refresh(final Collection<ShardingSphereDatabase> databases,
final GlobalRuleChangedType changedType) {
}
/**