jiangxiewei opened a new issue #4464: when did the configuration 
**default-database-strategy** work ?
URL: https://github.com/apache/incubator-shardingsphere/issues/4464
 
 
   ## First of all
   my English is suck
   ## Question
   when I only configured the default-database-strategy ( no specific table 
rule are configured ) , My defaul-database-strategy didn't work. (I use 
hintManager.setDatabaseShardingValue() )
   ##  Version
   4.0.0
   ##  Detail
   my configuration as follow :
   ``` properties
   spring.shardingsphere.datasource.names=psghz,psgother
   # psghz库配置
   
spring.shardingsphere.datasource.psghz.url=jdbc:postgresql://*******************:****/*****?useUnicode=true&characterEncoding=UTF-8&useSSL=false
   spring.shardingsphere.datasource.psghz.username=****
   spring.shardingsphere.datasource.psghz.password=********
   spring.shardingsphere.datasource.psghz.driverClassName=org.postgresql.Driver
   
spring.shardingsphere.datasource.psghz.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.psghz.max-active=10
   # psgother库配置
   
spring.shardingsphere.datasource.psgother.url=jdbc:postgresql://*******************:****/*****?useUnicode=true&characterEncoding=UTF-8&useSSL=false
   spring.shardingsphere.datasource.psgother.username=****
   spring.shardingsphere.datasource.psgother.password=********
   
spring.shardingsphere.datasource.psgother.driverClassName=org.postgresql.Driver
   
spring.shardingsphere.datasource.psgother.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.psgother.max-active=10
   # 默认hint配置
   
spring.shardingsphere.sharding.default-database-strategy.hint.algorithm-class-name=com.ibuscloud.pubtrans.analysis.plugin.sharding.HintShardingStrategy
   
#起初打开default-data-srouce-name,结果走了DefaultDatabaseRoutingEngine,关闭则走了UnicastRoutingEngine
   #spring.shardingsphere.sharding.default-data-source-name=psghz
   spring.shardingsphere.props.sql.show=true
   ````
   
   I follow  the code and see the RoutingEngineFactory.java create 
UnicastRoutingEngine.java 
   ``` java
            if (sqlStatementContext.getSqlStatement() instanceof DMLStatement 
&& tableNames.isEmpty() && shardingRule.hasDefaultDataSourceName()) {
               return new DefaultDatabaseRoutingEngine(shardingRule, 
tableNames);
           }
           if (sqlStatementContext.getSqlStatement() instanceof DMLStatement && 
shardingConditions.isAlwaysFalse() || tableNames.isEmpty() || 
!shardingRule.tableRuleExists(tableNames)) {
               return new UnicastRoutingEngine(shardingRule, tableNames);
           }
   ```
   and **!shardingRule.tableRuleExists(tableNames)** is true .
   so back to the question , how does the default-database-strategy.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to