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;
}
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);
}
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;
}
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;
}
}
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);
}
Aggregations