use of io.seata.rm.datasource.DataSourceProxy in project dynamic-datasource-spring-boot-starter by baomidou.
the class DynamicRoutingDataSource method closeDataSource.
/**
* close db
*
* @param ds dsName
* @param dataSource db
*/
private void closeDataSource(String ds, DataSource dataSource) {
try {
if (dataSource instanceof ItemDataSource) {
((ItemDataSource) dataSource).close();
} else {
if (seata) {
if (dataSource instanceof DataSourceProxy) {
DataSourceProxy dataSourceProxy = (DataSourceProxy) dataSource;
dataSource = dataSourceProxy.getTargetDataSource();
}
}
if (p6spy) {
if (dataSource instanceof P6DataSource) {
Field realDataSourceField = P6DataSource.class.getDeclaredField("realDataSource");
realDataSourceField.setAccessible(true);
dataSource = (DataSource) realDataSourceField.get(dataSource);
}
}
Method closeMethod = ReflectionUtils.findMethod(dataSource.getClass(), "close");
if (closeMethod != null) {
closeMethod.invoke(dataSource);
}
}
} catch (Exception e) {
log.warn("dynamic-datasource closed datasource named [{}] failed", ds, e);
}
}
Aggregations