1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 11:50:54 +00:00

do not judge tx status in txOrm

This commit is contained in:
jianzhiyao 2020-07-20 17:34:58 +08:00
parent aefe21b63a
commit 4aad313de7

View File

@ -530,7 +530,6 @@ func (o *orm) BeginWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions) (TxO
alias: o.alias, alias: o.alias,
db: &TxDB{tx: tx}, db: &TxDB{tx: tx},
}, },
isClosed: false,
} }
var taskTxOrm TxOrmer = _txOrm var taskTxOrm TxOrmer = _txOrm
@ -577,33 +576,15 @@ func (o *orm) DoTxWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions, task
type txOrm struct { type txOrm struct {
ormBase ormBase
isClosed bool
closeMutex sync.Mutex
} }
var _ TxOrmer = new(txOrm) var _ TxOrmer = new(txOrm)
func (t *txOrm) Commit() error { func (t *txOrm) Commit() error {
t.closeMutex.Lock()
defer t.closeMutex.Unlock()
if t.isClosed {
return ErrTxDone
}
t.isClosed = true
return t.db.(txEnder).Commit() return t.db.(txEnder).Commit()
} }
func (t *txOrm) Rollback() error { func (t *txOrm) Rollback() error {
t.closeMutex.Lock()
defer t.closeMutex.Unlock()
if t.isClosed {
return ErrTxDone
}
t.isClosed = true
return t.db.(txEnder).Rollback() return t.db.(txEnder).Rollback()
} }