@@ -6,24 +6,27 @@ import (
66 "fmt"
77
88 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
9+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
910 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1011 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/badconn"
1112 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/isolation"
1213 "github.com/ydb-platform/ydb-go-sdk/v3/table"
1314 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
1415)
1516
16- type tx struct {
17+ type transaction struct {
18+ tx.Identifier
19+
1720 conn * conn
1821 ctx context.Context //nolint:containedctx
1922 tx table.Transaction
2023}
2124
2225var (
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 {}
2730)
2831
2932func (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
4043 if err != nil {
4144 return nil , xerrors .WithStackTrace (err )
4245 }
43- transaction , err := c .session .BeginTransaction (ctx , table .TxSettings (txc ))
46+ nativeTx , err := c .session .BeginTransaction (ctx , table .TxSettings (txc ))
4447 if err != nil {
4548 return nil , badconn .Map (xerrors .WithStackTrace (err ))
4649 }
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 ,
5155 }
5256
5357 return c .currentTx , nil
5458}
5559
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 {
6161 if tx .conn .currentTx == tx {
6262 return nil
6363 }
@@ -72,11 +72,11 @@ func (tx *tx) checkTxState() error {
7272 )
7373}
7474
75- func (tx * tx ) Commit () (finalErr error ) {
75+ func (tx * transaction ) Commit () (finalErr error ) {
7676 var (
7777 ctx = tx .ctx
7878 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" ),
8080 tx ,
8181 )
8282 )
@@ -96,11 +96,11 @@ func (tx *tx) Commit() (finalErr error) {
9696 return nil
9797}
9898
99- func (tx * tx ) Rollback () (finalErr error ) {
99+ func (tx * transaction ) Rollback () (finalErr error ) {
100100 var (
101101 ctx = tx .ctx
102102 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" ),
104104 tx ,
105105 )
106106 )
@@ -121,11 +121,11 @@ func (tx *tx) Rollback() (finalErr error) {
121121 return err
122122}
123123
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 ) (
125125 _ driver.Rows , finalErr error ,
126126) {
127127 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" ),
129129 tx .ctx , tx , query ,
130130 )
131131 defer func () {
@@ -163,11 +163,11 @@ func (tx *tx) QueryContext(ctx context.Context, query string, args []driver.Name
163163 }, nil
164164}
165165
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 ) (
167167 _ driver.Result , finalErr error ,
168168) {
169169 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" ),
171171 tx .ctx , tx , query ,
172172 )
173173 defer func () {
@@ -199,9 +199,9 @@ func (tx *tx) ExecContext(ctx context.Context, query string, args []driver.Named
199199 return resultNoRows {}, nil
200200}
201201
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 ) {
203203 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" ),
205205 tx .ctx , tx , query ,
206206 )
207207 defer func () {
0 commit comments