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_CURSOR
24 #define _IGNITE_CACHE_QUERY_CURSOR
25 
26 #include <vector>
27 
28 #include <ignite/common/concurrent.h>
29 
31 #include "ignite/ignite_error.h"
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  {
44  template<typename K, typename V>
46  {
47  public:
51  QueryCursor() : impl(NULL)
52  {
53  // No-op.
54  }
55 
61  QueryCursor(impl::cache::query::QueryCursorImpl* impl) : impl(impl)
62  {
63  // No-op.
64  }
65 
71  bool HasNext()
72  {
73  IgniteError err;
74 
75  bool res = HasNext(err);
76 
78 
79  return res;
80  }
81 
88  bool HasNext(IgniteError& err)
89  {
90  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
91 
92  if (impl0)
93  return impl0->HasNext(&err);
94  else
95  {
97  "Instance is not usable (did you check for error?).");
98 
99  return false;
100  }
101  }
102 
109  {
110  IgniteError err;
111 
112  CacheEntry<K, V> res = GetNext(err);
113 
115 
116  return res;
117  }
118 
126  {
127  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
128 
129  if (impl0) {
130  impl::Out2Operation<K, V> outOp;
131 
132  impl0->GetNext(outOp, &err);
133 
134  if (err.GetCode() == IgniteError::IGNITE_SUCCESS)
135  {
136  K& key = outOp.Get1();
137  V& val = outOp.Get2();
138 
139  return CacheEntry<K, V>(key, val);
140  }
141  else
142  return CacheEntry<K, V>();
143  }
144  else
145  {
147  "Instance is not usable (did you check for error?).");
148 
149  return CacheEntry<K, V>();
150  }
151  }
152 
158  void GetAll(std::vector<CacheEntry<K, V>>& res)
159  {
160  IgniteError err;
161 
162  GetAll(res, err);
163 
165  }
166 
173  void GetAll(std::vector<CacheEntry<K, V>>& res, IgniteError& err)
174  {
175  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
176 
177  if (impl0) {
178  impl::OutQueryGetAllOperation<K, V> outOp(&res);
179 
180  impl0->GetAll(outOp, &err);
181  }
182  else
184  "Instance is not usable (did you check for error?).");
185  }
186 
192  bool IsValid()
193  {
194  return impl.IsValid();
195  }
196 
197  private:
199  ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
200  };
201  }
202  }
203 }
204 
205 #endif
void GetAll(std::vector< CacheEntry< K, V >> &res, IgniteError &err)
Get all entries.
Definition: query_cursor.h:173
QueryCursor(impl::cache::query::QueryCursorImpl *impl)
Constructor.
Definition: query_cursor.h:61
bool HasNext(IgniteError &err)
Check whether next entry exists.
Definition: query_cursor.h:88
int32_t GetCode() const
Get error code.
Definition: ignite_error.cpp:79
CacheEntry< K, V > GetNext(IgniteError &err)
Get next entry.
Definition: query_cursor.h:125
void GetAll(std::vector< CacheEntry< K, V >> &res)
Get all entries.
Definition: query_cursor.h:158
QueryCursor()
Default constructor.
Definition: query_cursor.h:51
Cache entry.
Definition: cache_entry.h:36
bool IsValid()
Check if the instance is valid.
Definition: query_cursor.h:192
static void ThrowIfNeeded(IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
static const int IGNITE_SUCCESS
Success.
Definition: ignite_error.h:82
CacheEntry< K, V > GetNext()
Get next entry.
Definition: query_cursor.h:108
Declares ignite::cache::CacheEntry class.
Ignite error information.
Definition: ignite_error.h:78
bool HasNext()
Check whether next entry exists.
Definition: query_cursor.h:71
Apache Ignite API.
Definition: binary_consts.h:28
Declares ignite::IgniteError class.
Query cursor.
Definition: query_cursor.h:45
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:112