use of com.google.common.collect.GenericMapMaker in project otter by alibaba.
the class MysqlDialect method initShardColumns.
private void initShardColumns() {
// soft引用设置,避免内存爆了
GenericMapMaker mapMaker = null;
mapMaker = new MapMaker().softValues().evictionListener(new MapEvictionListener<List<String>, Table>() {
public void onEviction(List<String> names, Table table) {
logger.warn("Eviction For Table:" + table);
}
});
this.shardColumns = mapMaker.makeComputingMap(new Function<List<String>, String>() {
public String apply(List<String> names) {
Assert.isTrue(names.size() == 2);
try {
String result = DdlUtils.getShardKeyByDRDS(jdbcTemplate, names.get(0), names.get(0), names.get(1));
if (StringUtils.isEmpty(result)) {
return "";
} else {
return result;
}
} catch (Exception e) {
throw new NestableRuntimeException("find table [" + names.get(0) + "." + names.get(1) + "] error", e);
}
}
});
}
Aggregations