From dc6cb274ee3a8896c54293288dfc9aafe1213503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 5 Oct 2024 00:58:15 +0200 Subject: [PATCH] v0.0.519 --- goextVersion.go | 4 ++-- sq/database.go | 2 +- sq/listener.go | 32 +++++++++++++++++++------------- sq/transaction.go | 36 +++++++++++++++++++----------------- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index b9eb3f1..f111e21 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.518" +const GoextVersion = "0.0.519" -const GoextVersionTimestamp = "2024-10-05T00:45:55+0200" +const GoextVersionTimestamp = "2024-10-05T00:58:15+0200" diff --git a/sq/database.go b/sq/database.go index bf3ff9c..ed0e067 100644 --- a/sq/database.go +++ b/sq/database.go @@ -172,7 +172,7 @@ func (db *database) BeginTransaction(ctx context.Context, iso sql.IsolationLevel return nil, exerr.Wrap(err, "Failed to start sql transaction").Build() } - return NewTransaction(xtx, txid, db), nil + return newTransaction(ctx, xtx, txid, db), nil } func (db *database) Exit() error { diff --git a/sq/listener.go b/sq/listener.go index eada73d..e89a668 100644 --- a/sq/listener.go +++ b/sq/listener.go @@ -9,12 +9,15 @@ type PrePingMeta struct { } type PreTxBeginMeta struct { + ConstructorContext context.Context } type PreTxCommitMeta struct { + ConstructorContext context.Context } type PreTxRollbackMeta struct { + ConstructorContext context.Context } type PreQueryMeta struct { @@ -30,25 +33,28 @@ type PostPingMeta struct { } type PostTxBeginMeta struct { - Init time.Time - Start time.Time - End time.Time + ConstructorContext context.Context + Init time.Time + Start time.Time + End time.Time } type PostTxCommitMeta struct { - Init time.Time - Start time.Time - End time.Time - ExecCounter int - QueryCounter int + ConstructorContext context.Context + Init time.Time + Start time.Time + End time.Time + ExecCounter int + QueryCounter int } type PostTxRollbackMeta struct { - Init time.Time - Start time.Time - End time.Time - ExecCounter int - QueryCounter int + ConstructorContext context.Context + Init time.Time + Start time.Time + End time.Time + ExecCounter int + QueryCounter int } type PostQueryMeta struct { diff --git a/sq/transaction.go b/sq/transaction.go index 887c35f..d643ccf 100644 --- a/sq/transaction.go +++ b/sq/transaction.go @@ -27,22 +27,24 @@ type Tx interface { } type transaction struct { - tx *sqlx.Tx - id uint16 - status TxStatus - execCtr int - queryCtr int - db *database + constructorContext context.Context + tx *sqlx.Tx + id uint16 + status TxStatus + execCtr int + queryCtr int + db *database } -func NewTransaction(xtx *sqlx.Tx, txid uint16, db *database) Tx { +func newTransaction(ctx context.Context, xtx *sqlx.Tx, txid uint16, db *database) Tx { return &transaction{ - tx: xtx, - id: txid, - status: TxStatusInitial, - execCtr: 0, - queryCtr: 0, - db: db, + constructorContext: ctx, + tx: xtx, + id: txid, + status: TxStatusInitial, + execCtr: 0, + queryCtr: 0, + db: db, } } @@ -50,7 +52,7 @@ func (tx *transaction) Rollback() error { t0 := time.Now() - preMeta := PreTxRollbackMeta{} + preMeta := PreTxRollbackMeta{ConstructorContext: tx.constructorContext} for _, v := range tx.db.lstr { err := v.PreTxRollback(tx.id, preMeta) if err != nil { @@ -66,7 +68,7 @@ func (tx *transaction) Rollback() error { tx.status = TxStatusRollback } - postMeta := PostTxRollbackMeta{Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr} + postMeta := PostTxRollbackMeta{ConstructorContext: tx.constructorContext, Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr} for _, v := range tx.db.lstr { v.PostTxRollback(tx.id, result, postMeta) } @@ -78,7 +80,7 @@ func (tx *transaction) Commit() error { t0 := time.Now() - preMeta := PreTxCommitMeta{} + preMeta := PreTxCommitMeta{ConstructorContext: tx.constructorContext} for _, v := range tx.db.lstr { err := v.PreTxCommit(tx.id, preMeta) if err != nil { @@ -94,7 +96,7 @@ func (tx *transaction) Commit() error { tx.status = TxStatusComitted } - postMeta := PostTxCommitMeta{Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr} + postMeta := PostTxCommitMeta{ConstructorContext: tx.constructorContext, Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr} for _, v := range tx.db.lstr { v.PostTxCommit(tx.id, result, postMeta) }