You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/25 02:44:06 UTC

[GitHub] [shardingsphere] q3056917665 commented on issue #17890: Multiple metadata OR All tables must be in the same datasource

q3056917665 commented on issue #17890:
URL: https://github.com/apache/shardingsphere/issues/17890#issuecomment-1136663331

   > Could you should us your rule configurations?
   
   ```
           Map<String, DataSource> dataSourceMap = new HashMap<>();
           dataSourceMap.put("ds", dataSource);
           dataSourceMap.put("dsweixin", dataSourceWeixin);
           dataSourceMap.put("dspay", dataSourcePay);
   
           //TableRuleConfiguration testTableRuleConfig = new TableRuleConfiguration("t_sharding_jdbc","ds.t_sharding_jdbc_${0..1}");
   
           List<ShardingTableRuleConfiguration> tableRuleConfigs = getTableRuleConfigs();
   
           // 配置分片规则
           ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
   
           for (ShardingTableRuleConfiguration tableRuleConfig : tableRuleConfigs) {
               shardingRuleConfiguration.getTables().add(tableRuleConfig);
   
   
           }
           Properties datePreciseShardingAlgorithmProps = new Properties();
           datePreciseShardingAlgorithmProps.setProperty("strategy", "STANDARD");
           datePreciseShardingAlgorithmProps.setProperty("algorithmClassName", monthDateStandardShardingAlgorithm.getClass().getName());
           shardingRuleConfiguration.getShardingAlgorithms().put("monthDateStandardShardingAlgorithm", new ShardingSphereAlgorithmConfiguration(monthDateStandardShardingAlgorithm.getType(), datePreciseShardingAlgorithmProps));
   
           Properties properties = new Properties();
           properties.setProperty("sql-show", "true");
           properties.setProperty("check-duplicate-table-enabled", "true");
           properties.setProperty("check-table-metadata-enabled ", "true");
           properties.setProperty("max.connections.size.per.query", "200");
           properties.setProperty("sql-federation-enabled", "true");
           // 获取数据源对象
           try {
               //创建sharding数据源
               logger.info("sharding开始创建数据源");
               long time = System.currentTimeMillis();
               DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Lists.newArrayList(shardingRuleConfiguration), properties);
               logger.info("sharding创建数据源结束,time:{}", (System.currentTimeMillis() - time));
               return dataSource;
           } catch (SQLException throwables) {
               logger.info("ShardingSphereConfig 创建ShardingDataSource失败", throwables);
   
           }
           return dataSource;
   ```


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

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org