BeginReadWriteTransaction starts read-write transaction.
(ctx context.Context, isolation_level pb.TransactionOptions_IsolationLevel, priority pb.RequestOptions_Priority, tag string)
| 121 | |
| 122 | // BeginReadWriteTransaction starts read-write transaction. |
| 123 | func (s *Session) BeginReadWriteTransaction(ctx context.Context, isolation_level pb.TransactionOptions_IsolationLevel, priority pb.RequestOptions_Priority, tag string) error { |
| 124 | if s.InReadWriteTransaction() { |
| 125 | return errors.New("read-write transaction is already running") |
| 126 | } |
| 127 | |
| 128 | // Use session's priority if transaction priority is not set. |
| 129 | if priority == pb.RequestOptions_PRIORITY_UNSPECIFIED { |
| 130 | priority = s.defaultPriority |
| 131 | } |
| 132 | |
| 133 | opts := spanner.TransactionOptions{ |
| 134 | CommitOptions: spanner.CommitOptions{ReturnCommitStats: true}, |
| 135 | CommitPriority: priority, |
| 136 | IsolationLevel: isolation_level, |
| 137 | TransactionTag: tag, |
| 138 | } |
| 139 | txn, err := spanner.NewReadWriteStmtBasedTransactionWithOptions(ctx, s.client, opts) |
| 140 | if err != nil { |
| 141 | return err |
| 142 | } |
| 143 | s.tc = &transactionContext{ |
| 144 | tag: tag, |
| 145 | priority: priority, |
| 146 | rwTxn: txn, |
| 147 | } |
| 148 | return nil |
| 149 | } |
| 150 | |
| 151 | // CommitReadWriteTransaction commits read-write transaction and returns commit timestamp if successful. |
| 152 | func (s *Session) CommitReadWriteTransaction(ctx context.Context) (spanner.CommitResponse, error) { |