use of com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty 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.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty in project ballcat-codegen by ballcat-projects.
the class DynamicDataSourceHelper method prodDataSourceProperty.
/**
* 获得数据源配置实体
* @param dsName 数据源名称
* @param url 数据库连接
* @param username 数据库用户名
* @param password 数据库密码
* @return 数据源配置
*/
public DataSourceProperty prodDataSourceProperty(String dsName, String url, String username, String password) {
DataSourceProperty dataSourceProperty = new DataSourceProperty();
dataSourceProperty.setPoolName(dsName);
dataSourceProperty.setUrl(url);
dataSourceProperty.setUsername(username);
dataSourceProperty.setPassword(password);
return dataSourceProperty;
}
use of com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty 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.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty in project XHuiCloud by sindaZeng.
the class XHuiDynamicDataSourceProvider method executeStmt.
/**
* 执行语句获得数据源参数
* @param statement 语句
* @return 数据源参数
* @throws SQLException sql异常
*/
@SneakyThrows
@Override
protected Map<String, DataSourceProperty> executeStmt(Statement statement) throws SQLException {
ResultSet rs = statement.executeQuery(properties.getQueryDsSql());
Map<String, DataSourceProperty> map = new HashMap<>(8);
List<GenDsInfo> sysTenantDs = populate(rs, GenDsInfo.class);
for (GenDsInfo ds : sysTenantDs) {
String url;
DsJdbcUrlEnum dsJdbcUrlEnum = DsJdbcUrlEnum.get(ds.getType());
if (DsJdbcUrlEnum.MSSQL == dsJdbcUrlEnum) {
url = String.format(dsJdbcUrlEnum.getUrl(), ds.getHost(), ds.getPort(), ds.getName());
} else {
url = String.format(dsJdbcUrlEnum.getUrl(), ds.getHost(), ds.getPort(), ds.getName());
}
DataSourceProperty property = new DataSourceProperty();
property.setUsername(ds.getUsername());
property.setPassword(ds.getPassword());
property.setUrl(url);
map.put(ds.getName(), property);
}
// 添加默认主数据源
DataSourceProperty property = new DataSourceProperty();
property.setUsername(properties.getUsername());
property.setPassword(properties.getPassword());
property.setUrl(properties.getUrl());
map.put("master", property);
return map;
}
use of com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty in project ruoyi-vue-pro by YunaiV.
the class DbDocController method buildDataSource.
/**
* 创建数据源
*/
// TODO 芋艿:screw 暂时不支持 druid,尴尬
private HikariDataSource buildDataSource() {
// 获得 DataSource 数据源,目前只支持首个
String primary = dynamicDataSourceProperties.getPrimary();
DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary);
// 创建 HikariConfig 配置类
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(dataSourceProperty.getUrl());
hikariConfig.setUsername(dataSourceProperty.getUsername());
hikariConfig.setPassword(dataSourceProperty.getPassword());
// 设置可以获取 tables remarks 信息
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
// 创建数据源
return new HikariDataSource(hikariConfig);
}
Aggregations