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 serialization {
25  namespace pimpl {
26  class Data;
27  }
28  }
29  namespace client {
30  namespace adaptor {
31  template <typename K, typename V>
32  class RawPointerTransactionalMap;
33  }
34 
42  template<typename K, typename V>
43  class TransactionalMap : public proxy::TransactionalMapImpl {
44  friend class TransactionContext;
45  friend class adaptor::RawPointerTransactionalMap<K, V>;
46 
47  public:
53  bool containsKey(const K& key) {
54  return proxy::TransactionalMapImpl::containsKey(toData(&key));
55  }
56 
62  boost::shared_ptr<V> get(const K& key) {
63  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::getData(toData(&key))));
64  }
65 
71  int size() {
72  return proxy::TransactionalMapImpl::size();
73  }
74 
80  bool isEmpty() {
81  return size() == 0;
82  }
83 
91  boost::shared_ptr<V> put(const K& key, const V& value) {
92  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::putData(toData(&key), toData(&value))));
93  };
94 
102  void set(const K& key, const V& value) {
103  proxy::TransactionalMapImpl::set(toData(&key), toData(&value));
104  }
105 
113  boost::shared_ptr<V> putIfAbsent(const K& key, const V& value) {
114  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::putIfAbsentData(toData(&key), toData(&value))));
115  };
116 
124  boost::shared_ptr<V> replace(const K& key, const V& value) {
125  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::replaceData(toData(&key), toData(&value))));
126  };
127 
135  bool replace(const K& key, const V& oldValue, const V& newValue) {
136  return proxy::TransactionalMapImpl::replace(toData(&key), toData(&oldValue), toData(&newValue));
137  };
138 
146  boost::shared_ptr<V> remove(const K& key) {
147  return boost::shared_ptr<V>(toObject<V>(proxy::TransactionalMapImpl::removeData(toData(&key))));
148  };
149 
158  void deleteEntry(const K& key) {
159  proxy::TransactionalMapImpl::deleteEntry(toData(&key));
160  };
161 
169  bool remove(const K& key, const V& value) {
170  return proxy::TransactionalMapImpl::remove(toData(&key), toData(&value));
171  }
172 
179  std::vector<K> keySet() {
180  return toObjectCollection<K>(proxy::TransactionalMapImpl::keySetData());
181  }
182 
189  std::vector<K> keySet(const serialization::IdentifiedDataSerializable *predicate) {
190  return toObjectCollection<K>(proxy::TransactionalMapImpl::keySetData(predicate));
191  }
192 
199  std::vector<V> values() {
200  return toObjectCollection<K>(proxy::TransactionalMapImpl::valuesData());
201  }
202 
208  std::vector<V> values(const serialization::IdentifiedDataSerializable *predicate) {
209  return toObjectCollection<K>(proxy::TransactionalMapImpl::valuesData(predicate));
210  }
211 
212  private:
213  TransactionalMap(const std::string& name, txn::TransactionProxy *transactionProxy)
214  : proxy::TransactionalMapImpl(name, transactionProxy) {
215 
216  }
217 
218  };
219  }
220 }
221 
222 #endif //HAZELCAST_TransactionalMap
223 
bool isEmpty()
Transactional implementation of IMap::isEmpty().
Definition: TransactionalMap.h:80
void set(const K &key, const V &value)
Transactional implementation of IMap::set(key, value).
Definition: TransactionalMap.h:102
bool replace(const K &key, const V &oldValue, const V &newValue)
Transactional implementation of IMap::replace(key, value, oldValue).
Definition: TransactionalMap.h:135
Transactional implementation of IMap.
Definition: TransactionalMap.h:43
boost::shared_ptr< V > put(const K &key, const V &value)
Transactional implementation of IMap::put(Object, Object).
Definition: TransactionalMap.h:91
std::vector< V > values(const serialization::IdentifiedDataSerializable *predicate)
Transactional implementation of IMap::values(Predicate) .
Definition: TransactionalMap.h:208
bool containsKey(const K &key)
Transactional implementation of IMap::containsKey(Object).
Definition: TransactionalMap.h:53
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:42
std::vector< K > keySet(const serialization::IdentifiedDataSerializable *predicate)
Transactional implementation of IMap::keySet(Predicate) .
Definition: TransactionalMap.h:189
void deleteEntry(const K &key)
Transactional implementation of IMap::delete(key).
Definition: TransactionalMap.h:158
int size()
Transactional implementation of IMap::size().
Definition: TransactionalMap.h:71
boost::shared_ptr< V > replace(const K &key, const V &value)
Transactional implementation of IMap::replace(key, value).
Definition: TransactionalMap.h:124
boost::shared_ptr< V > putIfAbsent(const K &key, const V &value)
Transactional implementation of IMap::putIfAbsent(key, value)
Definition: TransactionalMap.h:113
std::vector< K > keySet()
Transactional implementation of IMap::keySet().
Definition: TransactionalMap.h:179
std::vector< V > values()
Transactional implementation of IMap::values().
Definition: TransactionalMap.h:199
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