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 65bdd344885 Remove SQLParserRuleConfiguration when use 
ShardingSphere-JDBC cluster mode (#19777)
65bdd344885 is described below

commit 65bdd3448856c17f9b29c57d5a13d15ce5e0b8de
Author: zhaojinchao <[email protected]>
AuthorDate: Tue Aug 2 15:03:08 2022 +0800

    Remove SQLParserRuleConfiguration when use ShardingSphere-JDBC cluster mode 
(#19777)
    
    * Remove SQLParserRuleConfiguration when use ShardingSphere-JDBC cluster 
mode
    
    * Adjument code
    
    * Rename method name
    
    * Rename realRuleConfigurations to databaseRuleConfigs
---
 .../jdbc/core/datasource/ShardingSphereDataSource.java    |  4 +++-
 .../core/datasource/ShardingSphereDataSourceTest.java     | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

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 71e9f7d7588..f7555d92016 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
@@ -69,8 +69,10 @@ public final class ShardingSphereDataSource extends 
AbstractDataSourceAdapter im
                                                 final 
Collection<RuleConfiguration> ruleConfigs, final Properties props) throws 
SQLException {
         InstanceMetaData instanceMetaData = 
InstanceMetaDataBuilderFactory.create("JDBC", -1);
         Collection<RuleConfiguration> globalRuleConfigs = 
ruleConfigs.stream().filter(each -> each instanceof 
GlobalRuleConfiguration).collect(Collectors.toList());
+        Collection<RuleConfiguration> databaseRuleConfigs = new 
LinkedList<>(ruleConfigs);
+        databaseRuleConfigs.removeAll(globalRuleConfigs);
         ContextManagerBuilderParameter parameter = new 
ContextManagerBuilderParameter(modeConfig, 
Collections.singletonMap(databaseName,
-                new DataSourceProvidedDatabaseConfiguration(dataSourceMap, 
ruleConfigs)), globalRuleConfigs, props, Collections.emptyList(), 
instanceMetaData);
+                new DataSourceProvidedDatabaseConfiguration(dataSourceMap, 
databaseRuleConfigs)), globalRuleConfigs, props, Collections.emptyList(), 
instanceMetaData);
         return 
ContextManagerBuilderFactory.getInstance(modeConfig).build(parameter);
     }
     
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index 53828487aeb..74914345672 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -25,6 +25,9 @@ import 
org.apache.shardingsphere.infra.database.DefaultDatabase;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
 import org.apache.shardingsphere.infra.state.StateType;
 import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
 import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
 import org.junit.After;
@@ -37,6 +40,7 @@ import java.sql.SQLException;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Arrays;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
@@ -74,6 +78,17 @@ public final class ShardingSphereDataSourceTest {
         
assertThat(contextManager.getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection().getMetaData().getURL(),
 is("jdbc:mock://127.0.0.1/foo_ds"));
     }
     
+    @Test
+    public void assertRemoveGlobalRuleConfiguration() throws SQLException {
+        Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
+        
when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds");
+        CacheOption cacheOption = new CacheOption(1024, 1024);
+        SQLParserRuleConfiguration sqlParserRuleConfig = new 
SQLParserRuleConfiguration(true, cacheOption, cacheOption);
+        ShardingSphereDataSource actual = new 
ShardingSphereDataSource(DefaultDatabase.LOGIC_NAME,
+                null, Collections.singletonMap("ds", new 
MockedDataSource(connection)), 
Arrays.asList(mock(ShardingRuleConfiguration.class), sqlParserRuleConfig), new 
Properties());
+        
assertThat(getContextManager(actual).getMetaDataContexts().getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getConfigurations().size(),
 is(2));
+    }
+    
     @Test
     public void assertGetConnectionWithUsernameAndPassword() throws 
SQLException {
         Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);

Reply via email to