com.github.antelopeframework.mybatis.shard.ShardTableHolder Maven / Gradle / Ivy
package com.github.antelopeframework.mybatis.shard;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.Assert;
import lombok.extern.slf4j.Slf4j;
/**
*
* @author yangzhi.yzh
*
*/
@Slf4j
public class ShardTableHolder {
private static final ShardTableHolder instance = new ShardTableHolder();
private final Map strategyRegister = new HashMap<>();
/**
*
* @return
*/
public static ShardTableHolder getInstance() {
return instance;
}
/**
* 注册分表配置项.
*
* @param table
* @param shardTable
*/
public void register(ShardTable shardTable) {
Assert.notNull(shardTable);
if (this.strategyRegister.containsKey(shardTable.getOriginalTableName())) {
log.error("ShardTable with same originalTableName has been registered, the oldest will be override: originalTableName={}",
shardTable.getOriginalTableName());
}
this.strategyRegister.put(shardTable.getOriginalTableName().toLowerCase(), shardTable);
}
/**
* 获取分表配置项.
*
* @param table
* @return
*/
public ShardTable getShardTable(String table) {
return this.strategyRegister.get(table.toLowerCase());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy