use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project XHuiCloud by sindaZeng.
the class GenDsInfoServiceImpl method addDynamicDataSource.
@Override
public Boolean addDynamicDataSource(GenDsInfo genDsInfo) {
DataSourceProperty dataSourceProperty = new DataSourceProperty();
dataSourceProperty.setPoolName(genDsInfo.getName());
dataSourceProperty.setUrl(String.format(DsJdbcUrlEnum.get(genDsInfo.getType()).getUrl(), genDsInfo.getHost(), genDsInfo.getPort(), genDsInfo.getName()));
dataSourceProperty.setUsername(genDsInfo.getUsername());
dataSourceProperty.setPassword(genDsInfo.getPassword());
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
DynamicRoutingDataSource dynamicRoutingDataSource = SpringUtil.getBean(DynamicRoutingDataSource.class);
dynamicRoutingDataSource.addDataSource(dataSourceProperty.getPoolName(), dataSource);
return Boolean.TRUE;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project XHuiCloud by sindaZeng.
the class GenDsInfoServiceImpl method updateDynamicDataSource.
@Override
public Boolean updateDynamicDataSource(GenDsInfo genDsInfo) {
GenDsInfo _genDsInfo = getById(genDsInfo.getId());
if (_genDsInfo == null) {
throw SysException.sysFail("数据不存在");
}
// 先移除
DynamicRoutingDataSource dynamicRoutingDataSource = SpringUtil.getBean(DynamicRoutingDataSource.class);
dynamicRoutingDataSource.removeDataSource(_genDsInfo.getName());
// 再添加
addDynamicDataSource(genDsInfo);
if (StrUtil.isNotBlank(genDsInfo.getPassword())) {
_genDsInfo.setPassword(AesUtil.decrypt(genDsInfo.getPassword()));
}
return updateById(_genDsInfo);
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project eden-architect by shiyindaxiaojie.
the class DynamicDataSourceAutoConfiguration method dataSource.
/**
* 装配数据源
*
* @return
*/
@Primary
@Bean
public DataSource dataSource() {
log.info(AUTOWIRED_DYNAMIC_ROUTING_DATA_SOURCE);
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(dynamicDataSourceProperties.getPrimary());
dataSource.setStrict(dynamicDataSourceProperties.getStrict());
dataSource.setStrategy(dynamicDataSourceProperties.getStrategy());
dataSource.setP6spy(dynamicDataSourceProperties.getP6spy());
dataSource.setSeata(dynamicDataSourceProperties.getSeata());
return dataSource;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project dynamic-datasource-samples by dynamic-datasource.
the class MyQuartzAutoConfigurationMode2 method dataSource.
@Primary
@Bean
public DataSource dataSource() {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(properties.getPrimary());
dataSource.setStrict(properties.getStrict());
dataSource.setStrategy(properties.getStrategy());
dataSource.setP6spy(properties.getP6spy());
dataSource.setSeata(properties.getSeata());
return dataSource;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project longmarch by yuyueqty.
the class DataSourceController method remove.
@ApiOperation(value = "删除数据源")
@DeleteMapping
public String remove(String name) {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
ds.removeDataSource(name);
return "删除成功";
}
Aggregations