Search in sources :

Example 1 with GenericMapMaker

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);
            }
        }
    });
}
Also used : Function(com.google.common.base.Function) GenericMapMaker(com.google.common.collect.GenericMapMaker) Table(org.apache.ddlutils.model.Table) NestableRuntimeException(org.apache.commons.lang.exception.NestableRuntimeException) GenericMapMaker(com.google.common.collect.GenericMapMaker) MapMaker(com.google.common.collect.MapMaker) List(java.util.List) MapEvictionListener(com.google.common.collect.MapEvictionListener) NestableRuntimeException(org.apache.commons.lang.exception.NestableRuntimeException)

Aggregations

Function (com.google.common.base.Function)1 GenericMapMaker (com.google.common.collect.GenericMapMaker)1 MapEvictionListener (com.google.common.collect.MapEvictionListener)1 MapMaker (com.google.common.collect.MapMaker)1 List (java.util.List)1 NestableRuntimeException (org.apache.commons.lang.exception.NestableRuntimeException)1 Table (org.apache.ddlutils.model.Table)1