Apache Ignite C++
query_cursor.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
23 #ifndef _IGNITE_CACHE_QUERY_QUERY_CURSOR
24 #define _IGNITE_CACHE_QUERY_QUERY_CURSOR
25 
26 #include <vector>
27 
28 #include <ignite/common/concurrent.h>
29 #include <ignite/ignite_error.h>
30 
32 #include "ignite/impl/cache/query/query_impl.h"
33 #include "ignite/impl/operations.h"
34 
35 namespace ignite
36 {
37  namespace cache
38  {
39  namespace query
40  {
53  template<typename K, typename V>
55  {
56  public:
63  QueryCursor() : impl(0)
64  {
65  // No-op.
66  }
67 
75  QueryCursor(impl::cache::query::QueryCursorImpl* impl) : impl(impl)
76  {
77  // No-op.
78  }
79 
89  bool HasNext()
90  {
91  IgniteError err;
92 
93  bool res = HasNext(err);
94 
96 
97  return res;
98  }
99 
110  bool HasNext(IgniteError& err)
111  {
112  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
113 
114  if (impl0)
115  return impl0->HasNext(err);
116  else
117  {
119  "Instance is not usable (did you check for error?).");
120 
121  return false;
122  }
123  }
124 
135  {
136  IgniteError err;
137 
138  CacheEntry<K, V> res = GetNext(err);
139 
141 
142  return res;
143  }
144 
157  {
158  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
159 
160  if (impl0) {
161  impl::Out2Operation<K, V> outOp;
162 
163  impl0->GetNext(outOp, err);
164 
165  if (err.GetCode() == IgniteError::IGNITE_SUCCESS)
166  {
167  K& key = outOp.Get1();
168  V& val = outOp.Get2();
169 
170  return CacheEntry<K, V>(key, val);
171  }
172  else
173  return CacheEntry<K, V>();
174  }
175  else
176  {
178  "Instance is not usable (did you check for error?).");
179 
180  return CacheEntry<K, V>();
181  }
182  }
183 
193  void GetAll(std::vector<CacheEntry<K, V> >& res)
194  {
195  IgniteError err;
196 
197  GetAll(res, err);
198 
200  }
201 
211  void GetAll(std::vector<CacheEntry<K, V> >& res, IgniteError& err)
212  {
213  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
214 
215  if (impl0) {
216  impl::OutQueryGetAllOperation<K, V> outOp(res);
217 
218  impl0->GetAll(outOp, err);
219  }
220  else
222  "Instance is not usable (did you check for error?).");
223  }
224 
232  template<typename OutIter>
233  void GetAll(OutIter iter)
234  {
235  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
236 
237  if (impl0) {
238  impl::OutQueryGetAllOperationIter<K, V, OutIter> outOp(iter);
239 
240  impl0->GetAll(outOp);
241  }
242  else
243  {
245  "Instance is not usable (did you check for error?).");
246  }
247  }
248 
260  bool IsValid() const
261  {
262  return impl.IsValid();
263  }
264 
265  private:
267  ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
268  };
269  }
270  }
271 }
272 
273 #endif //_IGNITE_CACHE_QUERY_QUERY_CURSOR
void GetAll(std::vector< CacheEntry< K, V > > &res, IgniteError &err)
Get all entries.
Definition: query_cursor.h:211
QueryCursor(impl::cache::query::QueryCursorImpl *impl)
Constructor.
Definition: query_cursor.h:75
bool HasNext(IgniteError &err)
Check whether next entry exists.
Definition: query_cursor.h:110
void GetAll(OutIter iter)
Get all entries.
Definition: query_cursor.h:233
int32_t GetCode() const
Get error code.
Definition: ignite_error.cpp:78
CacheEntry< K, V > GetNext(IgniteError &err)
Get next entry.
Definition: query_cursor.h:156
QueryCursor()
Default constructor.
Definition: query_cursor.h:63
Cache entry class template.
Definition: cache_entry.h:40
static const int IGNITE_SUCCESS
Success.
Definition: ignite_error.h:98
CacheEntry< K, V > GetNext()
Get next entry.
Definition: query_cursor.h:134
Declares ignite::cache::CacheEntry class.
Ignite error information.
Definition: ignite_error.h:94
bool HasNext()
Check whether next entry exists.
Definition: query_cursor.h:89
bool IsValid() const
Check if the instance is valid.
Definition: query_cursor.h:260
Apache Ignite API.
Definition: cache.h:48
Declares ignite::IgniteError class.
void GetAll(std::vector< CacheEntry< K, V > > &res)
Get all entries.
Definition: query_cursor.h:193
Query cursor class template.
Definition: query_cursor.h:54
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:131