zoukankan      html  css  js  c++  java
  • SSM-MyBatis-09:Mybatis中SqlSession的close为什么能造成事务的回滚

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

    经过上几次的查找,笔者我就简单的说一下查找的思路,留给读者自己实践

    同样找到sqlsession的实现类,----DefaltSqlSession,找它的close方法

    public void close() {
            try {
                this.executor.close(this.isCommitOrRollbackRequired(false));
                this.closeCursors();
                this.dirty = false;
            } finally {
                ErrorContext.instance().reset();
            }
    
        }

    executor执行器的close方法里面的这个方法,传入false

    private boolean isCommitOrRollbackRequired(boolean force) {
            return !this.autoCommit && this.dirty || force;
        }

    根据上一篇博客写的,他们三个逻辑运算符的优先级  &&>||>!

    得到值为true

    看executor.close(boolean XXX)的方法,同样找他实现类BaseExecutor

    public void close(boolean forceRollback) {
            try {
                try {
                    this.rollback(forceRollback);
                } finally {
                    if(this.transaction != null) {
                        this.transaction.close();
                    }
    
                }
            } catch (SQLException var11) {
                log.warn("Unexpected exception on closing transaction.  Cause: " + var11);
            } finally {
                this.transaction = null;
                this.deferredLoads = null;
                this.localCache = null;
                this.localOutputParameterCache = null;
                this.closed = true;
            }
    
        }

    从头开始看,rollback(true)这一行

    public void rollback(boolean required) throws SQLException {
            if(!this.closed) {
                try {
                    this.clearLocalCache();
                    this.flushStatements(true);
                } finally {
                    if(required) {
                        this.transaction.rollback();
                    }
    
                }
            }
    
        }

    finally中是什么事物的回滚啊,这就真相大白

    SqlSession中的close在底层调用了事务的回滚的方法,当然会造成事务的回滚啊~~~~~~

  • 相关阅读:
    docker swarm 集群搭建和臫servoce对服务扩容
    docker 可视化 portainer
    docker Compose
    hadoop2 安装
    y的最大值最小值切割
    滑块图片拼接
    ast 对象还原
    babel/types is判断
    t.isLiteral()
    杂题集合
  • 原文地址:https://www.cnblogs.com/DawnCHENXI/p/8467447.html
Copyright © 2011-2022 走看看