Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
commit_options.h
Go to the documentation of this file.
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_OPTIONS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_OPTIONS_H
17 
18 #include "google/cloud/spanner/request_priority.h"
19 #include "google/cloud/spanner/version.h"
20 #include "absl/types/optional.h"
21 #include <string>
22 
23 namespace google {
24 namespace cloud {
25 namespace spanner {
26 inline namespace SPANNER_CLIENT_NS {
27 
28 /**
29  * Set options on calls to `spanner::Client::Commit()`.
30  *
31  * @par Example
32  * @snippet samples.cc commit-options
33  */
35  public:
36  /// Default options: no stats.
37  CommitOptions() = default;
38 
39  /// Set whether the `CommitResult` should contain `CommitStats`.
40  CommitOptions& set_return_stats(bool return_stats) {
41  return_stats_ = return_stats;
42  return *this;
43  }
44 
45  /// Whether the `CommitResult` should contain `CommitStats`.
46  bool return_stats() const { return return_stats_; }
47 
48  /// Set the priority of the `spanner::Client::Commit()` call.
50  absl::optional<RequestPriority> request_priority) {
51  request_priority_ = std::move(request_priority);
52  return *this;
53  }
54 
55  /// The priority of the `spanner::Client::Commit()` call.
56  absl::optional<RequestPriority> request_priority() const {
57  return request_priority_;
58  }
59 
60  /**
61  * Set the transaction tag for the `spanner::Client::Commit()` call.
62  * Ignored for the overload that already takes a `spanner::Transaction`.
63  */
65  absl::optional<std::string> transaction_tag) {
66  transaction_tag_ = std::move(transaction_tag);
67  return *this;
68  }
69 
70  /// The transaction tag for the `spanner::Client::Commit()` call.
71  absl::optional<std::string> const& transaction_tag() const {
72  return transaction_tag_;
73  }
74 
75  private:
76  // Note that CommitRequest.request_options.request_tag is ignored,
77  // so we do not even provide a mechanism to specify one.
78  bool return_stats_ = false;
79  absl::optional<RequestPriority> request_priority_;
80  absl::optional<std::string> transaction_tag_;
81 };
82 
83 } // namespace SPANNER_CLIENT_NS
84 } // namespace spanner
85 } // namespace cloud
86 } // namespace google
87 
88 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_OPTIONS_H