use of com.xhuicloud.common.datasource.enums.DsJdbcUrlEnum 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;
}
Aggregations