[#1291] added condition to switch between the db pools in case of dry submit
This commit is contained in:
parent
7d7d20744e
commit
a43713ce14
|
@ -675,9 +675,16 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the default app.Dao().ConcurrentDB() to prevent changing the transaction form.Dao
|
var dryDao *daos.Dao
|
||||||
// and causing "transaction has already been committed or rolled back" error
|
if form.dao.ConcurrentDB() == form.dao.NonconcurrentDB() {
|
||||||
dryDao := daos.New(form.app.Dao().ConcurrentDB())
|
// it is already in a transaction and therefore use the app concurrent db pool
|
||||||
|
// to prevent "transaction has already been committed or rolled back" error
|
||||||
|
dryDao = daos.New(form.app.Dao().ConcurrentDB())
|
||||||
|
} else {
|
||||||
|
// otherwise use the form noncurrent dao db pool
|
||||||
|
dryDao = daos.New(form.dao.NonconcurrentDB())
|
||||||
|
}
|
||||||
|
|
||||||
return dryDao.RunInTransaction(func(txDao *daos.Dao) error {
|
return dryDao.RunInTransaction(func(txDao *daos.Dao) error {
|
||||||
tx, ok := txDao.DB().(*dbx.Tx)
|
tx, ok := txDao.DB().(*dbx.Tx)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -685,11 +692,6 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
txDao.BeforeCreateFunc = nil
|
|
||||||
txDao.AfterCreateFunc = nil
|
|
||||||
txDao.BeforeUpdateFunc = nil
|
|
||||||
txDao.AfterUpdateFunc = nil
|
|
||||||
|
|
||||||
if err := txDao.SaveRecord(form.record); err != nil {
|
if err := txDao.SaveRecord(form.record); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue