Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:DruidDatasource无法关闭closed (baomidou#637) #638

Merged
merged 2 commits into from
May 15, 2024

Conversation

shen3
Copy link
Contributor

@shen3 shen3 commented May 11, 2024

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style
  • Refactor
  • Doc
  • Other, please describe:

The description of the PR:
1、closeDataSource方法进来默认直接把数据源dataSource 赋值给 realDatasource。下面if...else条件如果为真,realDatasource会被重新赋值,不影响原来的逻辑。
2、如果dataSource 是Druid等其他的数据源,也能够被closed。

@huayanYu
Copy link
Member

不喜欢提前赋值的这种方式

@shen3
Copy link
Contributor Author

shen3 commented May 15, 2024

DataSource realDataSource = null;
if (dataSource instanceof ItemDataSource) {
realDataSource = ((ItemDataSource) dataSource).getRealDataSource();
} else {
if (seata) {
if (dataSource instanceof DataSourceProxy) {
DataSourceProxy dataSourceProxy = (DataSourceProxy) dataSource;
realDataSource = dataSourceProxy.getTargetDataSource();
}
}
if (p6spy) {
if (dataSource instanceof P6DataSource) {
Field realDataSourceField = P6DataSource.class.getDeclaredField("realDataSource");
realDataSourceField.setAccessible(true);
realDataSource = (DataSource) realDataSourceField.get(dataSource);
}
}
}

这种?

if (null == realDataSource) {
realDataSource = dataSource;
}

if (null != realDataSource) {
DataSourceDestroyer destroyer = new DefaultDataSourceDestroyer();
if (graceDestroy) {
destroyer.asyncDestroy(ds, realDataSource);
} else {
destroyer.destroy(ds, realDataSource);
}
}

@huayanYu
Copy link
Member

en

@shen3
Copy link
Contributor Author

shen3 commented May 15, 2024

已重新提交

@huayanYu huayanYu merged commit f018082 into baomidou:master May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants