Why does the commit method of sqlsession in Ssm-mybatis-08:mybatis cause things to be submitted

Source: Internet
Author: User

------------I do not have him, but the hand is ripe, humble and foolish, and eager to be hungry-------------

As the title shows, this small section discusses why Sqlsession commits cause things to be submitted

First look at Sqlsession's commit () He is an interface method, so go to his implementation class looking for (CTRL+H) Defaultsqlsession class to find his commit parameterless method, because we call is also his no argument method, look down

 Public voidcommit () { This. Commit (false); }     Public voidcommit (Boolean force) {Try {             This. Executor.commit ( This. iscommitorrollbackrequired (force));  This. Dirty =false; } Catch(Exception var6) {ThrowExceptionfactory.wrapexception ("Error committing transaction. Cause:"+VAR6, VAR6); } finally{errorcontext.instance (). reset (); }    }

Did you see it? He called his next parameter method, and passed in the parameter, and we made a note, forceis false

Dirty turns false in the executor's submission below, stating that the data is not dirty

Executor.commit (XXX) Executor of the submission, we look at the method inside, commit in the method parameters called the method and get the return value, look at the method inside, notice the value passed in to False

Private Boolean iscommitorrollbackrequired (Boolean force) {        return !  this. Dirty | | Force ;    }

This method, to be honest, looks a bit ignorant at one glance, but you know!     && | | Use priority, you can calculate the &&>| |                    >! The result is true for return.

The above this.dirty is in the last mentioned additions and deletions will call the Update method, the inside of the change to True

The above autocommit is created sqlsession when the early change to False,opensession method the bottom

Next look at the above Executor.commit (XXX) method, he is the executor executor interface, find his implementation class Baseexecutor class of Commit with a Boolean parameter method

  Public voidcommit (Boolean required) throws SQLException {if( This. Closed) {            Throw NewExecutorexception ("cannot commit, transaction is already closed"); } Else {             This. Clearlocalcache ();  This. flushstatements (); if(required) { This. Transaction.commit (); }        }   }

There are some don't need attention, but simply mention a mouth, Clearlocalcache () Clean up the cache, flushstatements refresh parameters

The final level of attention is because if the required is passed in the parameter, which has been interpreted to be true, so he executes the next line of code is Transaction.commit (), Oh, transaction's English name is called the Thing

End of sentence:Session.commit () finally dispatched to the submission of things, This.transaction.commit ()

Why does the commit method of sqlsession in Ssm-mybatis-08:mybatis cause things to be submitted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.