@@ -225,7 +225,6 @@ type conn struct {
225225 resetForRetry bool
226226 commitResponse * spanner.CommitResponse
227227 database string
228- retryAborts bool
229228
230229 execSingleQuery func (ctx context.Context , c * spanner.Client , statement spanner.Statement , bound spanner.TimestampBound , options ExecOptions ) * spanner.RowIterator
231230 execSingleQueryTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , options ExecOptions ) (rowIterator , * spanner.CommitResponse , error )
@@ -236,25 +235,6 @@ type conn struct {
236235 state * connectionstate.ConnectionState
237236 // batch is the currently active DDL or DML batch on this connection.
238237 batch * batch
239- // autoBatchDml determines whether DML statements should automatically
240- // be batched and sent to Spanner when a non-DML statement is encountered.
241- autoBatchDml bool
242- // autoBatchDmlUpdateCount determines the update count that is returned for
243- // DML statements that are executed when autoBatchDml is true.
244- autoBatchDmlUpdateCount int64
245- // autoBatchDmlUpdateCountVerification enables/disables the verification
246- // that the update count that was returned for automatically batched DML
247- // statements was correct.
248- autoBatchDmlUpdateCountVerification bool
249-
250- // readOnlyStaleness is used for queries in autocommit mode and for read-only transactions.
251- readOnlyStaleness spanner.TimestampBound
252- // isolationLevel determines the default isolation level that is used for read/write
253- // transactions on this connection. This default is ignored if the BeginTx function is
254- // called with an isolation level other than sql.LevelDefault.
255- isolationLevel sql.IsolationLevel
256- // beginTransactionOption determines the default transactions start mode.
257- beginTransactionOption spanner.BeginTransactionOption
258238
259239 // execOptions are applied to the next statement or transaction that is executed
260240 // on this connection. It can also be set by passing it in as an argument to
@@ -289,7 +269,7 @@ func (c *conn) CommitResponse() (commitResponse *spanner.CommitResponse, err err
289269}
290270
291271func (c * conn ) RetryAbortsInternally () bool {
292- return c . retryAborts
272+ return propertyRetryAbortsInternally . GetValueOrDefault ( c . state )
293273}
294274
295275func (c * conn ) SetRetryAbortsInternally (retry bool ) error {
@@ -299,9 +279,13 @@ func (c *conn) SetRetryAbortsInternally(retry bool) error {
299279
300280func (c * conn ) setRetryAbortsInternally (retry bool ) (driver.Result , error ) {
301281 if c .inTransaction () {
302- return c .tx .setRetryAbortsInternally (retry )
282+ if _ , err := c .tx .setRetryAbortsInternally (retry ); err != nil {
283+ return nil , err
284+ }
285+ }
286+ if err := propertyRetryAbortsInternally .SetValue (c .state , retry , connectionstate .ContextUser ); err != nil {
287+ return nil , err
303288 }
304- c .retryAborts = retry
305289 return driver .ResultNoRows , nil
306290}
307291
@@ -325,7 +309,7 @@ func (c *conn) setAutocommitDMLMode(mode AutocommitDMLMode) (driver.Result, erro
325309}
326310
327311func (c * conn ) ReadOnlyStaleness () spanner.TimestampBound {
328- return c . readOnlyStaleness
312+ return propertyReadOnlyStaleness . GetValueOrDefault ( c . state )
329313}
330314
331315func (c * conn ) SetReadOnlyStaleness (staleness spanner.TimestampBound ) error {
@@ -334,17 +318,18 @@ func (c *conn) SetReadOnlyStaleness(staleness spanner.TimestampBound) error {
334318}
335319
336320func (c * conn ) setReadOnlyStaleness (staleness spanner.TimestampBound ) (driver.Result , error ) {
337- c .readOnlyStaleness = staleness
321+ if err := propertyReadOnlyStaleness .SetValue (c .state , staleness , connectionstate .ContextUser ); err != nil {
322+ return nil , err
323+ }
338324 return driver .ResultNoRows , nil
339325}
340326
341327func (c * conn ) IsolationLevel () sql.IsolationLevel {
342- return c . isolationLevel
328+ return propertyIsolationLevel . GetValueOrDefault ( c . state )
343329}
344330
345331func (c * conn ) SetIsolationLevel (level sql.IsolationLevel ) error {
346- c .isolationLevel = level
347- return nil
332+ return propertyIsolationLevel .SetValue (c .state , level , connectionstate .ContextUser )
348333}
349334
350335func (c * conn ) MaxCommitDelay () time.Duration {
@@ -419,30 +404,27 @@ func (c *conn) setStatementTag(statementTag string) (driver.Result, error) {
419404}
420405
421406func (c * conn ) AutoBatchDml () bool {
422- return c . autoBatchDml
407+ return propertyAutoBatchDml . GetValueOrDefault ( c . state )
423408}
424409
425410func (c * conn ) SetAutoBatchDml (autoBatch bool ) error {
426- c .autoBatchDml = autoBatch
427- return nil
411+ return propertyAutoBatchDml .SetValue (c .state , autoBatch , connectionstate .ContextUser )
428412}
429413
430414func (c * conn ) AutoBatchDmlUpdateCount () int64 {
431- return c . autoBatchDmlUpdateCount
415+ return propertyAutoBatchDmlUpdateCount . GetValueOrDefault ( c . state )
432416}
433417
434418func (c * conn ) SetAutoBatchDmlUpdateCount (updateCount int64 ) error {
435- c .autoBatchDmlUpdateCount = updateCount
436- return nil
419+ return propertyAutoBatchDmlUpdateCount .SetValue (c .state , updateCount , connectionstate .ContextUser )
437420}
438421
439422func (c * conn ) AutoBatchDmlUpdateCountVerification () bool {
440- return c . autoBatchDmlUpdateCountVerification
423+ return propertyAutoBatchDmlUpdateCountVerification . GetValueOrDefault ( c . state )
441424}
442425
443426func (c * conn ) SetAutoBatchDmlUpdateCountVerification (verify bool ) error {
444- c .autoBatchDmlUpdateCountVerification = verify
445- return nil
427+ return propertyAutoBatchDmlUpdateCountVerification .SetValue (c .state , verify , connectionstate .ContextUser )
446428}
447429
448430func (c * conn ) StartBatchDDL () error {
@@ -683,16 +665,8 @@ func (c *conn) ResetSession(_ context.Context) error {
683665 }
684666 c .commitResponse = nil
685667 c .batch = nil
686- c .autoBatchDml = c .connector .connectorConfig .AutoBatchDml
687- c .autoBatchDmlUpdateCount = c .connector .connectorConfig .AutoBatchDmlUpdateCount
688- c .autoBatchDmlUpdateCountVerification = ! c .connector .connectorConfig .DisableAutoBatchDmlUpdateCountVerification
689- c .retryAborts = c .connector .retryAbortsInternally
690- c .isolationLevel = c .connector .connectorConfig .IsolationLevel
691- c .beginTransactionOption = c .connector .connectorConfig .BeginTransactionOption
692668
693669 _ = c .state .Reset (connectionstate .ContextUser )
694- // TODO: Reset the following fields to the connector default
695- c .readOnlyStaleness = spanner.TimestampBound {}
696670 c .execOptions = ExecOptions {
697671 DecodeToNativeArrays : c .connector .connectorConfig .DecodeToNativeArrays ,
698672 }
@@ -817,7 +791,7 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions ExecO
817791 // The statement was either detected as being a query, or potentially not recognized at all.
818792 // In that case, just default to using a single-use read-only transaction and let Spanner
819793 // return an error if the statement is not suited for that type of transaction.
820- iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , c .readOnlyStaleness , execOptions )}
794+ iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , c .ReadOnlyStaleness () , execOptions )}
821795 }
822796 } else {
823797 if execOptions .PartitionedQueryOptions .PartitionQuery {
@@ -875,7 +849,7 @@ func (c *conn) execContext(ctx context.Context, query string, execOptions ExecOp
875849 }
876850
877851 // Start an automatic DML batch.
878- if c .autoBatchDml && ! c .inBatch () && c .inReadWriteTransaction () {
852+ if c .AutoBatchDml () && ! c .inBatch () && c .inReadWriteTransaction () {
879853 if _ , err := c .startBatchDML ( /* automatic = */ true ); err != nil {
880854 return nil , err
881855 }
@@ -964,19 +938,19 @@ func (c *conn) getTransactionOptions() ReadWriteTransactionOptions {
964938 }()
965939 txOpts := ReadWriteTransactionOptions {
966940 TransactionOptions : c .execOptions .TransactionOptions ,
967- DisableInternalRetries : ! c .retryAborts ,
941+ DisableInternalRetries : ! c .RetryAbortsInternally () ,
968942 }
969943 // Only use the default isolation level from the connection if the ExecOptions
970944 // did not contain a more specific isolation level.
971945 if txOpts .TransactionOptions .IsolationLevel == spannerpb .TransactionOptions_ISOLATION_LEVEL_UNSPECIFIED {
972946 // This should never really return an error, but we check just to be absolutely sure.
973- level , err := toProtoIsolationLevel (c .isolationLevel )
947+ level , err := toProtoIsolationLevel (c .IsolationLevel () )
974948 if err == nil {
975949 txOpts .TransactionOptions .IsolationLevel = level
976950 }
977951 }
978952 if txOpts .TransactionOptions .BeginTransactionOption == spanner .DefaultBeginTransaction {
979- txOpts .TransactionOptions .BeginTransactionOption = c .convertDefaultBeginTransactionOption (c . beginTransactionOption )
953+ txOpts .TransactionOptions .BeginTransactionOption = c .convertDefaultBeginTransactionOption (propertyBeginTransactionOption . GetValueOrDefault ( c . state ) )
980954 }
981955 return txOpts
982956}
@@ -992,7 +966,7 @@ func (c *conn) getReadOnlyTransactionOptions() ReadOnlyTransactionOptions {
992966 opts .BeginTransactionOption = c .convertDefaultBeginTransactionOption (opts .BeginTransactionOption )
993967 return opts
994968 }
995- return ReadOnlyTransactionOptions {TimestampBound : c .readOnlyStaleness , BeginTransactionOption : c .convertDefaultBeginTransactionOption (c . beginTransactionOption )}
969+ return ReadOnlyTransactionOptions {TimestampBound : c .ReadOnlyStaleness () , BeginTransactionOption : c .convertDefaultBeginTransactionOption (propertyBeginTransactionOption . GetValueOrDefault ( c . state ) )}
996970}
997971
998972func (c * conn ) withTempBatchReadOnlyTransactionOptions (options * BatchReadOnlyTransactionOptions ) {
@@ -1004,7 +978,7 @@ func (c *conn) getBatchReadOnlyTransactionOptions() BatchReadOnlyTransactionOpti
1004978 defer func () { c .tempBatchReadOnlyTransactionOptions = nil }()
1005979 return * c .tempBatchReadOnlyTransactionOptions
1006980 }
1007- return BatchReadOnlyTransactionOptions {TimestampBound : c .readOnlyStaleness }
981+ return BatchReadOnlyTransactionOptions {TimestampBound : c .ReadOnlyStaleness () }
1008982}
1009983
1010984func (c * conn ) Begin () (driver.Tx , error ) {
@@ -1134,10 +1108,10 @@ func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
11341108
11351109func (c * conn ) convertDefaultBeginTransactionOption (opt spanner.BeginTransactionOption ) spanner.BeginTransactionOption {
11361110 if opt == spanner .DefaultBeginTransaction {
1137- if c . beginTransactionOption == spanner .DefaultBeginTransaction {
1111+ if propertyBeginTransactionOption . GetValueOrDefault ( c . state ) == spanner .DefaultBeginTransaction {
11381112 return spanner .InlinedBeginTransaction
11391113 }
1140- return c . beginTransactionOption
1114+ return propertyBeginTransactionOption . GetValueOrDefault ( c . state )
11411115 }
11421116 return opt
11431117}
0 commit comments