Java Code Examples for com.alibaba.druid.pool.DruidDataSource#isEnable()

The following examples show how to use com.alibaba.druid.pool.DruidDataSource#isEnable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicDBUtil.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 通过 dbKey ,获取数据源
 *
 * @param dbKey
 * @return
 */
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
    //获取多数据源配置
    DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    //先判断缓存中是否存在数据库链接
    DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
    if (cacheDbSource != null && !cacheDbSource.isClosed()) {
        log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
        return cacheDbSource;
    } else {
        DruidDataSource dataSource = getJdbcDataSource(dbSource);
        if(dataSource!=null && dataSource.isEnable()){
            DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
        }else{
            throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey);
        }
        log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
        return dataSource;
    }
}
 
Example 2
Source File: DynamicDBUtil.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 通过 dbKey ,获取数据源
 *
 * @param dbKey
 * @return
 */
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
    //获取多数据源配置
    DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    //先判断缓存中是否存在数据库链接
    DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
    if (cacheDbSource != null && !cacheDbSource.isClosed()) {
        log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
        return cacheDbSource;
    } else {
        DruidDataSource dataSource = getJdbcDataSource(dbSource);
        if(dataSource!=null && dataSource.isEnable()){
            DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
        }else{
            throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey);
        }
        log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
        return dataSource;
    }
}
 
Example 3
Source File: DataSourceCachePool.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 清空数据源缓存
 */
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();
}
 
Example 4
Source File: DataSourceCachePool.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: DataSourceCachePool.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 清空数据源缓存
 */
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();
}
 
Example 6
Source File: DataSourceCachePool.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
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);
}