This repository has been archived by the owner on Jan 4, 2020. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
原事务方法不支持如下写法
原因是
Model::startTrans()
方法会自动执行一次commit
,这样会导致上面嵌套写法的事务在中间被强制提交 ,而之后的commit
以及rollback
全部无效,主要是rollback的失效会导致严重的问题。改进想法:
M()->startTrans();
不自动提交,这样只会transTimes+1
,然后 commit 和 rollback 都检测transTimes == 1
如果是的话就执行 提交或回滚,否则只将 transTimes -1 ,唯一的要求外层需要检测内层返回值或异常,如果不成功外层也要执行 rollback 确保正常回滚。例子: