use of com.xhuicloud.common.datasource.entity.GenDsInfo in project XHuiCloud by sindaZeng.
the class GenCodeController method generator.
/**
* 代码生成
* 数据库名 需要生成的表名。必须严格传入此库拥有的表
*/
@SneakyThrows
@PostMapping
@PreAuthorize("@authorize.hasPermission('sys_download_code')")
public void generator(@RequestParam Integer dataSourceId, @Valid @RequestBody GenCodeDto genCodeDto, HttpServletResponse response) {
GenDsInfo genDsInfo = genDsInfoService.getById(dataSourceId);
JdbcHandle jdbcHandle = handle.get(genDsInfo.getType());
if (ObjectUtil.isNotNull(jdbcHandle) && jdbcHandle.test(genDsInfo)) {
DynamicDataSourceContextHolder.push(genDsInfo.getName());
byte[] data = jdbcHandle.genCode(genCodeDto);
response.reset();
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s.zip", genCodeDto.getModuleName()));
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
DynamicDataSourceContextHolder.clear();
}
}
use of com.xhuicloud.common.datasource.entity.GenDsInfo 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.xhuicloud.common.datasource.entity.GenDsInfo in project XHuiCloud by sindaZeng.
the class GenDatasourceInfoController method getTableInfoById.
/**
* 分页查询数据源的表信息
*
* @param id 数据源
* @return
*/
@GetMapping("/{id}")
public Response getTableInfoById(Page page, @PathVariable Integer id) {
GenDsInfo genDsInfo = genDsInfoService.getById(id);
JdbcHandle jdbcHandle = handle.get(genDsInfo.getType());
jdbcHandle.test(genDsInfo);
return Response.success(jdbcHandle.getPageTableInfo(page));
}
use of com.xhuicloud.common.datasource.entity.GenDsInfo 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);
}
Aggregations