zoukankan      html  css  js  c++  java
  • Spring Boot 整合 SardingSphere (精确分表策略)

    概要:

    application.properties

    # 精确分表策略
    spring.shardingsphere.sharding.tables.s_user.table-strategy.standard.sharding-column=age
    spring.shardingsphere.sharding.tables.s_user.table-strategy.standard.precise-algorithm-class-name=com.sharding.demo.config.TableShardingAlgorithm

    TableShardingAlgorithm

    package com.sharding.demo.config;
    
    import lombok.extern.slf4j.Slf4j;
    import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
    import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
    
    import java.util.Collection;
    
    @Slf4j
    public class TableShardingAlgorithm implements PreciseShardingAlgorithm<String> {
    
        @Override
        public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<String> preciseShardingValue) {
            try{
                log.info("preciseShardingValue:{},column:{}",preciseShardingValue.getValue(),preciseShardingValue.getColumnName());
                for (String each : availableTargetNames) {
                    log.info("each:" + each);
                }
                // 返回 就是最后落实的表
                return "s_user0";
            } catch (Exception e){
                e.printStackTrace();
            }
            throw new IllegalArgumentException();
        }
    }
  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/15734061.html
Copyright © 2011-2022 走看看