fix(datasource): rebuild connection url when params change (#345)#537
Open
wsyjh8 wants to merge 1 commit into
Open
fix(datasource): rebuild connection url when params change (#345)#537wsyjh8 wants to merge 1 commit into
wsyjh8 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么 / 为什么需要
updateDatasource之前直接使用resolveConnectionUrl:当客户端带回原有 connectionUrl 时会原样保存,导致修改 databaseName / host / port 后,URL 中的库名等不随之更新(#345)。这是 service 层的契约问题,而不仅是 UI 问题:#484 将 connectionUrl 标记为
@JsonProperty(WRITE_ONLY)后,自带 UI 的 GET 不再返回 URL、提交时该字段为空,从而掩盖了 UI 上的症状;但 REST / MCP 等直接携带 URL 的调用方仍可稳定复现。本 PR 在连接参数发生变化时,按参数重新生成连接 URL。
是否修复了某个 issue?
Fixes #345
如何实现的
updateDatasource:当existing != null、handler 具备必需连接字段、且连接参数(type / host / port / databaseName)发生变化时,调用buildConnectionUrl按参数重建;否则保留resolveConnectionUrl的结果,避免覆盖用户手动填写的自定义 URL。|时回退到resolveConnectionUrl、保留原 URL。目前 Oracle 的 databaseName 形如service|schema,朴素重建会把|schema拼进 URL,此守卫可避免拼坏。|,本逻辑会自动采用,无需后续改动。buildConnectionUrl),本 PR 不改变其现有行为,为其补充 URL 构造属于独立增强。如何验证
新增
DatasourceServiceImplTest用例:updateDatasource_rebuildsConnectionUrlWhenDatabaseNameChanges:MySQL 修改库名后 URL 反映新库名(复现 [BUG] 数据源模块,修改数据库名,url中的库名不会跟着变更 #345)。updateDatasource_preservesCustomUrlWhenParamsUnchanged:参数未变化时保留用户自定义 URL。updateDatasource_preservesUrlForCompositeDatabaseName:Oracleservice|schema仅 schema 变化时保留原 URL,不被拼坏。updateDatasource_rebuildsUrlForPostgresCompositeDatabaseName:PostgreSQLdb|schema修改库名时正常重建,且|不泄漏进 URL(验证守卫未误伤 PostgreSQL)。执行以下命令通过:
./mvnw.cmd -pl data-agent-management test -Dtest=DatasourceServiceImplTest -Dcheckstyle.skip=true./mvnw.cmd -pl data-agent-management test -Dtest=DatasourceServiceImplTest,DatasourceControllerTest,*DatasourceTypeHandlerTest,DatasourceTypeHandlerRegistryTest -DfailIfNoTests=false./mvnw.cmd -pl data-agent-management spotless:check./mvnw.cmd -pl data-agent-management checkstyle:check给 reviewer 的特别说明
OracleDatasourceTypeHandler.buildConnectionUrl与realConnectionTest,本 PR 改动updateDatasource并新增connectionParamsChanged;共用文件DatasourceServiceImpl.java的改动位于不同方法,合并冲突风险极低。