| | |
| | | |
| | | |
| | | @Bean |
| | | public DataSource getDataSource(){ |
| | | public DataSource getDataSource() { |
| | | DataSource dataSource = null; |
| | | try { |
| | | Properties properties = new Properties(); |
| | |
| | | |
| | | /** |
| | | * 配置多数据源 |
| | | * |
| | | * @return |
| | | */ |
| | | private Map<String, DataSource> createDataSourceMap() { |
| | |
| | | |
| | | /** |
| | | * 分片配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private Collection<RuleConfiguration> createShardingRuleConfiguration() { |
| | |
| | | props1.setProperty("algorithm-expression", "t_user_competition$->{appUserId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_user_competition-inline", new AlgorithmConfiguration("INLINE", props1)); |
| | | result1.getKeyGenerators().put("t_user_competition-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | linkedList.add(result1); |
| | | |
| | | //分片规则配置 |
| | | ShardingRuleConfiguration result2 = new ShardingRuleConfiguration(); |
| | | result2.getTables().add(getPaymentCompetitionTableRuleConfiguration()); |
| | | result1.getTables().add(getPaymentCompetitionTableRuleConfiguration()); |
| | | Properties props2 = new Properties(); |
| | | props2.setProperty("algorithm-expression", "t_payment_competition$->{appUserId % 5 + 1}"); |
| | | result2.getShardingAlgorithms().put("t_payment_competition-inline", new AlgorithmConfiguration("INLINE", props2)); |
| | | result2.getKeyGenerators().put("t_payment_competition-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | linkedList.add(result2); |
| | | |
| | | result1.getShardingAlgorithms().put("t_payment_competition-inline", new AlgorithmConfiguration("INLINE", props2)); |
| | | result1.getKeyGenerators().put("t_payment_competition-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | linkedList.add(result1); |
| | | return linkedList; |
| | | } |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserCompetitionTableRuleConfiguration() { |
| | |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getPaymentCompetitionTableRuleConfiguration() { |