GridGain C++
core/include/ignite/cache/query/query_cursor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (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  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
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 
22 #ifndef _IGNITE_CACHE_QUERY_QUERY_CURSOR
23 #define _IGNITE_CACHE_QUERY_QUERY_CURSOR
24 
25 #include <vector>
26 
27 #include <ignite/common/concurrent.h>
28 #include <ignite/ignite_error.h>
29 
31 #include "ignite/impl/cache/query/query_impl.h"
32 #include "ignite/impl/operations.h"
33 
34 namespace ignite
35 {
36  namespace cache
37  {
38  namespace query
39  {
52  template<typename K, typename V>
54  {
55  public:
62  QueryCursor() : impl(0)
63  {
64  // No-op.
65  }
66 
74  QueryCursor(impl::cache::query::QueryCursorImpl* impl) : impl(impl)
75  {
76  // No-op.
77  }
78 
88  bool HasNext()
89  {
90  IgniteError err;
91 
92  bool res = HasNext(err);
93 
95 
96  return res;
97  }
98 
109  bool HasNext(IgniteError& err)
110  {
111  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
112 
113  if (impl0)
114  return impl0->HasNext(err);
115  else
116  {
118  "Instance is not usable (did you check for error?).");
119 
120  return false;
121  }
122  }
123 
134  {
135  IgniteError err;
136 
137  CacheEntry<K, V> res = GetNext(err);
138 
140 
141  return res;
142  }
143 
156  {
157  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
158 
159  if (impl0) {
160  K key;
161  V val;
162 
163  impl::Out2Operation<K, V> outOp(key, val);
164 
165  impl0->GetNext(outOp, err);
166 
167  return CacheEntry<K, V>(key, val);
168  }
169  else
170  {
172  "Instance is not usable (did you check for error?).");
173 
174  return CacheEntry<K, V>();
175  }
176  }
177 
187  void GetAll(std::vector<CacheEntry<K, V> >& res)
188  {
189  IgniteError err;
190 
191  GetAll(res, err);
192 
194  }
195 
205  void GetAll(std::vector<CacheEntry<K, V> >& res, IgniteError& err)
206  {
207  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
208 
209  if (impl0) {
210  impl::OutQueryGetAllOperation<K, V> outOp(res);
211 
212  impl0->GetAll(outOp, err);
213  }
214  else
216  "Instance is not usable (did you check for error?).");
217  }
218 
226  template<typename OutIter>
227  void GetAll(OutIter iter)
228  {
229  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
230 
231  if (impl0) {
232  impl::OutQueryGetAllOperationIter<K, V, OutIter> outOp(iter);
233 
234  impl0->GetAll(outOp);
235  }
236  else
237  {
239  "Instance is not usable (did you check for error?).");
240  }
241  }
242 
254  bool IsValid() const
255  {
256  return impl.IsValid();
257  }
258 
259  private:
261  ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
262  };
263  }
264  }
265 }
266 
267 #endif //_IGNITE_CACHE_QUERY_QUERY_CURSOR
ignite
Ignite API.
Definition: cache.h:47
ignite::cache::query::QueryCursor::GetAll
void GetAll(std::vector< CacheEntry< K, V > > &res)
Get all entries.
Definition: core/include/ignite/cache/query/query_cursor.h:187
ignite::cache::query::QueryCursor::HasNext
bool HasNext()
Check whether next entry exists.
Definition: core/include/ignite/cache/query/query_cursor.h:88
ignite::cache::CacheEntry
Cache entry class template.
Definition: core/include/ignite/cache/cache_entry.h:39
ignite::cache::query::QueryCursor
Query cursor class template.
Definition: core/include/ignite/cache/query/query_cursor.h:53
ignite::cache::query::QueryCursor::QueryCursor
QueryCursor(impl::cache::query::QueryCursorImpl *impl)
Constructor.
Definition: core/include/ignite/cache/query/query_cursor.h:74
ignite::cache::query::QueryCursor::GetNext
CacheEntry< K, V > GetNext()
Get next entry.
Definition: core/include/ignite/cache/query/query_cursor.h:133
ignite::IgniteError::IGNITE_ERR_GENERIC
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:130
cache_entry.h
ignite::cache::query::QueryCursor::GetAll
void GetAll(OutIter iter)
Get all entries.
Definition: core/include/ignite/cache/query/query_cursor.h:227
ignite::cache::query::QueryCursor::IsValid
bool IsValid() const
Check if the instance is valid.
Definition: core/include/ignite/cache/query/query_cursor.h:254
ignite::cache::query::QueryCursor::GetNext
CacheEntry< K, V > GetNext(IgniteError &err)
Get next entry.
Definition: core/include/ignite/cache/query/query_cursor.h:155
ignite::cache::query::QueryCursor::GetAll
void GetAll(std::vector< CacheEntry< K, V > > &res, IgniteError &err)
Get all entries.
Definition: core/include/ignite/cache/query/query_cursor.h:205
ignite::IgniteError::ThrowIfNeeded
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:26
ignite::cache::query::QueryCursor::QueryCursor
QueryCursor()
Default constructor.
Definition: core/include/ignite/cache/query/query_cursor.h:62
ignite_error.h
ignite::cache::query::QueryCursor::HasNext
bool HasNext(IgniteError &err)
Check whether next entry exists.
Definition: core/include/ignite/cache/query/query_cursor.h:109
ignite::IgniteError
Ignite error information.
Definition: ignite_error.h:93