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);
|
}
|
}
|