use of com.hccake.ballcat.codegen.model.entity.DataSourceConfig in project ballcat-codegen by ballcat-projects.
the class DataSourceConfigServiceImpl method save.
@Override
public boolean save(DataSourceConfigDTO dto) {
// 新的数据源配置信息
DataSourceProperty dataSourceProperty = dynamicDataSourceHelper.prodDataSourceProperty(dto.getDsKey(), dto.getUrl(), dto.getUsername(), dto.getPass());
// 校验数据源配置
if (dynamicDataSourceHelper.isErrorDataSourceProperty(dataSourceProperty)) {
return false;
}
// 转换为实体,并将密码加密
DataSourceConfig dataSourceConfig = DataSourceConfigConverter.INSTANCE.dtoToPo(dto);
String pass = dto.getPass();
dataSourceConfig.setPassword(dynamicDataSourceHelper.encryptPass(pass));
// 落库存储
int flag = baseMapper.insert(dataSourceConfig);
if (!SqlHelper.retBool(flag)) {
return false;
}
// 动态添加数据源
dynamicDataSourceHelper.addDynamicDataSource(dataSourceProperty);
return true;
}
use of com.hccake.ballcat.codegen.model.entity.DataSourceConfig in project ballcat-codegen by ballcat-projects.
the class DynamicJdbcDataSourceLoader method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
// 查找所有配置的生成项目使用数据源
List<DataSourceConfig> list = dataSourceConfigService.list();
// 遍历添加进动态数据源中
for (DataSourceConfig dataSourceConfig : list) {
String dsName = dataSourceConfig.getDsKey();
String username = dataSourceConfig.getUsername();
String password = dynamicDataSourceHelper.decryptPassword(dataSourceConfig.getPassword());
String url = dataSourceConfig.getUrl();
DataSourceProperty property = dynamicDataSourceHelper.prodDataSourceProperty(dsName, url, username, password);
// 如果数据源异常,则不加载
if (!dynamicDataSourceHelper.isErrorDataSourceProperty(property)) {
dynamicDataSourceHelper.addDynamicDataSource(property);
}
}
}
use of com.hccake.ballcat.codegen.model.entity.DataSourceConfig in project ballcat-codegen by ballcat-projects.
the class DataSourceConfigServiceImpl method removeById.
@Override
public boolean removeById(Serializable id) {
// 获取现有数据源配置
DataSourceConfig oldConfig = baseMapper.selectById(id);
Assert.notNull(oldConfig, "Delete data source config that does not exist");
if (SqlHelper.retBool(baseMapper.deleteById(id))) {
// 删除现有数据源
dynamicDataSourceHelper.removeDataSource(oldConfig.getDsKey());
return true;
}
return false;
}
use of com.hccake.ballcat.codegen.model.entity.DataSourceConfig in project ballcat-codegen by ballcat-projects.
the class DataSourceConfigServiceImpl method update.
/**
* 更新数据源配置
* @param dto 数据源配置信息
* @return boolean
*/
@Override
public boolean update(DataSourceConfigDTO dto) {
// 获取现有数据源配置
DataSourceConfig oldConfig = baseMapper.selectById(dto.getId());
Assert.notNull(oldConfig, "Update data source config that does not exist");
// 转换为实体
DataSourceConfig dataSourceConfig = DataSourceConfigConverter.INSTANCE.dtoToPo(dto);
// 若没有修改密码,则使用现有的密码,否则加密存储
String pass = dto.getPass();
if (StrUtil.isBlank(pass)) {
pass = dynamicDataSourceHelper.decryptPassword(oldConfig.getPassword());
} else {
dataSourceConfig.setPassword(dynamicDataSourceHelper.encryptPass(pass));
}
// 新的数据源配置信息
DataSourceProperty dataSourceProperty = dynamicDataSourceHelper.prodDataSourceProperty(dto.getDsKey(), dto.getUrl(), dto.getUsername(), pass);
// 校验数据源配置
if (dynamicDataSourceHelper.isErrorDataSourceProperty(dataSourceProperty)) {
return false;
}
// 落库存储
int flag = baseMapper.updateById(dataSourceConfig);
if (!SqlHelper.retBool(flag)) {
return false;
}
// 先删除现有数据源
dynamicDataSourceHelper.removeDataSource(oldConfig.getDsKey());
// 再添加数据源
dynamicDataSourceHelper.addDynamicDataSource(dataSourceProperty);
return true;
}
Aggregations