Search in sources :

Example 1 with MapEvictionListener

use of com.google.common.collect.MapEvictionListener in project otter by alibaba.

the class AbstractDbDialect method initTables.

// ================================ helper method ==========================
private void initTables(final JdbcTemplate jdbcTemplate) {
    // 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.tables = mapMaker.makeComputingMap(new Function<List<String>, Table>() {

        public Table apply(List<String> names) {
            Assert.isTrue(names.size() == 2);
            try {
                beforeFindTable(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                DdlUtilsFilter filter = getDdlUtilsFilter(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                Table table = DdlUtils.findTable(jdbcTemplate, names.get(0), names.get(0), names.get(1), filter);
                afterFindTable(table, jdbcTemplate, names.get(0), names.get(0), names.get(1));
                if (table == null) {
                    throw new NestableRuntimeException("no found table [" + names.get(0) + "." + names.get(1) + "] , pls check");
                } else {
                    return table;
                }
            } 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) DdlUtilsFilter(com.alibaba.otter.shared.common.utils.meta.DdlUtilsFilter) GenericMapMaker(com.google.common.collect.GenericMapMaker) MapMaker(com.google.common.collect.MapMaker) List(java.util.List) MapEvictionListener(com.google.common.collect.MapEvictionListener) DataAccessException(org.springframework.dao.DataAccessException) NestableRuntimeException(org.apache.commons.lang.exception.NestableRuntimeException) SQLException(java.sql.SQLException)

Example 2 with MapEvictionListener

use of com.google.common.collect.MapEvictionListener 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)2 GenericMapMaker (com.google.common.collect.GenericMapMaker)2 MapEvictionListener (com.google.common.collect.MapEvictionListener)2 MapMaker (com.google.common.collect.MapMaker)2 List (java.util.List)2 NestableRuntimeException (org.apache.commons.lang.exception.NestableRuntimeException)2 Table (org.apache.ddlutils.model.Table)2 DdlUtilsFilter (com.alibaba.otter.shared.common.utils.meta.DdlUtilsFilter)1 SQLException (java.sql.SQLException)1 DataAccessException (org.springframework.dao.DataAccessException)1