cc.iliz.mybatis.shading.db.ShardingEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-sharding Show documentation
Show all versions of mybatis-sharding Show documentation
A sharding based on mybatis
package cc.iliz.mybatis.shading.db;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.ibatis.mapping.SqlCommandType;
import org.springframework.util.StringUtils;
public class ShardingEntry {
private Map> dbTables=new ConcurrentHashMap<>();
private String sql;
private SqlCommandType sqlCommandType;
private Set names;
public ShardingEntry(){}
public ShardingEntry(String sql) {
super();
this.sql = sql;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public SqlCommandType getSqlCommandType() {
return sqlCommandType;
}
public void setSqlCommandType(SqlCommandType sqlCommandType) {
this.sqlCommandType = sqlCommandType;
}
public Set getNames() {
return names;
}
public void setNames(Set names) {
this.names = names;
}
public Map> getDbTables() {
return dbTables;
}
public void setDbTables(Map> dbTables) {
this.dbTables = dbTables;
}
public void addItemToDbTables(String datasourceName,String tableName){
if(StringUtils.isEmpty(datasourceName) || StringUtils.isEmpty(tableName)){
return;
}
Set tableNames = dbTables.get(datasourceName);
if(tableNames != null){
tableNames.add(tableName);
}else{
tableNames = new HashSet<>();
tableNames.add(tableName);
dbTables.put(datasourceName, tableNames);
}
}
}