GridGain C++ Client Library
query_cursor.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) GridGain Systems. All Rights Reserved.
3 * _________ _____ __________________ _____
4 * __ ____/___________(_)______ /__ ____/______ ____(_)_______
5 * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
6 * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
7 * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
8 */
9 
15 #ifndef _GRIDGAIN_CACHE_QUERY_CURSOR
16 #define _GRIDGAIN_CACHE_QUERY_CURSOR
17 
18 #include <vector>
19 
20 #include <ignite/common/concurrent.h>
21 
23 #include "gridgain/grid_error.h"
24 #include "gridgain/impl/cache/query/query_impl.h"
25 #include "gridgain/impl/operations.h"
26 
27 namespace gridgain
28 {
29  namespace cache
30  {
31  namespace query
32  {
36  template<typename K, typename V>
38  {
39  public:
43  QueryCursor() : impl(NULL)
44  {
45  // No-op.
46  }
47 
53  QueryCursor(impl::cache::query::QueryCursorImpl* impl) : impl(impl)
54  {
55  // No-op.
56  }
57 
63  bool HasNext()
64  {
65  GridError err;
66 
67  bool res = HasNext(err);
68 
70 
71  return res;
72  }
73 
80  bool HasNext(GridError& err)
81  {
82  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
83 
84  if (impl0)
85  return impl0->HasNext(&err);
86  else
87  {
89  "Instance is not usable (did you check for error?).");
90 
91  return false;
92  }
93  }
94 
101  {
102  GridError err;
103 
104  CacheEntry<K, V> res = GetNext(err);
105 
107 
108  return res;
109  }
110 
118  {
119  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
120 
121  if (impl0) {
122  impl::Out2Operation<K, V> outOp;
123 
124  impl0->GetNext(outOp, &err);
125 
126  if (err.GetCode() == GridError::GG_SUCCESS)
127  {
128  K& key = outOp.Get1();
129  V& val = outOp.Get2();
130 
131  return CacheEntry<K, V>(key, val);
132  }
133  else
134  return CacheEntry<K, V>();
135  }
136  else
137  {
139  "Instance is not usable (did you check for error?).");
140 
141  return CacheEntry<K, V>();
142  }
143  }
144 
150  void GetAll(std::vector<CacheEntry<K, V>>& res)
151  {
152  GridError err;
153 
154  GetAll(res, err);
155 
157  }
158 
165  void GetAll(std::vector<CacheEntry<K, V>>& res, GridError& err)
166  {
167  impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
168 
169  if (impl0) {
170  impl::OutQueryGetAllOperation<K, V> outOp(&res);
171 
172  impl0->GetAll(outOp, &err);
173  }
174  else
176  "Instance is not usable (did you check for error?).");
177  }
178 
184  bool IsValid()
185  {
186  return impl.IsValid();
187  }
188 
189  private:
191  ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
192  };
193  }
194  }
195 }
196 
197 #endif
bool HasNext(GridError &err)
Check whether next entry exists.
Definition: query_cursor.h:80
static const int GG_ERR_GENERIC
Generic GridGain error.
Definition: grid_error.h:104
CacheEntry< K, V > GetNext()
Get next entry.
Definition: query_cursor.h:100
void GetAll(std::vector< CacheEntry< K, V >> &res)
Get all entries.
Definition: query_cursor.h:150
void GetAll(std::vector< CacheEntry< K, V >> &res, GridError &err)
Get all entries.
Definition: query_cursor.h:165
QueryCursor(impl::cache::query::QueryCursorImpl *impl)
Constructor.
Definition: query_cursor.h:53
Declares gridgain::GridError class.
int32_t GetCode() const
Get error code.
Definition: grid_error.cpp:74
Query cursor.
Definition: query_cursor.h:37
Declares gridgain::cache::CacheEntry class.
CacheEntry< K, V > GetNext(GridError &err)
Get next entry.
Definition: query_cursor.h:117
static const int GG_SUCCESS
Success.
Definition: grid_error.h:74
bool IsValid()
Check if the instance is valid.
Definition: query_cursor.h:184
QueryCursor()
Default constructor.
Definition: query_cursor.h:43
static void ThrowIfNeeded(GridError &err)
Throw an error if code is not GG_SUCCESS.
Definition: grid_error.cpp:22
Cache entry.
Definition: cache_entry.h:28
bool HasNext()
Check whether next entry exists.
Definition: query_cursor.h:63
GridGain API.
Definition: cache.h:35
Grid error information.
Definition: grid_error.h:70