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 a9a9902  Jdbc only load specified logic schema (#14137)
a9a9902 is described below

commit a9a990254706f0f94823d103361578566581eddf
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Dec 17 17:09:18 2021 +0800

    Jdbc only load specified logic schema (#14137)
    
    Co-authored-by: shardingsphere <[email protected]>
---
 .../driver/jdbc/core/datasource/ShardingSphereDataSource.java  |  2 +-
 .../shardingsphere/mode/manager/ContextManagerBuilder.java     |  5 +++--
 .../manager/fixture/DefaultFixtureContextManagerBuilder.java   |  3 ++-
 .../mode/manager/fixture/FixtureContextManagerBuilder.java     |  3 ++-
 .../mode/manager/cluster/ClusterContextManagerBuilder.java     | 10 ++++++----
 .../coordinator/ClusterContextManagerCoordinatorTest.java      |  2 +-
 .../mode/manager/memory/MemoryContextManagerBuilder.java       |  2 +-
 .../manager/standalone/StandaloneContextManagerBuilder.java    |  6 ++++--
 .../standalone/StandaloneContextManagerBuilderTextTest.java    |  3 ++-
 .../shardingsphere/proxy/initializer/BootstrapInitializer.java |  2 +-
 10 files changed, 23 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index 836b48f..a0513ff 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -72,7 +72,7 @@ public final class ShardingSphereDataSource extends 
AbstractDataSourceAdapter im
         Map<String, Collection<RuleConfiguration>> schemaRuleConfigs = 
Collections.singletonMap(
                 schemaName, ruleConfigs.stream().filter(each -> each 
instanceof SchemaRuleConfiguration).collect(Collectors.toList()));
         Collection<RuleConfiguration> globalRuleConfigs = 
ruleConfigs.stream().filter(each -> each instanceof 
GlobalRuleConfiguration).collect(Collectors.toList());
-        return 
ContextManagerBuilderFactory.newInstance(modeConfig).build(modeConfig, 
dataSourcesMap, schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, null);
+        return 
ContextManagerBuilderFactory.newInstance(modeConfig).build(modeConfig, 
dataSourcesMap, schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, null, 
schemaName);
     }
     
     @Override
diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
index b11a942..4b2d716 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
@@ -42,11 +42,12 @@ public interface ContextManagerBuilder extends TypedSPI, 
RequiredSPI {
      * @param globalRuleConfigs global rule configurations
      * @param props properties
      * @param isOverwrite whether overwrite to persistence
-     * @param port port                   
+     * @param port port
+     * @param schemaName schema name            
      * @return context manager
      * @throws SQLException SQL exception
      */
     ContextManager build(ModeConfiguration modeConfig, Map<String, Map<String, 
DataSource>> dataSourcesMap,
                          Map<String, Collection<RuleConfiguration>> 
schemaRuleConfigs, Collection<RuleConfiguration> globalRuleConfigs, Properties 
props, boolean isOverwrite, 
-                         Integer port) throws SQLException;
+                         Integer port, String schemaName) throws SQLException;
 }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
index 073d14f..568d27f 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
@@ -32,7 +32,8 @@ public final class DefaultFixtureContextManagerBuilder 
implements ContextManager
 
     @Override
     public ContextManager build(final ModeConfiguration modeConfig, final 
Map<String, Map<String, DataSource>> dataSourcesMap, final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs,
-                                final Collection<RuleConfiguration> 
globalRuleConfigs, final Properties props, final boolean isOverwrite, final 
Integer port) throws SQLException {
+                                final Collection<RuleConfiguration> 
globalRuleConfigs, final Properties props, 
+                                final boolean isOverwrite, final Integer port, 
final String schemaName) throws SQLException {
         return null;
     }
 
diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
index 2dc45bc..003e1de 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
@@ -32,7 +32,8 @@ public final class FixtureContextManagerBuilder implements 
ContextManagerBuilder
 
     @Override
     public ContextManager build(final ModeConfiguration modeConfig, final 
Map<String, Map<String, DataSource>> dataSourcesMap, final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs,
-                                final Collection<RuleConfiguration> 
globalRuleConfigs, final Properties props, final boolean isOverwrite, final 
Integer port) throws SQLException {
+                                final Collection<RuleConfiguration> 
globalRuleConfigs, final Properties props, 
+                                final boolean isOverwrite, final Integer port, 
final String schemaName) throws SQLException {
         return null;
     }
 
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index d5c7029..8bd3c68 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.mode.manager.cluster;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
@@ -48,6 +49,7 @@ import 
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
 
 import javax.sql.DataSource;
 import java.sql.SQLException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -78,8 +80,8 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     @Override
     public ContextManager build(final ModeConfiguration modeConfig, final 
Map<String, Map<String, DataSource>> dataSourcesMap,
                                 final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs, final 
Collection<RuleConfiguration> globalRuleConfigs,
-                                final Properties props, final boolean 
isOverwrite, final Integer port) throws SQLException {
-        beforeBuildContextManager(modeConfig, dataSourcesMap, 
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, port);
+                                final Properties props, final boolean 
isOverwrite, final Integer port, final String schemaName) throws SQLException {
+        beforeBuildContextManager(modeConfig, dataSourcesMap, 
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, port, schemaName);
         contextManager = new ContextManager();
         contextManager.init(metaDataContexts, transactionContexts, new 
ModeScheduleContext(modeConfig));
         afterBuildContextManager();
@@ -89,12 +91,12 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     
     private void beforeBuildContextManager(final ModeConfiguration modeConfig, 
final Map<String, Map<String, DataSource>> dataSourcesMap,
                                            final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs, final 
Collection<RuleConfiguration> globalRuleConfigs,
-                                           final Properties props, final 
boolean isOverwrite, final Integer port) throws SQLException {
+                                           final Properties props, final 
boolean isOverwrite, final Integer port, final String schemaName) throws 
SQLException {
         ClusterPersistRepository repository = 
createClusterPersistRepository((ClusterPersistRepositoryConfiguration) 
modeConfig.getRepository());
         registryCenter = new RegistryCenter(repository, port);
         metaDataPersistService = new MetaDataPersistService(repository);
         persistConfigurations(metaDataPersistService, dataSourcesMap, 
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite);
-        Collection<String> schemaNames = 
metaDataPersistService.getSchemaMetaDataService().loadAllNames();
+        Collection<String> schemaNames = Strings.isNullOrEmpty(schemaName) ? 
metaDataPersistService.getSchemaMetaDataService().loadAllNames() : 
Arrays.asList(schemaName);
         Map<String, Map<String, DataSource>> clusterDataSources = 
loadDataSourcesMap(metaDataPersistService, dataSourcesMap, schemaNames);
         Map<String, Collection<RuleConfiguration>> clusterSchemaRuleConfigs = 
loadSchemaRules(metaDataPersistService, schemaNames);
         Properties clusterProps = 
metaDataPersistService.getPropsService().load();
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index e96d03b..72ae990 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -104,7 +104,7 @@ public final class ClusterContextManagerCoordinatorTest {
         PersistRepositoryConfiguration persistRepositoryConfiguration = new 
ClusterPersistRepositoryConfiguration("TEST", "", "", new Properties());
         ModeConfiguration configuration = new ModeConfiguration("Cluster", 
persistRepositoryConfiguration, false);
         ClusterContextManagerBuilder builder = new 
ClusterContextManagerBuilder();
-        contextManager = builder.build(configuration, new HashMap<>(), new 
HashMap<>(), new LinkedList<>(), new Properties(), false, null);
+        contextManager = builder.build(configuration, new HashMap<>(), new 
HashMap<>(), new LinkedList<>(), new Properties(), false, null, null);
         contextManager.renewMetaDataContexts(new 
MetaDataContexts(contextManager.getMetaDataContexts().getMetaDataPersistService().get(),
 createMetaDataMap(), globalRuleMetaData, 
                 mock(ExecutorEngine.class),
                 new ConfigurationProperties(new Properties()), 
mock(OptimizerContext.class, RETURNS_DEEP_STUBS)));
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
index 9b9b084..016a1ce 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
@@ -45,7 +45,7 @@ public final class MemoryContextManagerBuilder implements 
ContextManagerBuilder
     @Override
     public ContextManager build(final ModeConfiguration modeConfig, final 
Map<String, Map<String, DataSource>> dataSourcesMap,
                                 final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs, final 
Collection<RuleConfiguration> globalRuleConfigs,
-                                final Properties props, final boolean 
isOverwrite, final Integer port) throws SQLException {
+                                final Properties props, final boolean 
isOverwrite, final Integer port, final String schemaName) throws SQLException {
         Map<String, Collection<ShardingSphereRule>> rules = 
SchemaRulesBuilder.buildRules(dataSourcesMap, schemaRuleConfigs, props);
         Map<String, ShardingSphereSchema> schemas = new 
SchemaLoader(dataSourcesMap, schemaRuleConfigs, rules, props).load();
         MetaDataContexts metaDataContexts = new 
MetaDataContextsBuilder(dataSourcesMap, schemaRuleConfigs, globalRuleConfigs, 
schemas, rules, props).build(null);
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index c8e1770..778a49b 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.mode.manager.standalone;
 
+import com.google.common.base.Strings;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
@@ -41,6 +42,7 @@ import 
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
 
 import javax.sql.DataSource;
 import java.sql.SQLException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -61,12 +63,12 @@ public final class StandaloneContextManagerBuilder 
implements ContextManagerBuil
     @Override
     public ContextManager build(final ModeConfiguration modeConfig, final 
Map<String, Map<String, DataSource>> dataSourcesMap,
                                 final Map<String, 
Collection<RuleConfiguration>> schemaRuleConfigs, final 
Collection<RuleConfiguration> globalRuleConfigs,
-                                final Properties props, final boolean 
isOverwrite, final Integer port) throws SQLException {
+                                final Properties props, final boolean 
isOverwrite, final Integer port, final String schemaName) throws SQLException {
         PersistRepositoryConfiguration repositoryConfig = null == 
modeConfig.getRepository() ? new 
StandalonePersistRepositoryConfiguration("File", new Properties()) : 
modeConfig.getRepository();
         StandalonePersistRepository repository = 
TypedSPIRegistry.getRegisteredService(StandalonePersistRepository.class, 
repositoryConfig.getType(), repositoryConfig.getProps());
         MetaDataPersistService metaDataPersistService = new 
MetaDataPersistService(repository);
         persistConfigurations(metaDataPersistService, dataSourcesMap, 
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite);
-        Collection<String> schemaNames = 
metaDataPersistService.getSchemaMetaDataService().loadAllNames();
+        Collection<String> schemaNames = Strings.isNullOrEmpty(schemaName) ? 
metaDataPersistService.getSchemaMetaDataService().loadAllNames() : 
Arrays.asList(schemaName);
         Map<String, Map<String, DataSource>> standaloneDataSources = 
loadDataSourcesMap(metaDataPersistService, dataSourcesMap, schemaNames);
         Map<String, Collection<RuleConfiguration>> standaloneSchemaRules = 
loadSchemaRules(metaDataPersistService, schemaNames);
         Properties standaloneProps = 
metaDataPersistService.getPropsService().load();
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
index fc71c0b..acfc587 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
@@ -56,7 +56,8 @@ public final class StandaloneContextManagerBuilderTextTest {
         Properties props = new Properties();
         ModeConfiguration modeConfiguration = new 
ModeConfiguration("testType", null, false);
         StandaloneContextManagerBuilder standaloneContextManagerBuilder = new 
StandaloneContextManagerBuilder();
-        ContextManager actual = 
standaloneContextManagerBuilder.build(modeConfiguration, dataSourceMap, 
schemaRuleConfigs, globalRuleConfigurationCollection, props, false, 1000);
+        ContextManager actual = 
standaloneContextManagerBuilder.build(modeConfiguration, dataSourceMap, 
schemaRuleConfigs, 
+                globalRuleConfigurationCollection, props, false, 1000, null);
         MetaDataContexts metaDataContexts = actual.getMetaDataContexts();
         
assertNotNull(metaDataContexts.getMetaDataMap().get(TEST_DATA_SOURCE_INNER_MAP));
         assertNotNull(metaDataContexts.getExecutorEngine());
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
index a47729d..e2fc5c9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
@@ -77,7 +77,7 @@ public final class BootstrapInitializer {
         boolean isOverwrite = null == modeConfig || modeConfig.isOverwrite();
         Map<String, Map<String, DataSource>> dataSourcesMap = 
getDataSourcesMap(proxyConfig.getSchemaDataSources());
         ContextManager contextManager = 
ContextManagerBuilderFactory.newInstance(modeConfig).build(modeConfig, 
dataSourcesMap,
-                proxyConfig.getSchemaRules(), proxyConfig.getGlobalRules(), 
proxyConfig.getProps(), isOverwrite, port);
+                proxyConfig.getSchemaRules(), proxyConfig.getGlobalRules(), 
proxyConfig.getProps(), isOverwrite, port, null);
         ProxyContext.getInstance().init(contextManager);
     }
     

Reply via email to