Skip to content

Commit

Permalink
rename field
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Mar 15, 2020
1 parent 4b251e3 commit f98cdc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions GoMybatisDataSourceRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
//动态数据源路由
type GoMybatisDataSourceRouter struct {
driverLinkDBMap map[string]*sql.DB // map[driverLink]*DB
driverTypeUrlMap map[string]string // map[driverType]Url
driverLinkUrlMap map[string]string // map[driverLink]Url
routerFunc func(mapperName string) *string
}

Expand All @@ -20,14 +20,14 @@ func (it GoMybatisDataSourceRouter) New(routerFunc func(mapperName string) *stri
}
}
it.driverLinkDBMap = make(map[string]*sql.DB)
it.driverTypeUrlMap = make(map[string]string)
it.driverLinkUrlMap = make(map[string]string)
it.routerFunc = routerFunc
return it
}

func (it *GoMybatisDataSourceRouter) SetDB(driverType string, driverLink string, db *sql.DB) {
it.driverLinkDBMap[driverLink] = db
it.driverTypeUrlMap[driverLink] = driverType
it.driverLinkUrlMap[driverLink] = driverType
}

func (it *GoMybatisDataSourceRouter) Router(mapperName string, engine SessionEngine) (Session, error) {
Expand All @@ -52,11 +52,11 @@ func (it *GoMybatisDataSourceRouter) Router(mapperName string, engine SessionEng
if db == nil {
return nil, utils.NewError("GoMybatisDataSourceRouter", "router not find datasource opened ! do you forget invoke GoMybatis.GoMybatisEngine{}.New().Open(\"driverName\", Uri)?")
}
var url = ""
var driverLink = ""
if key != nil {
url = *key
driverLink = *key
}
var local = LocalSession{}.New(it.driverTypeUrlMap[url], url, db, engine.Log())
var local = LocalSession{}.New(it.driverLinkUrlMap[driverLink], driverLink, db, engine.Log())
var session = Session(&local)
return session, nil
}
Expand Down
28 changes: 14 additions & 14 deletions LocalSession.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
//本地直连session
type LocalSession struct {
SessionId string
driver string
url string
driverType string
driverLink string
db *sql.DB
stmt *sql.Stmt
txStack tx.TxStack
Expand All @@ -24,14 +24,14 @@ type LocalSession struct {
logSystem Log
}

func (it LocalSession) New(driver string, url string, db *sql.DB, logSystem Log) LocalSession {
func (it LocalSession) New(driverType string, driverLink string, db *sql.DB, logSystem Log) LocalSession {
return LocalSession{
SessionId: utils.CreateUUID(),
db: db,
txStack: tx.TxStack{}.New(),
driver: driver,
url: url,
logSystem: logSystem,
SessionId: utils.CreateUUID(),
db: db,
txStack: tx.TxStack{}.New(),
driverType: driverType,
driverLink: driverLink,
logSystem: logSystem,
}
}

Expand Down Expand Up @@ -189,23 +189,23 @@ func (it *LocalSession) Begin(p *tx.Propagation) error {
//stop old tx
//}
//new session(tx)
var db, e = sql.Open(it.driver, it.url)
var db, e = sql.Open(it.driverType, it.driverLink)
if e != nil {
return e
}
var sess = LocalSession{}.New(it.driver, it.url, db, it.logSystem) //same PROPAGATION_REQUIRES_NEW
var sess = LocalSession{}.New(it.driverType, it.driverLink, db, it.logSystem) //same PROPAGATION_REQUIRES_NEW
it.newLocalSession = &sess
break
case tx.PROPAGATION_NOT_SUPPORTED:
//if it.txStack.Len() > 0 {
//stop old tx
//}
//new session( no tx)
var db, e = sql.Open(it.driver, it.url)
var db, e = sql.Open(it.driverType, it.driverLink)
if e != nil {
return e
}
var sess = LocalSession{}.New(it.driver, it.url, db, it.logSystem)
var sess = LocalSession{}.New(it.driverType, it.driverLink, db, it.logSystem)
it.newLocalSession = &sess
break
case tx.PROPAGATION_NEVER: //END
Expand Down Expand Up @@ -433,7 +433,7 @@ func (it *LocalSession) ExecPrepare(sqlPrepare string, args ...interface{}) (*Re
}

func (it *LocalSession) StmtConvert() (stmt.StmtIndexConvert, error) {
return stmt.BuildStmtConvert(it.driver)
return stmt.BuildStmtConvert(it.driverType)
}

func (it *LocalSession) dbErrorPack(e error) error {
Expand Down

0 comments on commit f98cdc5

Please sign in to comment.