From c10ee3de2b24e90f706cc38dd377f4c66f205518 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Wed, 5 Nov 2025 01:13:56 +0000 Subject: [PATCH] [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 --- connection.go | 14 ++++++++++---- connector.go | 9 +++++---- errors/errors.go | 7 +++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/connection.go b/connection.go index 93de20e8..398e557a 100644 --- a/connection.go +++ b/connection.go @@ -26,10 +26,16 @@ import ( ) type conn struct { - id string - cfg *config.Config - client cli_service.TCLIService - session *cli_service.TOpenSessionResp + id string + cfg *config.Config + client cli_service.TCLIService + session *cli_service.TOpenSessionResp + autoCommit bool // Cache autocommit state client-side (default: true) +} + +// tx implements driver.Tx for transaction support +type tx struct { + conn *conn } // Prepare prepares a statement with the query bound to this connection. diff --git a/connector.go b/connector.go index 53908b4c..c0ef12b3 100644 --- a/connector.go +++ b/connector.go @@ -67,10 +67,11 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) { } conn := &conn{ - id: client.SprintGuid(session.SessionHandle.GetSessionId().GUID), - cfg: c.cfg, - client: tclient, - session: session, + id: client.SprintGuid(session.SessionHandle.GetSessionId().GUID), + cfg: c.cfg, + client: tclient, + session: session, + autoCommit: true, // Initialize autocommit cache to true (default state) } log := logger.WithContext(conn.id, driverctx.CorrelationIdFromContext(ctx), "") diff --git a/errors/errors.go b/errors/errors.go index d6a19158..3a41dd09 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -17,6 +17,13 @@ const ( ErrParametersNotSupported = "query parameters are not supported by this server" ErrMixedNamedAndPositionalParameters = "named and positional parameters cannot be used simultaneously" + // Transaction errors + ErrTransactionBegin = "failed to begin transaction" + ErrTransactionCommit = "failed to commit transaction" + ErrTransactionRollback = "failed to rollback transaction" + ErrTransactionNested = "transaction already in progress" + ErrUnsupportedIsolation = "unsupported transaction isolation level" + // Request error messages (connection, authentication, network error) ErrCloseConnection = "failed to close connection" ErrThriftClient = "error initializing thrift client"