Hazelcast C++ Client
TransactionalMap.h
1 /*
2  * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
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 // Created by sancar koyunlu on 8/5/13.
18 #ifndef HAZELCAST_TransactionalMap
19 #define HAZELCAST_TransactionalMap
20 
21 #include "hazelcast/client/proxy/TransactionalMapImpl.h"
22 
23 namespace hazelcast {
24  namespace client {
25  namespace serialization {
26  namespace pimpl {
27  class Data;
28  }
29  }
30 
31  namespace adaptor {
32  template <typename K, typename V>
33  class RawPointerTransactionalMap;
34  }
35 
43  template<typename K, typename V>
44  class TransactionalMap : public proxy::TransactionalMapImpl {
45  friend class TransactionContext;
46  friend class adaptor::RawPointerTransactionalMap<K, V>;
47 
48  public:
54  bool containsKey(const K& key) {
55  return proxy::TransactionalMapImpl::containsKey(toData(&key));
56  }
57 
63  boost::shared_ptr<V> get(const K& key) {
64  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::getData(toData(&key))));
65  }
66 
72  int size() {
73  return proxy::TransactionalMapImpl::size();
74  }
75 
81  bool isEmpty() {
82  return size() == 0;
83  }
84 
92  boost::shared_ptr<V> put(const K& key, const V& value) {
93  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::putData(toData(&key), toData(&value))));
94  };
95 
103  void set(const K& key, const V& value) {
104  proxy::TransactionalMapImpl::set(toData(&key), toData(&value));
105  }
106 
114  boost::shared_ptr<V> putIfAbsent(const K& key, const V& value) {
115  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::putIfAbsentData(toData(&key), toData(&value))));
116  };
117 
125  boost::shared_ptr<V> replace(const K& key, const V& value) {
126  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::replaceData(toData(&key), toData(&value))));
127  };
128 
136  bool replace(const K& key, const V& oldValue, const V& newValue) {
137  return proxy::TransactionalMapImpl::replace(toData(&key), toData(&oldValue), toData(&newValue));
138  };
139 
147  boost::shared_ptr<V> remove(const K& key) {
148  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::removeData(toData(&key))));
149  };
150 
159  void deleteEntry(const K& key) {
160  proxy::TransactionalMapImpl::deleteEntry(toData(&key));
161  };
162 
170  bool remove(const K& key, const V& value) {
171  return proxy::TransactionalMapImpl::remove(toData(&key), toData(&value));
172  }
173 
180  std::vector<K> keySet() {
181  return toObjectCollection<K>(proxy::TransactionalMapImpl::keySetData());
182  }
183 
190  std::vector<K> keySet(const serialization::IdentifiedDataSerializable *predicate) {
191  return toObjectCollection<K>(proxy::TransactionalMapImpl::keySetData(predicate));
192  }
193 
200  std::vector<V> values() {
201  return toObjectCollection<K>(proxy::TransactionalMapImpl::valuesData());
202  }
203 
209  std::vector<V> values(const serialization::IdentifiedDataSerializable *predicate) {
210  return toObjectCollection<K>(proxy::TransactionalMapImpl::valuesData(predicate));
211  }
212 
213  private:
214  TransactionalMap(const std::string& name, txn::TransactionProxy *transactionProxy)
215  : proxy::TransactionalMapImpl(name, transactionProxy) {
216 
217  }
218 
219  };
220  }
221 }
222 
223 #endif //HAZELCAST_TransactionalMap
224 
bool isEmpty()
Transactional implementation of IMap::isEmpty().
Definition: TransactionalMap.h:81
void set(const K &key, const V &value)
Transactional implementation of IMap::set(key, value).
Definition: TransactionalMap.h:103
bool replace(const K &key, const V &oldValue, const V &newValue)
Transactional implementation of IMap::replace(key, value, oldValue).
Definition: TransactionalMap.h:136
Transactional implementation of IMap.
Definition: TransactionalMap.h:44
boost::shared_ptr< V > put(const K &key, const V &value)
Transactional implementation of IMap::put(Object, Object).
Definition: TransactionalMap.h:92
std::vector< V > values(const serialization::IdentifiedDataSerializable *predicate)
Transactional implementation of IMap::values(Predicate) .
Definition: TransactionalMap.h:209
bool containsKey(const K &key)
Transactional implementation of IMap::containsKey(Object).
Definition: TransactionalMap.h:54
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:47
std::vector< K > keySet(const serialization::IdentifiedDataSerializable *predicate)
Transactional implementation of IMap::keySet(Predicate) .
Definition: TransactionalMap.h:190
void deleteEntry(const K &key)
Transactional implementation of IMap::delete(key).
Definition: TransactionalMap.h:159
int size()
Transactional implementation of IMap::size().
Definition: TransactionalMap.h:72
boost::shared_ptr< V > replace(const K &key, const V &value)
Transactional implementation of IMap::replace(key, value).
Definition: TransactionalMap.h:125
boost::shared_ptr< V > putIfAbsent(const K &key, const V &value)
Transactional implementation of IMap::putIfAbsent(key, value)
Definition: TransactionalMap.h:114
std::vector< K > keySet()
Transactional implementation of IMap::keySet().
Definition: TransactionalMap.h:180
std::vector< V > values()
Transactional implementation of IMap::values().
Definition: TransactionalMap.h:200
Transactional implementation of IMap.
Definition: RawPointerTransactionalMap.h:35
Definition: MapEntryView.h:32
Provides a context to do transactional operations; so beginning/committing transactions, but also retrieving transactional data-structures like the TransactionalMap.
Definition: TransactionContext.h:52