bharathikannan-zarget commented on issue #4478: Is this possible to just shard 
databases with table rule configuration?
URL: 
https://github.com/apache/incubator-shardingsphere/issues/4478#issuecomment-593363892
 
 
   Hi @menghaoranss 
   
   ```
     @Bean
     StandardShardingStrategyConfiguration 
standardShardingStrategyConfiguration() {
       return new StandardShardingStrategyConfiguration("tenant_id", new 
TenantIDBasedRoutingAlgorithm());
     }
   
   
     class TenantIDBasedRoutingAlgorithm implements 
PreciseShardingAlgorithm<String> {
       @Override
       public String doSharding(Collection<String> collection,
           PreciseShardingValue<String> preciseShardingValue) {
         System.out.println("Sharding Value::; " + 
preciseShardingValue.getValue());
         return null;
       }
     }
   ```
   
   # Sharding Config
   
   ```
   @Bean
     public DataSource createDataSource() throws SQLException {
       ShardingRuleConfiguration shardingRuleConfiguration = new 
ShardingRuleConfiguration();
       
shardingRuleConfiguration.setDefaultDatabaseShardingStrategyConfig(standardShardingStrategyConfiguration());
   
       return ShardingDataSourceFactory.createDataSource(getDataSources(), 
shardingRuleConfiguration, new HashMap<>(), new Properties());
     }
   ```
   
   We use database level sharding, for all the database same tables will be 
present. Based on the tenant id, we will route the database accordingly. I used 
ShardingDatabaseStrategey with no explicit table rules, i want sharding rules 
applied for the tables. 
   
   

----------------------------------------------------------------
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