fix:主事务内多个嵌套事务,导致影响主事务提交|回滚 (#533)
Co-authored-by: zhangpeng <xinniankuailezp@163.com>
This commit is contained in:
parent
a37ed90c80
commit
b83572ca2d
@ -117,7 +117,7 @@ public class ConnectionFactory {
|
||||
Iterator<SavePointHolder> iterator = savePointHolders.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
SavePointHolder savePointHolder = iterator.next();
|
||||
if (savePointHolder.releaseSavepoint() <= 0) {
|
||||
if (savePointHolder.releaseSavepoint()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ public class ConnectionFactory {
|
||||
SavePointHolder savePointHolder = iterator.next();
|
||||
ConnectionProxy connectionProxy = savePointHolder.getConnectionProxy();
|
||||
markedConnectionProxy.add(connectionProxy);
|
||||
if (savePointHolder.rollbackSavePoint() <= 0) {
|
||||
if (savePointHolder.rollbackSavePoint()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@ -221,15 +221,7 @@ public class ConnectionFactory {
|
||||
public static boolean hasSavepoint(String xid) {
|
||||
Map<String, List<SavePointHolder>> savePointMap = SAVEPOINT_CONNECTION_HOLDER.get();
|
||||
List<SavePointHolder> savePointHolders = savePointMap.get(xid);
|
||||
if (savePointHolders == null || savePointHolders.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (SavePointHolder savePointHolder : savePointHolders) {
|
||||
if (!CollectionUtils.isEmpty(savePointHolder.getSavePoints())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return !CollectionUtils.isEmpty(savePointHolders);
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
package com.baomidou.dynamic.datasource.tx;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLTransientConnectionException;
|
||||
import java.sql.Savepoint;
|
||||
@ -27,6 +29,7 @@ import java.util.List;
|
||||
*
|
||||
* @author zp
|
||||
*/
|
||||
@Slf4j
|
||||
public class SavePointHolder {
|
||||
/**
|
||||
* savepoint name prefix
|
||||
@ -72,14 +75,15 @@ public class SavePointHolder {
|
||||
* @return savepoint index
|
||||
* @throws SQLException SQLException
|
||||
*/
|
||||
public int releaseSavepoint() throws SQLException {
|
||||
public boolean releaseSavepoint() throws SQLException {
|
||||
Savepoint savepoint = savepoints.pollLast();
|
||||
if (savepoint != null) {
|
||||
connectionProxy.releaseSavepoint(savepoint);
|
||||
String savepointName = savepoint.getSavepointName();
|
||||
return Integer.parseInt(savepointName.substring(SAVEPOINT_NAME_PREFIX.length()));
|
||||
log.info("dynamic-datasource releaseSavepoint [{}]", savepointName);
|
||||
return savepoints.isEmpty();
|
||||
}
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,14 +92,15 @@ public class SavePointHolder {
|
||||
* @return savepoint index
|
||||
* @throws SQLException SQLException
|
||||
*/
|
||||
public int rollbackSavePoint() throws SQLException {
|
||||
public boolean rollbackSavePoint() throws SQLException {
|
||||
Savepoint savepoint = savepoints.pollLast();
|
||||
if (savepoint != null) {
|
||||
connectionProxy.rollback(savepoint);
|
||||
String savepointName = savepoint.getSavepointName();
|
||||
return Integer.parseInt(savepointName.substring(SAVEPOINT_NAME_PREFIX.length()));
|
||||
log.info("dynamic-datasource rollbackSavePoint [{}]", savepointName);
|
||||
return savepoints.isEmpty();
|
||||
}
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user