Skip to content

Commit

Permalink
事务传播行为,未添加注解的方法加入上一个事务
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed May 12, 2019
1 parent 167120a commit 6fa2c9e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
8 changes: 8 additions & 0 deletions LocalSession.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ func (it *LocalSession) Begin(p *tx.Propagation) error {
return nil
}

func (it *LocalSession)LastPROPAGATION () *tx.Propagation{
if it.txStack.Len()!=0{
var _,pr=it.txStack.Last()
return pr
}
return nil
}

func (it *LocalSession) Close() {
if it.logSystem != nil {
it.logSystem.Println([]byte("[GoMybatis] ["+it.Id()+"] Close session"))
Expand Down
6 changes: 4 additions & 2 deletions SessionFactory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package GoMybatis

import "sync"
import (
"sync"
)

type SessionFactory struct {
Engine SessionEngine
Expand Down Expand Up @@ -68,4 +70,4 @@ func (it *SessionFactory) CloseAll(id string) {
}
return true
})
}
}
4 changes: 4 additions & 0 deletions SessionFactorySession.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func (it *SessionFactorySession) Close() {
it.Factory.SessionMap.Delete(id)
}
}

func (it *SessionFactorySession) LastPROPAGATION () *tx.Propagation{
return it.Session.LastPROPAGATION()
}
1 change: 1 addition & 0 deletions SqlEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Session interface {
Commit() error
Begin(p *tx.Propagation) error
Close()
LastPROPAGATION () *tx.Propagation
}

//产生session的引擎
Expand Down
14 changes: 11 additions & 3 deletions TransactionAspectSupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ func AopProxyServiceValue(service reflect.Value, engine SessionEngine) {
//压入map
engine.GoroutineSessionMap().Put(goroutineID, session)
}
var err = session.Begin(&propagation)
if err != nil {
panic(err)
if !haveTx {
var err = session.Begin(session.LastPROPAGATION())
if err != nil {
panic(err)
}
}else{
var err = session.Begin(&propagation)
if err != nil {
panic(err)
}
}

var nativeImplResult = doNativeMethod(funcField, arg, nativeImplFunc, session, engine.Log())
if !haveRollBackType(nativeImplResult, rollbackTag) {
var err = session.Commit()
Expand Down

0 comments on commit 6fa2c9e

Please sign in to comment.