@@ -6,24 +6,27 @@ import (
6
6
"fmt"
7
7
8
8
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
9
+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
9
10
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
10
11
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/badconn"
11
12
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/isolation"
12
13
"github.com/ydb-platform/ydb-go-sdk/v3/table"
13
14
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
14
15
)
15
16
16
- type tx struct {
17
+ type transaction struct {
18
+ tx.Identifier
19
+
17
20
conn * conn
18
21
ctx context.Context //nolint:containedctx
19
22
tx table.Transaction
20
23
}
21
24
22
25
var (
23
- _ driver.Tx = & tx {}
24
- _ driver.ExecerContext = & tx {}
25
- _ driver.QueryerContext = & tx {}
26
- _ table. TransactionIdentifier = & tx {}
26
+ _ driver.Tx = & transaction {}
27
+ _ driver.ExecerContext = & transaction {}
28
+ _ driver.QueryerContext = & transaction {}
29
+ _ tx. Identifier = & transaction {}
27
30
)
28
31
29
32
func (c * conn ) beginTx (ctx context.Context , txOptions driver.TxOptions ) (currentTx , error ) {
@@ -40,24 +43,21 @@ func (c *conn) beginTx(ctx context.Context, txOptions driver.TxOptions) (current
40
43
if err != nil {
41
44
return nil , xerrors .WithStackTrace (err )
42
45
}
43
- transaction , err := c .session .BeginTransaction (ctx , table .TxSettings (txc ))
46
+ nativeTx , err := c .session .BeginTransaction (ctx , table .TxSettings (txc ))
44
47
if err != nil {
45
48
return nil , badconn .Map (xerrors .WithStackTrace (err ))
46
49
}
47
- c .currentTx = & tx {
48
- conn : c ,
49
- ctx : ctx ,
50
- tx : transaction ,
50
+ c .currentTx = & transaction {
51
+ Identifier : tx .ID (nativeTx .ID ()),
52
+ conn : c ,
53
+ ctx : ctx ,
54
+ tx : nativeTx ,
51
55
}
52
56
53
57
return c .currentTx , nil
54
58
}
55
59
56
- func (tx * tx ) ID () string {
57
- return tx .tx .ID ()
58
- }
59
-
60
- func (tx * tx ) checkTxState () error {
60
+ func (tx * transaction ) checkTxState () error {
61
61
if tx .conn .currentTx == tx {
62
62
return nil
63
63
}
@@ -72,11 +72,11 @@ func (tx *tx) checkTxState() error {
72
72
)
73
73
}
74
74
75
- func (tx * tx ) Commit () (finalErr error ) {
75
+ func (tx * transaction ) Commit () (finalErr error ) {
76
76
var (
77
77
ctx = tx .ctx
78
78
onDone = trace .DatabaseSQLOnTxCommit (tx .conn .trace , & ctx ,
79
- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx ).Commit" ),
79
+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*transaction ).Commit" ),
80
80
tx ,
81
81
)
82
82
)
@@ -96,11 +96,11 @@ func (tx *tx) Commit() (finalErr error) {
96
96
return nil
97
97
}
98
98
99
- func (tx * tx ) Rollback () (finalErr error ) {
99
+ func (tx * transaction ) Rollback () (finalErr error ) {
100
100
var (
101
101
ctx = tx .ctx
102
102
onDone = trace .DatabaseSQLOnTxRollback (tx .conn .trace , & ctx ,
103
- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx ).Rollback" ),
103
+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*transaction ).Rollback" ),
104
104
tx ,
105
105
)
106
106
)
@@ -121,11 +121,11 @@ func (tx *tx) Rollback() (finalErr error) {
121
121
return err
122
122
}
123
123
124
- func (tx * tx ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (
124
+ func (tx * transaction ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (
125
125
_ driver.Rows , finalErr error ,
126
126
) {
127
127
onDone := trace .DatabaseSQLOnTxQuery (tx .conn .trace , & ctx ,
128
- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx ).QueryContext" ),
128
+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*transaction ).QueryContext" ),
129
129
tx .ctx , tx , query ,
130
130
)
131
131
defer func () {
@@ -163,11 +163,11 @@ func (tx *tx) QueryContext(ctx context.Context, query string, args []driver.Name
163
163
}, nil
164
164
}
165
165
166
- func (tx * tx ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (
166
+ func (tx * transaction ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (
167
167
_ driver.Result , finalErr error ,
168
168
) {
169
169
onDone := trace .DatabaseSQLOnTxExec (tx .conn .trace , & ctx ,
170
- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx ).ExecContext" ),
170
+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*transaction ).ExecContext" ),
171
171
tx .ctx , tx , query ,
172
172
)
173
173
defer func () {
@@ -199,9 +199,9 @@ func (tx *tx) ExecContext(ctx context.Context, query string, args []driver.Named
199
199
return resultNoRows {}, nil
200
200
}
201
201
202
- func (tx * tx ) PrepareContext (ctx context.Context , query string ) (_ driver.Stmt , finalErr error ) {
202
+ func (tx * transaction ) PrepareContext (ctx context.Context , query string ) (_ driver.Stmt , finalErr error ) {
203
203
onDone := trace .DatabaseSQLOnTxPrepare (tx .conn .trace , & ctx ,
204
- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx ).PrepareContext" ),
204
+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*transaction ).PrepareContext" ),
205
205
tx .ctx , tx , query ,
206
206
)
207
207
defer func () {
0 commit comments