浏览代码

合并代码

syh 4 年之前
父节点
当前提交
78355b53ad

+ 0 - 92
jeecg-boot-module-system/src/main/java/org/jeecg/modules/db/dynamic/DataSourceCachePool.java

@@ -1,92 +0,0 @@
-package org.jeecg.modules.db.dynamic;
-
-import cn.com.ctop.common.module.service.ISysBaseApi;
-import com.alibaba.druid.pool.DruidDataSource;
-import org.jeecg.common.constant.CacheConstant;
-import org.jeecg.common.system.vo.DynamicDataSourceModel;
-import org.jeecg.common.util.SpringContextUtils;
-import org.springframework.data.redis.core.RedisTemplate;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * 数据源缓存池
- */
-public class DataSourceCachePool {
-    /** 数据源连接池缓存【本地 class缓存 - 不支持分布式】 */
-    private static Map<String, DruidDataSource> dbSources = new HashMap<>();
-    private static RedisTemplate<String, Object> redisTemplate;
-
-    private static RedisTemplate<String, Object> getRedisTemplate() {
-        if (redisTemplate == null) {
-            redisTemplate = (RedisTemplate<String, Object>) SpringContextUtils.getBean("redisTemplate");
-        }
-        return redisTemplate;
-    }
-
-    /**
-     * 获取多数据源缓存
-     *
-     * @param dbKey
-     * @return
-     */
-    public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) {
-        String redisCacheKey = CacheConstant.SYS_DYNAMICDB_CACHE + dbKey;
-        if (getRedisTemplate().hasKey(redisCacheKey)) {
-            return (DynamicDataSourceModel) getRedisTemplate().opsForValue().get(redisCacheKey);
-        }
-        ISysBaseApi sysBaseAPI = SpringContextUtils.getBean(ISysBaseApi.class);
-        DynamicDataSourceModel dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey);
-        if (dbSource != null) {
-            getRedisTemplate().opsForValue().set(redisCacheKey, dbSource);
-        }
-        return dbSource;
-    }
-
-    public static DruidDataSource getCacheBasicDataSource(String dbKey) {
-        return dbSources.get(dbKey);
-    }
-
-    /**
-     * put 数据源缓存
-     *
-     * @param dbKey
-     * @param db
-     */
-    public static void putCacheBasicDataSource(String dbKey, DruidDataSource db) {
-        dbSources.put(dbKey, db);
-    }
-
-    /**
-     * 清空数据源缓存
-     */
-    public static void cleanAllCache() {
-        //关闭数据源连接
-        for(Map.Entry<String, DruidDataSource> entry : dbSources.entrySet()){
-            String dbkey = entry.getKey();
-            DruidDataSource druidDataSource = entry.getValue();
-            if(druidDataSource!=null && druidDataSource.isEnable()){
-                druidDataSource.close();
-            }
-            //清空redis缓存
-            getRedisTemplate().delete(CacheConstant.SYS_DYNAMICDB_CACHE + dbkey);
-        }
-        //清空缓存
-        dbSources.clear();
-    }
-
-    public static void removeCache(String dbKey) {
-        //关闭数据源连接
-        DruidDataSource druidDataSource = dbSources.get(dbKey);
-        if(druidDataSource!=null && druidDataSource.isEnable()){
-            druidDataSource.close();
-        }
-        //清空redis缓存
-        getRedisTemplate().delete(CacheConstant.SYS_DYNAMICDB_CACHE + dbKey);
-        //清空缓存
-        dbSources.remove(dbKey);
-    }
-
-}

+ 2 - 1
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/dynamic/db/DynamicDBUtil.java

@@ -1,4 +1,4 @@
-package org.jeecg.common.util.dynamic.db;
+package cn.com.ctop.common.module.db.dynamic;
 
 import com.alibaba.druid.pool.DruidDataSource;
 import lombok.extern.slf4j.Slf4j;
@@ -6,6 +6,7 @@ import org.apache.commons.lang.ArrayUtils;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.DynamicDataSourceModel;
 import org.jeecg.common.util.ReflectHelper;
+import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
 import org.jeecg.common.util.oConvertUtils;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;