forked from kidgrow-microservices-platform

克 刘
2020-03-16 549148d90d41a3320bd36d469fd690354c78de58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.kidgrow.db.sharding;
 
import org.apache.commons.lang.StringUtils;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: 按照字符串Hash求余确定分表<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/4 16:05 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
public class HashModTableSuffix implements TableSuffix {
 
    private String hash;
    private static final int MOD = 100;
 
    public HashModTableSuffix(String hash) {
        if (StringUtils.isEmpty(hash)) {
            throw new IllegalArgumentException("hash should not be null or empty");
        }
        this.hash = hash;
    }
 
    @Override
    public String getSuffix() {
        return String.format("_%d", hash.hashCode() / MOD);
    }
}