Skip to content

Commit c10ee3d

Browse files
committed
[PECOBLR-1156] Add foundational structures for transaction support
Add core infrastructure for Multi-Statement Transaction (MST) support: - Add autoCommit bool field to conn struct for client-side state caching - Create tx struct implementing driver.Tx interface - Add transaction error constants (Begin, Commit, Rollback, Nested, UnsupportedIsolation) - Initialize autoCommit to true in connector (default state) This implements the foundational structures defined in the MST design document, following the JDBC implementation pattern with client-side autocommit caching. Part of Epic: PECOBLR-1144 (MST Support in GoLang driver) Design: DESIGN_MULTI_STATEMENT_TRANSACTIONS.md Signed-off-by: Gopal Lal <[email protected]>
1 parent c7243d0 commit c10ee3d

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

connection.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ import (
2626
)
2727

2828
type conn struct {
29-
id string
30-
cfg *config.Config
31-
client cli_service.TCLIService
32-
session *cli_service.TOpenSessionResp
29+
id string
30+
cfg *config.Config
31+
client cli_service.TCLIService
32+
session *cli_service.TOpenSessionResp
33+
autoCommit bool // Cache autocommit state client-side (default: true)
34+
}
35+
36+
// tx implements driver.Tx for transaction support
37+
type tx struct {
38+
conn *conn
3339
}
3440

3541
// Prepare prepares a statement with the query bound to this connection.

connector.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
6767
}
6868

6969
conn := &conn{
70-
id: client.SprintGuid(session.SessionHandle.GetSessionId().GUID),
71-
cfg: c.cfg,
72-
client: tclient,
73-
session: session,
70+
id: client.SprintGuid(session.SessionHandle.GetSessionId().GUID),
71+
cfg: c.cfg,
72+
client: tclient,
73+
session: session,
74+
autoCommit: true, // Initialize autocommit cache to true (default state)
7475
}
7576
log := logger.WithContext(conn.id, driverctx.CorrelationIdFromContext(ctx), "")
7677

errors/errors.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const (
1717
ErrParametersNotSupported = "query parameters are not supported by this server"
1818
ErrMixedNamedAndPositionalParameters = "named and positional parameters cannot be used simultaneously"
1919

20+
// Transaction errors
21+
ErrTransactionBegin = "failed to begin transaction"
22+
ErrTransactionCommit = "failed to commit transaction"
23+
ErrTransactionRollback = "failed to rollback transaction"
24+
ErrTransactionNested = "transaction already in progress"
25+
ErrUnsupportedIsolation = "unsupported transaction isolation level"
26+
2027
// Request error messages (connection, authentication, network error)
2128
ErrCloseConnection = "failed to close connection"
2229
ErrThriftClient = "error initializing thrift client"

0 commit comments

Comments
 (0)