Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
commit_options.h
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
24namespace google {
25namespace cloud {
26namespace spanner {
27GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
28
29/**
30 * Set options on calls to `spanner::Client::Commit()`.
31 *
32 * @par Example
33 * @snippet samples.cc commit-options
34 */
35class CommitOptions {
36 public:
37 /// Default options: no stats.
38 CommitOptions() = default;
39
40 /**
41 * Constructs from 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
96GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
97} // namespace spanner
98} // namespace cloud
99} // namespace google
100
101#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_OPTIONS_H
Set options on calls to spanner::Client::Commit().
Definition: commit_options.h:35
CommitOptions & set_return_stats(bool return_stats)
Set whether the CommitResult should contain CommitStats.
Definition: commit_options.h:53
CommitOptions & set_transaction_tag(absl::optional< std::string > transaction_tag)
Set the transaction tag for the spanner::Client::Commit() call.
Definition: commit_options.h:77
operator Options() const
Converts to the new, recommended way to represent options of all varieties, google::cloud::Options.
CommitOptions()=default
Default options: no stats.
bool return_stats() const
Whether the CommitResult should contain CommitStats.
Definition: commit_options.h:59
CommitOptions(Options const &opts)
Constructs from the new, recommended way to represent options of all varieties, google::cloud::Option...
absl::optional< RequestPriority > request_priority() const
The priority of the spanner::Client::Commit() call.
Definition: commit_options.h:69
absl::optional< std::string > const & transaction_tag() const
The transaction tag for the spanner::Client::Commit() call.
Definition: commit_options.h:84
CommitOptions & set_request_priority(absl::optional< RequestPriority > request_priority)
Set the priority of the spanner::Client::Commit() call.
Definition: commit_options.h:62
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
RequestPriority
Definition: request_priority.h:26