fix db bug

This commit is contained in:
Looly
2019-08-22 21:04:35 +08:00
parent 4a247db4b7
commit ea7c851424
2 changed files with 18 additions and 12 deletions

View File

@@ -8,6 +8,7 @@
### 新特性
### Bug修复
* 【db】 解决ThreadLocalConnection多数据源被移除问题pr#66@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@@ -46,7 +46,8 @@ public enum ThreadLocalConnection {
GroupedConnection groupedConnection = threadLocal.get();
if (null != groupedConnection) {
groupedConnection.close(ds);
if(groupedConnection.removeAble()){
if (groupedConnection.isEmpty()) {
// 当所有分组都没有持有的连接时,移除这个分组连接
threadLocal.remove();
}
}
@@ -54,6 +55,8 @@ public enum ThreadLocalConnection {
/**
* 分组连接,根据不同的分组获取对应的连接,用于多数据源情况
*
* @author Looly
*/
public static class GroupedConnection {
@@ -101,11 +104,13 @@ public enum ThreadLocalConnection {
}
/**
* 多数据源情况情况下判断是否能从上下文中删除
* @return
* 持有的连接是否为空
*
* @return 持有的连接是否为空
* @since 4.6.4
*/
public boolean removeAble(){
return connMap.size()==0;
public boolean isEmpty() {
return connMap.isEmpty();
}
}
}