------------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