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

duanzhengqiang 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 df0fa347f8e Get defaultSchemaName according to databaseType (#19076)
df0fa347f8e is described below

commit df0fa347f8e0d8cd1b7cd5b04eb0067bcd8b0ca6
Author: zhaojinchao <[email protected]>
AuthorDate: Wed Jul 13 08:17:42 2022 +0800

    Get defaultSchemaName according to databaseType (#19076)
    
    * Get defaultSchemaName according to databaseType
    
    * Add unit test
    
    * Change Example to Sample
---
 docs/document/content/dev-manual/ha.en.md           |  2 +-
 .../metadata/database/ShardingSphereDatabase.java   |  4 +++-
 .../infra/metadata/ShardingSphereMetaDataTest.java  | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/docs/document/content/dev-manual/ha.en.md 
b/docs/document/content/dev-manual/ha.en.md
index 85c1f4f1a63..c420d367289 100644
--- a/docs/document/content/dev-manual/ha.en.md
+++ b/docs/document/content/dev-manual/ha.en.md
@@ -11,7 +11,7 @@ chapter = true
 | ------------------------------------------------------------ | 
-------------------------------- |
 | DatabaseDiscoveryProviderAlgorithm                           | Database 
discovery provider algorithm                     |
 
-## Example
+## Sample
 
 ### DatabaseDiscoveryProviderAlgorithm
 
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java
index ef1414e68ce..60511396cbd 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
 import 
org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
 import 
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -76,7 +77,8 @@ public final class ShardingSphereDatabase {
                                                 final DatabaseConfiguration 
databaseConfig, final ConfigurationProperties props, final InstanceContext 
instanceContext) throws SQLException {
         Collection<ShardingSphereRule> databaseRules = 
DatabaseRulesBuilder.build(name, databaseConfig, instanceContext);
         Map<String, ShardingSphereSchema> schemas = new ConcurrentHashMap<>();
-        schemas.putAll(GenericSchemaBuilder.build(new 
GenericSchemaBuilderMaterials(protocolType, storageType, 
databaseConfig.getDataSources(), databaseRules, props, name)));
+        schemas.putAll(GenericSchemaBuilder.build(new 
GenericSchemaBuilderMaterials(protocolType, storageType, 
databaseConfig.getDataSources(), databaseRules, props,
+                DatabaseTypeEngine.getDefaultSchemaName(storageType, name))));
         schemas.putAll(SystemSchemaBuilder.build(name, protocolType));
         return create(name, protocolType, databaseConfig, databaseRules, 
schemas);
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
index 9443057a971..f6879517f11 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
@@ -17,8 +17,12 @@
 
 package org.apache.shardingsphere.infra.metadata;
 
+import 
org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
 import 
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -37,6 +41,7 @@ import java.util.Properties;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.verify;
@@ -86,4 +91,20 @@ public final class ShardingSphereMetaDataTest {
         when(result.getRuleMetaData()).thenReturn(new 
ShardingSphereRuleMetaData(Collections.singleton(databaseResourceHeldRule)));
         return result;
     }
+    
+    @Test
+    public void assertGetPostgresDefaultSchema() throws SQLException {
+        PostgreSQLDatabaseType databaseType = new PostgreSQLDatabaseType();
+        ShardingSphereDatabase actual = 
ShardingSphereDatabase.create("foo_db", databaseType, databaseType,
+                mock(DataSourceProvidedDatabaseConfiguration.class), new 
ConfigurationProperties(new Properties()), mock(InstanceContext.class));
+        assertNotNull(actual.getSchemas().get("public"));
+    }
+    
+    @Test
+    public void assertGetMySQLDefaultSchema() throws SQLException {
+        MySQLDatabaseType databaseType = new MySQLDatabaseType();
+        ShardingSphereDatabase actual = 
ShardingSphereDatabase.create("foo_db", databaseType, databaseType,
+                mock(DataSourceProvidedDatabaseConfiguration.class), new 
ConfigurationProperties(new Properties()), mock(InstanceContext.class));
+        assertNotNull(actual.getSchemas().get("foo_db"));
+    }
 }

Reply via email to