feat: close method
This commit is contained in:
parent
9ea902215a
commit
a7b4650156
@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@ -51,7 +52,7 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
|
||||
|
||||
private static final String UNDERLINE = "_";
|
||||
/**
|
||||
* 所有数据库¬
|
||||
* 所有数据库
|
||||
*/
|
||||
private final Map<String, DataSource> dataSourceMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
@ -90,17 +91,6 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
|
||||
throw new CannotFindDataSourceException("dynamic-datasource can not find primary datasource");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前所有的数据源
|
||||
* please use getDataSources()
|
||||
*
|
||||
* @return 当前所有数据源
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<String, DataSource> getCurrentDataSources() {
|
||||
return dataSourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的数据源
|
||||
*
|
||||
@ -110,17 +100,6 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
|
||||
return dataSourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取的当前所有的分组数据源
|
||||
* please use getGroupDataSources()
|
||||
*
|
||||
* @return 当前所有的分组数据源
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<String, GroupDataSource> getCurrentGroupDataSources() {
|
||||
return groupDataSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取的所有的分组数据源
|
||||
*
|
||||
@ -295,16 +274,7 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
|
||||
dataSource = (DataSource) realDataSourceField.get(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
Method closeMethod = null;
|
||||
for(Class<?> clazz = dataSource.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
|
||||
try {
|
||||
closeMethod = clazz.getDeclaredMethod("close");
|
||||
if (closeMethod != null) {
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored){}
|
||||
}
|
||||
Method closeMethod = ReflectionUtils.findMethod(dataSource.getClass(), "close");
|
||||
if (closeMethod != null) {
|
||||
closeMethod.invoke(dataSource);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user