Google Cloud Spanner C++ Client  2.1.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 // https://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 "google/cloud/options.h"
21 #include "absl/types/optional.h"
22 #include <string>
23 
24 namespace google {
25 namespace cloud {
26 namespace spanner {
28 
29 /**
30  * Set options on calls to `spanner::Client::Commit()`.
31  *
32  * @par Example
33  * @snippet samples.cc commit-options
34  */
36  public:
37  /// Default options: no stats.
38  CommitOptions() = default;
39 
40  /**
41  * Constructs from the the new, recommended way to represent options
42  * of all varieties, `google::cloud::Options`.
43  */
44  explicit CommitOptions(Options const& opts);
45 
46  /**
47  * Converts to the new, recommended way to represent options of all
48  * varieties, `google::cloud::Options`.
49  */
50  explicit operator Options() const;
51 
52  /// Set whether the `CommitResult` should contain `CommitStats`.
53  CommitOptions& set_return_stats(bool return_stats) {
54  return_stats_ = return_stats;
55  return *this;
56  }
57 
58  /// Whether the `CommitResult` should contain `CommitStats`.
59  bool return_stats() const { return return_stats_; }
60 
61  /// Set the priority of the `spanner::Client::Commit()` call.
63  absl::optional<RequestPriority> request_priority) {
64  request_priority_ = std::move(request_priority);
65  return *this;
66  }
67 
68  /// The priority of the `spanner::Client::Commit()` call.
69  absl::optional<RequestPriority> request_priority() const {
70  return request_priority_;
71  }
72 
73  /**
74  * Set the transaction tag for the `spanner::Client::Commit()` call.
75  * Ignored for the overload that already takes a `spanner::Transaction`.
76  */
78  absl::optional<std::string> transaction_tag) {
79  transaction_tag_ = std::move(transaction_tag);
80  return *this;
81  }
82 
83  /// The transaction tag for the `spanner::Client::Commit()` call.
84  absl::optional<std::string> const& transaction_tag() const {
85  return transaction_tag_;
86  }
87 
88  private:
89  // Note that CommitRequest.request_options.request_tag is ignored,
90  // so we do not even provide a mechanism to specify one.
91  bool return_stats_ = false;
92  absl::optional<RequestPriority> request_priority_;
93  absl::optional<std::string> transaction_tag_;
94 };
95 
97 } // namespace spanner
98 } // namespace cloud
99 } // namespace google
100 
101 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_OPTIONS_H