Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
4c218b89
Commit
4c218b89
authored
Aug 15, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
cb5e7729
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
8 deletions
+43
-8
State.go
getWay/State.go
+1
-4
MysqlClient.go
mysqlrym/MysqlClient.go
+42
-4
No files found.
getWay/State.go
View file @
4c218b89
...
...
@@ -6,8 +6,7 @@ type State int16
const
(
BusinessError
State
=
1001
OK
State
=
1000
Expire
State
=
1
-
iota
Illegal1
Illegal1
State
=
1
-
iota
Illegal2
Illegal3
Illegal4
...
...
@@ -24,8 +23,6 @@ func (t State) String() string {
return
"business error"
case
OK
:
return
"OK"
case
Expire
:
return
"expire request"
case
Illegal1
:
return
"illegal request(1)"
case
Illegal2
:
...
...
mysqlrym/MysqlClient.go
View file @
4c218b89
...
...
@@ -22,6 +22,8 @@ func TestLog() {
var
customerDb
*
gorm
.
DB
var
customerDbMap
sync
.
Map
var
gidNeedTX
sync
.
Map
func
SetTx
()
{
...
...
@@ -30,18 +32,24 @@ func SetTx() {
}
func
GetDb
()
*
gorm
.
DB
{
return
getDb
(
customerDb
)
return
getDb
(
customerDb
,
&
customerDbMap
)
}
func
getDb
(
db
*
gorm
.
DB
)
*
gorm
.
DB
{
func
getDb
(
db
*
gorm
.
DB
,
dbMap
*
sync
.
Map
)
*
gorm
.
DB
{
gid
:=
util
.
GetGID
()
_
,
needTx
:=
gidNeedTX
.
Load
(
gid
)
if
needTx
{
cacheTx
,
ok
:=
dbMap
.
Load
(
gid
)
if
ok
{
return
cacheTx
.
(
*
gorm
.
DB
)
}
else
{
if
conf
.
LogShowSql
{
db
=
db
.
Debug
()
}
tx
:=
db
.
Begin
()
dbMap
.
Store
(
gid
,
tx
)
return
tx
}
}
else
{
if
conf
.
LogShowSql
{
db
=
db
.
Debug
()
...
...
@@ -51,11 +59,41 @@ func getDb(db *gorm.DB) *gorm.DB {
}
func
Rollback
()
{
customerDb
.
Rollback
()
gid
:=
util
.
GetGID
()
_
,
needTx
:=
gidNeedTX
.
Load
(
gid
)
if
needTx
{
rollbackTx
(
gid
,
&
customerDbMap
)
gidNeedTX
.
Delete
(
gid
)
}
}
func
Commit
()
{
customerDb
.
Commit
()
gid
:=
util
.
GetGID
()
_
,
needTx
:=
gidNeedTX
.
Load
(
gid
)
if
needTx
{
commitTx
(
gid
,
&
customerDbMap
)
gidNeedTX
.
Delete
(
gid
)
}
}
func
rollbackTx
(
gid
uint64
,
dbMap
*
sync
.
Map
)
{
cacheTx
,
ok
:=
dbMap
.
Load
(
gid
)
if
ok
{
tx
:=
cacheTx
.
(
*
gorm
.
DB
)
tx
.
Rollback
()
dbMap
.
Delete
(
gid
)
}
}
func
commitTx
(
gid
uint64
,
dbMap
*
sync
.
Map
)
{
cacheTx
,
ok
:=
dbMap
.
Load
(
gid
)
if
ok
{
tx
:=
cacheTx
.
(
*
gorm
.
DB
)
tx
.
Commit
()
dbMap
.
Delete
(
gid
)
}
}
func
Init
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment