Search in sources :

Example 1 with DynamicDataSourceModel

use of org.jeecg.common.system.vo.DynamicDataSourceModel in project kms by mahonelau.

the class DataSourceCachePool method getCacheDynamicDataSourceModel.

/**
 * 获取多数据源缓存
 *
 * @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);
    }
    CommonAPI commonAPI = SpringContextUtils.getBean(CommonAPI.class);
    DynamicDataSourceModel dbSource = commonAPI.getDynamicDbSourceByCode(dbKey);
    if (dbSource != null) {
        getRedisTemplate().opsForValue().set(redisCacheKey, dbSource);
    }
    return dbSource;
}
Also used : CommonAPI(org.jeecg.common.api.CommonAPI) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 2 with DynamicDataSourceModel

use of org.jeecg.common.system.vo.DynamicDataSourceModel in project kms by mahonelau.

the class SqlUtils method createPageSqlByDBKey.

/**
 * 生成分页查询 SQL
 *
 * @param sql
 * @param page
 * @param rows
 * @return
 */
public static String createPageSqlByDBKey(String dbKey, String sql, int page, int rows) {
    DynamicDataSourceModel dynamicSourceEntity = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    String dbType = dynamicSourceEntity.getDbType();
    return createPageSqlByDBType(dbType, sql, page, rows);
}
Also used : DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 3 with DynamicDataSourceModel

use of org.jeecg.common.system.vo.DynamicDataSourceModel in project kykms by mahonelau.

the class DataSourceCachePool method getCacheDynamicDataSourceModel.

/**
 * 获取多数据源缓存
 *
 * @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);
    }
    CommonAPI commonAPI = SpringContextUtils.getBean(CommonAPI.class);
    DynamicDataSourceModel dbSource = commonAPI.getDynamicDbSourceByCode(dbKey);
    if (dbSource != null) {
        getRedisTemplate().opsForValue().set(redisCacheKey, dbSource);
    }
    return dbSource;
}
Also used : CommonAPI(org.jeecg.common.api.CommonAPI) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 4 with DynamicDataSourceModel

use of org.jeecg.common.system.vo.DynamicDataSourceModel in project kykms by mahonelau.

the class DynamicDBUtil method getDbSourceByDbKey.

/**
 * 通过 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;
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 5 with DynamicDataSourceModel

use of org.jeecg.common.system.vo.DynamicDataSourceModel in project kykms by mahonelau.

the class SqlUtils method createPageSqlByDBKey.

/**
 * 生成分页查询 SQL
 *
 * @param sql
 * @param page
 * @param rows
 * @return
 */
public static String createPageSqlByDBKey(String dbKey, String sql, int page, int rows) {
    DynamicDataSourceModel dynamicSourceEntity = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    String dbType = dynamicSourceEntity.getDbType();
    return createPageSqlByDBType(dbType, sql, page, rows);
}
Also used : DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Aggregations

DynamicDataSourceModel (org.jeecg.common.system.vo.DynamicDataSourceModel)8 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 CommonAPI (org.jeecg.common.api.CommonAPI)3 JeecgBootException (org.jeecg.common.exception.JeecgBootException)3