Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
transaction_links.hxx
1 /*
2  * Copyright 2021 Couchbase, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <ostream>
20 #include <string>
21 
22 #include <boost/optional.hpp>
23 
24 #include <couchbase/internal/nlohmann/json.hpp>
25 #include <couchbase/support.hxx>
26 
27 namespace couchbase
28 {
29 namespace transactions
30 {
32  class transaction_links
33  {
34  private:
35  boost::optional<std::string> atr_id_;
36  boost::optional<std::string> atr_bucket_name_;
37  boost::optional<std::string> atr_scope_name_;
38  boost::optional<std::string> atr_collection_name_;
39  // id of the transaction that has staged content
40  boost::optional<std::string> staged_transaction_id_;
41  boost::optional<std::string> staged_attempt_id_;
42  boost::optional<nlohmann::json> staged_content_;
43 
44  // for {BACKUP_FIELDS}
45  boost::optional<std::string> cas_pre_txn_;
46  boost::optional<std::string> revid_pre_txn_;
47  boost::optional<uint32_t> exptime_pre_txn_;
48  boost::optional<std::string> crc32_of_staging_;
49  boost::optional<std::string> op_;
50  boost::optional<nlohmann::json> forward_compat_;
51  bool is_deleted_;
52 
53  public:
54  transaction_links() = default;
55  transaction_links(boost::optional<std::string> atr_id,
56  boost::optional<std::string> atr_bucket_name,
57  boost::optional<std::string> atr_scope_name,
58  boost::optional<std::string> atr_collection_name,
59  boost::optional<std::string> staged_transaction_id,
60  boost::optional<std::string> staged_attempt_id,
61  boost::optional<nlohmann::json> staged_content,
62  boost::optional<std::string> cas_pre_txn,
63  boost::optional<std::string> revid_pre_txn,
64  boost::optional<uint32_t> exptime_pre_txn,
65  boost::optional<std::string> crc32_of_staging,
66  boost::optional<std::string> op,
67  boost::optional<nlohmann::json> forward_compat,
68  bool is_deleted)
69  : atr_id_(std::move(atr_id))
70  , atr_bucket_name_(std::move(atr_bucket_name))
71  , atr_scope_name_(std::move(atr_scope_name))
72  , atr_collection_name_(std::move(atr_collection_name))
73  , staged_transaction_id_(std::move(staged_transaction_id))
74  , staged_attempt_id_(std::move(staged_attempt_id))
75  , staged_content_(std::move(staged_content))
76  , cas_pre_txn_(std::move(cas_pre_txn))
77  , revid_pre_txn_(std::move(revid_pre_txn))
78  , exptime_pre_txn_(exptime_pre_txn)
79  , crc32_of_staging_(std::move(crc32_of_staging))
80  , op_(std::move(op))
81  , forward_compat_(forward_compat)
82  , is_deleted_(is_deleted)
83  {
84  }
85 
89  CB_NODISCARD bool is_document_in_transaction() const
90  {
91  return !!(atr_id_);
92  }
93  CB_NODISCARD bool has_staged_content() const
94  {
95  return !!(staged_content_);
96  }
97  CB_NODISCARD bool is_document_being_removed() const
98  {
99  return (!!op_ && *op_ == "remove");
100  }
101 
102  CB_NODISCARD bool has_staged_write() const
103  {
104  return !!(staged_attempt_id_);
105  }
106 
107  CB_NODISCARD boost::optional<std::string> atr_id() const
108  {
109  return atr_id_;
110  }
111 
112  CB_NODISCARD boost::optional<std::string> atr_bucket_name() const
113  {
114  return atr_bucket_name_;
115  }
116 
117  CB_NODISCARD boost::optional<std::string> atr_scope_name() const
118  {
119  return atr_scope_name_;
120  }
121 
122  CB_NODISCARD boost::optional<std::string> atr_collection_name() const
123  {
124  return atr_collection_name_;
125  }
126 
127  CB_NODISCARD boost::optional<std::string> staged_transaction_id() const
128  {
129  return staged_transaction_id_;
130  }
131 
132  CB_NODISCARD boost::optional<std::string> staged_attempt_id() const
133  {
134  return staged_attempt_id_;
135  }
136 
137  CB_NODISCARD boost::optional<std::string> cas_pre_txn() const
138  {
139  return cas_pre_txn_;
140  }
141 
142  CB_NODISCARD boost::optional<std::string> revid_pre_txn() const
143  {
144  return revid_pre_txn_;
145  }
146 
147  CB_NODISCARD boost::optional<uint32_t> exptime_pre_txn() const
148  {
149  return exptime_pre_txn_;
150  }
151 
152  CB_NODISCARD boost::optional<std::string> op() const
153  {
154  return op_;
155  }
156 
157  CB_NODISCARD boost::optional<std::string> crc32_of_staging() const
158  {
159  return crc32_of_staging_;
160  }
161 
162  template<typename Content>
163  CB_NODISCARD Content staged_content() const
164  {
165  return staged_content_ ? staged_content_->get<Content>() : Content();
166  }
167 
168  CB_NODISCARD boost::optional<nlohmann::json> forward_compat() const
169  {
170  return forward_compat_;
171  }
172 
173  CB_NODISCARD bool is_deleted() const
174  {
175  return is_deleted_;
176  }
177 
178  friend std::ostream& operator<<(std::ostream& os, const transaction_links& links);
179  };
180 
181  std::ostream& operator<<(std::ostream& os, const transaction_links& links);
182 } // namespace transactions
183 } // namespace couchbase
Definition: bucket.hxx:33