Apache Ignite C++
core/include/ignite/cache/query/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  K key;
162  V val;
163 
164  impl::Out2Operation<K, V> outOp(key, val);
165 
166  impl0->GetNext(outOp, err);
167 
168  return CacheEntry<K, V>(key, val);
169  }
170  else
171  {
173  "Instance is not usable (did you check for error?).");
174 
175  return CacheEntry<K, V>();
176  }
177  }
178 
188  void GetAll(std::vector<CacheEntry<K, V> >& res)
189  {
190  IgniteError err;
191 
192  GetAll(res, err);
193 
195  }
196 
206  void GetAll(std::vector<CacheEntry<K, V> >& res, IgniteError& err)
207  {
208  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
209 
210  if (impl0) {
211  impl::OutQueryGetAllOperation<K, V> outOp(res);
212 
213  impl0->GetAll(outOp, err);
214  }
215  else
217  "Instance is not usable (did you check for error?).");
218  }
219 
227  template<typename OutIter>
228  void GetAll(OutIter iter)
229  {
230  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
231 
232  if (impl0) {
233  impl::OutQueryGetAllOperationIter<K, V, OutIter> outOp(iter);
234 
235  impl0->GetAll(outOp);
236  }
237  else
238  {
240  "Instance is not usable (did you check for error?).");
241  }
242  }
243 
255  bool IsValid() const
256  {
257  return impl.IsValid();
258  }
259 
260  private:
262  ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
263  };
264  }
265  }
266 }
267 
268 #endif //_IGNITE_CACHE_QUERY_QUERY_CURSOR
ignite
Apache Ignite API.
Definition: cache.h:48
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:188
ignite::cache::query::QueryCursor::HasNext
bool HasNext()
Check whether next entry exists.
Definition: core/include/ignite/cache/query/query_cursor.h:89
ignite::cache::CacheEntry
Cache entry class template.
Definition: core/include/ignite/cache/cache_entry.h:40
ignite::cache::query::QueryCursor
Query cursor class template.
Definition: core/include/ignite/cache/query/query_cursor.h:54
ignite::cache::query::QueryCursor::QueryCursor
QueryCursor(impl::cache::query::QueryCursorImpl *impl)
Constructor.
Definition: core/include/ignite/cache/query/query_cursor.h:75
ignite::cache::query::QueryCursor::GetNext
CacheEntry< K, V > GetNext()
Get next entry.
Definition: core/include/ignite/cache/query/query_cursor.h:134
ignite::IgniteError::IGNITE_ERR_GENERIC
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:131
cache_entry.h
ignite::cache::query::QueryCursor::GetAll
void GetAll(OutIter iter)
Get all entries.
Definition: core/include/ignite/cache/query/query_cursor.h:228
ignite::cache::query::QueryCursor::IsValid
bool IsValid() const
Check if the instance is valid.
Definition: core/include/ignite/cache/query/query_cursor.h:255
ignite::cache::query::QueryCursor::GetNext
CacheEntry< K, V > GetNext(IgniteError &err)
Get next entry.
Definition: core/include/ignite/cache/query/query_cursor.h:156
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:206
ignite::IgniteError::ThrowIfNeeded
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
ignite::cache::query::QueryCursor::QueryCursor
QueryCursor()
Default constructor.
Definition: core/include/ignite/cache/query/query_cursor.h:63
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:110
ignite::IgniteError
Ignite error information.
Definition: ignite_error.h:94