Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
update_instance_request_builder.h
1// Copyright 2019 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_UPDATE_INSTANCE_REQUEST_BUILDER_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
17
18#include "google/cloud/spanner/instance.h"
19#include "google/cloud/spanner/version.h"
20#include <google/protobuf/util/field_mask_util.h>
21#include <google/protobuf/util/message_differencer.h>
22#include <google/spanner/admin/instance/v1/spanner_instance_admin.pb.h>
23#include <map>
24#include <string>
25
26namespace google {
27namespace cloud {
28namespace spanner {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30
31/**
32 * UpdateInstanceRequestBuilder is a builder class for
33 * `google::spanner::admin::instance::v1::UpdateInstanceRequest`
34 *
35 * This is useful when calling
36 * `google::cloud::spanner::InstanceAdminClient::UpdateInstance()` function.
37 *
38 * @par Example
39 * @snippet samples.cc update-instance
40 */
42 public:
43 /**
44 * Constructs a `UpdateInstanceRequestBuilder`.
45 */
47
48 // Copy and move.
52 default;
54 default;
55
56 friend bool operator==(UpdateInstanceRequestBuilder const& a,
57 UpdateInstanceRequestBuilder const& b) noexcept {
58 return google::protobuf::util::MessageDifferencer::Equivalent(a.request_,
59 b.request_);
60 }
61 friend bool operator!=(UpdateInstanceRequestBuilder const& a,
62 UpdateInstanceRequestBuilder const& b) noexcept {
63 return !(a == b);
64 }
65
66 explicit UpdateInstanceRequestBuilder(std::string instance_name) {
67 request_.mutable_instance()->set_name(std::move(instance_name));
68 }
69 explicit UpdateInstanceRequestBuilder(Instance const& in) {
70 request_.mutable_instance()->set_name(in.FullName());
71 }
72
73 /**
74 * Constructs `UpdateInstanceRequestBuilder` with
75 * google::spanner::admin::instance::v1::Instance. It's particularly useful
76 * if you want to add some labels to existing instances.
77 */
79 google::spanner::admin::instance::v1::Instance in) {
80 *request_.mutable_instance() = std::move(in);
81 }
82
83 UpdateInstanceRequestBuilder& SetName(std::string name) & {
84 request_.mutable_instance()->set_name(std::move(name));
85 return *this;
86 }
87 UpdateInstanceRequestBuilder&& SetName(std::string name) && {
88 request_.mutable_instance()->set_name(std::move(name));
89 return std::move(*this);
90 }
91 UpdateInstanceRequestBuilder& SetDisplayName(std::string display_name) & {
92 SetDisplayNameImpl(std::move(display_name));
93 return *this;
94 }
95 UpdateInstanceRequestBuilder&& SetDisplayName(std::string display_name) && {
96 SetDisplayNameImpl(std::move(display_name));
97 return std::move(*this);
98 }
100 SetNodeCountImpl(node_count);
101 return *this;
102 }
103 UpdateInstanceRequestBuilder&& SetNodeCount(int node_count) && {
104 SetNodeCountImpl(node_count);
105 return std::move(*this);
106 }
107 UpdateInstanceRequestBuilder& SetProcessingUnits(int processing_units) & {
108 SetProcessingUnitsImpl(processing_units);
109 return *this;
110 }
111 UpdateInstanceRequestBuilder&& SetProcessingUnits(int processing_units) && {
112 SetProcessingUnitsImpl(processing_units);
113 return std::move(*this);
114 }
116 std::map<std::string, std::string> const& labels) & {
117 AddLabelsImpl(labels);
118 return *this;
119 }
121 std::map<std::string, std::string> const& labels) && {
122 AddLabelsImpl(labels);
123 return std::move(*this);
124 }
126 std::map<std::string, std::string> const& labels) & {
127 request_.mutable_instance()->clear_labels();
128 AddLabelsImpl(labels);
129 return *this;
130 }
132 std::map<std::string, std::string> const& labels) && {
133 request_.mutable_instance()->clear_labels();
134 AddLabelsImpl(labels);
135 return std::move(*this);
136 }
137 google::spanner::admin::instance::v1::UpdateInstanceRequest& Build() & {
138 return request_;
139 }
140 google::spanner::admin::instance::v1::UpdateInstanceRequest&& Build() && {
141 return std::move(request_);
142 }
143
144 private:
145 google::spanner::admin::instance::v1::UpdateInstanceRequest request_;
146 void SetDisplayNameImpl(std::string display_name) {
147 if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
148 "display_name", request_.field_mask())) {
149 request_.mutable_field_mask()->add_paths("display_name");
150 }
151 request_.mutable_instance()->set_display_name(std::move(display_name));
152 }
153 void SetNodeCountImpl(int node_count) {
154 if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
155 "node_count", request_.field_mask())) {
156 request_.mutable_field_mask()->add_paths("node_count");
157 }
158 request_.mutable_instance()->set_node_count(node_count);
159 }
160 void SetProcessingUnitsImpl(int processing_units) {
161 if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
162 "processing_units", request_.field_mask())) {
163 request_.mutable_field_mask()->add_paths("processing_units");
164 }
165 request_.mutable_instance()->set_processing_units(processing_units);
166 }
167 void AddLabelsImpl(std::map<std::string, std::string> const& labels) {
168 if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
169 "labels", request_.field_mask())) {
170 request_.mutable_field_mask()->add_paths("labels");
171 }
172 for (auto const& pair : labels) {
173 request_.mutable_instance()->mutable_labels()->insert(
174 {pair.first, pair.second});
175 }
176 }
177};
178
179GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
180} // namespace spanner
181} // namespace cloud
182} // namespace google
183
184#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
This class identifies a Cloud Spanner Instance.
Definition: instance.h:42
std::string FullName() const
Returns the fully qualified instance name as a string of the form: "projects/<project-id>/instances/<...
UpdateInstanceRequestBuilder is a builder class for google::spanner::admin::instance::v1::UpdateInsta...
Definition: update_instance_request_builder.h:41
friend bool operator==(UpdateInstanceRequestBuilder const &a, UpdateInstanceRequestBuilder const &b) noexcept
Definition: update_instance_request_builder.h:56
UpdateInstanceRequestBuilder(Instance const &in)
Definition: update_instance_request_builder.h:69
UpdateInstanceRequestBuilder & operator=(UpdateInstanceRequestBuilder &&)=default
UpdateInstanceRequestBuilder & SetDisplayName(std::string display_name) &
Definition: update_instance_request_builder.h:91
UpdateInstanceRequestBuilder && SetName(std::string name) &&
Definition: update_instance_request_builder.h:87
UpdateInstanceRequestBuilder(std::string instance_name)
Definition: update_instance_request_builder.h:66
UpdateInstanceRequestBuilder & SetNodeCount(int node_count) &
Definition: update_instance_request_builder.h:99
friend bool operator!=(UpdateInstanceRequestBuilder const &a, UpdateInstanceRequestBuilder const &b) noexcept
Definition: update_instance_request_builder.h:61
google::spanner::admin::instance::v1::UpdateInstanceRequest & Build() &
Definition: update_instance_request_builder.h:137
google::spanner::admin::instance::v1::UpdateInstanceRequest && Build() &&
Definition: update_instance_request_builder.h:140
UpdateInstanceRequestBuilder && SetNodeCount(int node_count) &&
Definition: update_instance_request_builder.h:103
UpdateInstanceRequestBuilder & AddLabels(std::map< std::string, std::string > const &labels) &
Definition: update_instance_request_builder.h:115
UpdateInstanceRequestBuilder & SetProcessingUnits(int processing_units) &
Definition: update_instance_request_builder.h:107
UpdateInstanceRequestBuilder(UpdateInstanceRequestBuilder &&)=default
UpdateInstanceRequestBuilder()=default
Constructs a UpdateInstanceRequestBuilder.
UpdateInstanceRequestBuilder && SetDisplayName(std::string display_name) &&
Definition: update_instance_request_builder.h:95
UpdateInstanceRequestBuilder && SetProcessingUnits(int processing_units) &&
Definition: update_instance_request_builder.h:111
UpdateInstanceRequestBuilder && SetLabels(std::map< std::string, std::string > const &labels) &&
Definition: update_instance_request_builder.h:131
UpdateInstanceRequestBuilder & SetName(std::string name) &
Definition: update_instance_request_builder.h:83
UpdateInstanceRequestBuilder && AddLabels(std::map< std::string, std::string > const &labels) &&
Definition: update_instance_request_builder.h:120
UpdateInstanceRequestBuilder & SetLabels(std::map< std::string, std::string > const &labels) &
Definition: update_instance_request_builder.h:125
UpdateInstanceRequestBuilder(google::spanner::admin::instance::v1::Instance in)
Constructs UpdateInstanceRequestBuilder with google::spanner::admin::instance::v1::Instance.
Definition: update_instance_request_builder.h:78
UpdateInstanceRequestBuilder(UpdateInstanceRequestBuilder const &)=default
UpdateInstanceRequestBuilder & operator=(UpdateInstanceRequestBuilder const &)=default
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23