You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/06/03 09:15:49 UTC

[shardingsphere] branch master updated: Adjust filter logic from isComplete to hasDataSource when get databaseType (#18168)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 a9194342032 Adjust filter logic from isComplete to hasDataSource when get databaseType (#18168)
a9194342032 is described below

commit a9194342032c49a1ee93c27b07c272565767c670
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Fri Jun 3 17:15:34 2022 +0800

    Adjust filter logic from isComplete to hasDataSource when get databaseType (#18168)
---
 .../shardingsphere/infra/database/type/DatabaseTypeEngine.java    | 8 ++++----
 .../proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
index ba04d660e73..2404bb01f8f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
@@ -53,7 +53,7 @@ public final class DatabaseTypeEngine {
             return configuredDatabaseType.get();
         }
         Collection<DataSource> dataSources = databaseConfigs.values().stream()
-                .filter(DatabaseTypeEngine::isComplete).findFirst().map(optional -> optional.getDataSources().values()).orElseGet(Collections::emptyList);
+                .filter(DatabaseTypeEngine::hasDataSource).findFirst().map(optional -> optional.getDataSources().values()).orElseGet(Collections::emptyList);
         return getDatabaseType(dataSources);
     }
     
@@ -65,7 +65,7 @@ public final class DatabaseTypeEngine {
      */
     public static DatabaseType getStorageType(final Map<String, ? extends DatabaseConfiguration> databaseConfigs) {
         return getDatabaseType(
-                databaseConfigs.values().stream().filter(DatabaseTypeEngine::isComplete).findFirst().map(optional -> optional.getDataSources().values()).orElseGet(Collections::emptyList));
+                databaseConfigs.values().stream().filter(DatabaseTypeEngine::hasDataSource).findFirst().map(optional -> optional.getDataSources().values()).orElseGet(Collections::emptyList));
     }
     
     /**
@@ -107,8 +107,8 @@ public final class DatabaseTypeEngine {
         return configuredDatabaseType.isEmpty() ? Optional.empty() : Optional.of(DatabaseTypeEngine.getTrunkDatabaseType(configuredDatabaseType));
     }
     
-    private static boolean isComplete(final DatabaseConfiguration databaseConfig) {
-        return !databaseConfig.getRuleConfigurations().isEmpty() && !databaseConfig.getDataSources().isEmpty();
+    private static boolean hasDataSource(final DatabaseConfiguration databaseConfig) {
+        return !databaseConfig.getDataSources().isEmpty();
     }
     
     private static boolean matchURLs(final String url, final DatabaseType databaseType) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java
index f2fbf5dc1e9..3a9aabc41a8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java
@@ -50,7 +50,7 @@ public final class FrontDatabaseProtocolTypeFactory {
         if (metaDataContexts.getMetaData().getDatabases().isEmpty()) {
             return DatabaseTypeEngine.getTrunkDatabaseType(DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE);
         }
-        Optional<ShardingSphereDatabase> database = metaDataContexts.getMetaData().getDatabases().values().stream().filter(ShardingSphereDatabase::isComplete).findFirst();
+        Optional<ShardingSphereDatabase> database = metaDataContexts.getMetaData().getDatabases().values().stream().filter(ShardingSphereDatabase::hasDataSource).findFirst();
         return database.isPresent() ? database.get().getResource().getDatabaseType() : DatabaseTypeEngine.getTrunkDatabaseType(DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE);
     }