forked from github/dataease
feat: 根据dataease.properties配置里的mysql链接信息来更新demo数据源的配置信息
This commit is contained in:
parent
ffdf4022a2
commit
80e9a9fe6a
@ -26,6 +26,7 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
|
||||
datasourceService.initDsCheckJob();
|
||||
dataSetTableService.updateDatasetTableStatus();
|
||||
engineService.initSimpleEngine();
|
||||
datasourceService.updateDemoDs();
|
||||
CacheUtils.removeAll("ENGINE");
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -646,4 +648,22 @@ public class DatasourceService {
|
||||
addJob(basicInfo.getDsCheckIntervalType(), Integer.valueOf(basicInfo.getDsCheckInterval()));
|
||||
}
|
||||
|
||||
public void updateDemoDs() {
|
||||
Datasource datasource = datasourceMapper.selectByPrimaryKey("76026997-94f9-4a35-96ca-151084638969");
|
||||
MysqlConfiguration mysqlConfiguration = new Gson().fromJson(datasource.getConfiguration(), MysqlConfiguration.class);
|
||||
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
||||
Matcher matcher = WITH_SQL_FRAGMENT.matcher(env.getProperty("spring.datasource.url"));
|
||||
if (!matcher.find()) {
|
||||
return;
|
||||
}
|
||||
mysqlConfiguration.setHost(matcher.group(1));
|
||||
mysqlConfiguration.setPort(Integer.valueOf(matcher.group(2)));
|
||||
mysqlConfiguration.setDataBase(matcher.group(3).split("\\?")[0]);
|
||||
mysqlConfiguration.setExtraParams(matcher.group(3).split("\\?")[1]);
|
||||
mysqlConfiguration.setUsername(env.getProperty("spring.datasource.username"));
|
||||
mysqlConfiguration.setPassword(env.getProperty("spring.datasource.password"));
|
||||
datasource.setConfiguration(new Gson().toJson(mysqlConfiguration));
|
||||
datasourceMapper.updateByPrimaryKey(datasource);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user