Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
attempt_context.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 #pragma once
17 
18 #include <string>
19 
21 #include <couchbase/transactions/transaction_get_result.hxx>
22 
23 namespace couchbase
24 {
25 namespace transactions
26 {
36  {
37  public:
48  virtual transaction_get_result get(std::shared_ptr<collection> collection, const std::string& id) = 0;
49 
60  virtual boost::optional<transaction_get_result> get_optional(std::shared_ptr<collection> collection, const std::string& id) = 0;
61 
81  template<typename Content>
82  transaction_get_result replace(std::shared_ptr<collection> collection,
83  const transaction_get_result& document,
84  const Content& content)
85  {
86  nlohmann::json json_content = content;
87  return replace_raw(collection, document, json_content);
88  }
106  template<typename Content>
107  transaction_get_result insert(std::shared_ptr<collection> collection, const std::string& id, const Content& content)
108  {
109  nlohmann::json json_content = content;
110  return insert_raw(collection, id, json_content);
111  }
126  virtual void remove(std::shared_ptr<couchbase::collection> collection, transaction_get_result& document) = 0;
127 
138  virtual void commit() = 0;
139 
150  virtual void rollback() = 0;
151 
152  protected:
154  virtual transaction_get_result insert_raw(std::shared_ptr<collection> collection,
155  const std::string& id,
156  const nlohmann::json& content) = 0;
157 
159  virtual transaction_get_result replace_raw(std::shared_ptr<collection> collection,
160  const transaction_get_result& document,
161  const nlohmann::json& content) = 0;
162  };
163 
164 } // namespace transactions
165 } // namespace couchbase
Definition: bucket.hxx:33
transaction_get_result replace(std::shared_ptr< collection > collection, const transaction_get_result &document, const Content &content)
Definition: attempt_context.hxx:82
Encapsulates results of an individual transaction operation.
Definition: transaction_get_result.hxx:38
virtual transaction_get_result replace_raw(std::shared_ptr< collection > collection, const transaction_get_result &document, const nlohmann::json &content)=0
virtual transaction_get_result insert_raw(std::shared_ptr< collection > collection, const std::string &id, const nlohmann::json &content)=0
virtual boost::optional< transaction_get_result > get_optional(std::shared_ptr< collection > collection, const std::string &id)=0
Provides methods to perform transactional operations.
Definition: attempt_context.hxx:35
Exposes collection-level kv operations.
Definition: collection.hxx:46
transaction_get_result insert(std::shared_ptr< collection > collection, const std::string &id, const Content &content)
Definition: attempt_context.hxx:107