| Apache Ignite C++

thin-client/include/ignite/thin/cache/query/query_sql_fields.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_THIN_CACHE_QUERY_QUERY_SQL_FIELDS
24 #define _IGNITE_THIN_CACHE_QUERY_QUERY_SQL_FIELDS
25
26 #include <stdint.h>
27 #include <string>
28 #include <vector>
29
30 #include <ignite/impl/thin/copyable_writable.h>
31
32 namespace ignite
33 {
34 namespace impl
35 {
36 namespace thin
37 {
38 // Forward declaration
39 class SqlFieldsQueryRequest;
40 }
41 }
42
43 namespace thin
44 {
45 namespace cache
46 {
47 namespace query
48 {
52 class SqlFieldsQuery
53 {
54 public:
55 friend class ignite::impl::thin::SqlFieldsQueryRequest;
56
62 explicit SqlFieldsQuery(const std::string& sql) :
63 sql(sql),
64 schema(),
65 pageSize(1024),
66 maxRows(0),
67 timeout(0),
68 loc(false),
69 distributedJoins(false),
70 enforceJoinOrder(false),
71 lazy(false),
72 collocated(false),
73 args()
74 {
75 // No-op.
76 }
77
83 SqlFieldsQuery(const SqlFieldsQuery& other) :
84 sql(other.sql),
85 schema(other.schema),
86 pageSize(other.pageSize),
87 maxRows(other.maxRows),
88 timeout(other.timeout),
89 loc(other.loc),
90 distributedJoins(other.distributedJoins),
91 enforceJoinOrder(other.enforceJoinOrder),
92 lazy(other.lazy),
93 collocated(other.collocated),
94 args()
95 {
96 args.reserve(other.args.size());
97
98 typedef std::vector<impl::thin::CopyableWritable*>::const_iterator Iter;
99
100 for (Iter i = other.args.begin(); i != other.args.end(); ++i)
101 args.push_back((*i)->Copy());
102 }
103
109 SqlFieldsQuery& operator=(const SqlFieldsQuery& other)
110 {
111 if (this != &other)
112 {
113 SqlFieldsQuery tmp(other);
114
115 Swap(tmp);
116 }
117
118 return *this;
119 }
120
124 ~SqlFieldsQuery()
125 {
126 ClearArguments();
127 }
128
134 void Swap(SqlFieldsQuery& other)
135 {
136 if (this != &other)
137 {
138 using std::swap;
139
140 swap(sql, other.sql);
141 swap(schema, other.schema);
142 swap(pageSize, other.pageSize);
143 swap(maxRows, other.maxRows);
144 swap(timeout, other.timeout);
145 swap(loc, other.loc);
146 swap(distributedJoins, other.distributedJoins);
147 swap(enforceJoinOrder, other.enforceJoinOrder);
148 swap(lazy, other.lazy);
149 swap(collocated, other.collocated);
150 swap(args, other.args);
151 }
152 }
153
159 const std::string& GetSql() const
160 {
161 return sql;
162 }
163
169 void SetSql(const std::string& sql)
170 {
171 this->sql = sql;
172 }
173
181 void SetSchema(const std::string& schema)
182 {
183 this->schema = schema;
184 }
185
194 const std::string& GetSchema() const
195 {
196 return schema;
197 }
198
204 int32_t GetPageSize() const
205 {
206 return pageSize;
207 }
208
214 void SetPageSize(int32_t pageSize)
215 {
216 this->pageSize = pageSize;
217 }
218
224 void SetMaxRows(int32_t maxRows)
225 {
226 this->maxRows = maxRows;
227 }
228
234 int32_t GetMaxRows() const
235 {
236 return maxRows;
237 }
238
244 void SetTimeout(int64_t timeout)
245 {
246 this->timeout = timeout;
247 }
248
254 int64_t GetTimeout() const
255 {
256 return timeout;
257 }
258
264 bool IsLocal() const
265 {
266 return loc;
267 }
268
274 void SetLocal(bool loc)
275 {
276 this->loc = loc;
277 }
278
284 bool IsDistributedJoins() const
285 {
286 return distributedJoins;
287 }
288
297 void SetDistributedJoins(bool enabled)
298 {
299 distributedJoins = enabled;
300 }
301
307 bool IsEnforceJoinOrder() const
308 {
309 return enforceJoinOrder;
310 }
311
323 void SetEnforceJoinOrder(bool enforce)
324 {
325 enforceJoinOrder = enforce;
326 }
327
335 bool IsLazy() const
336 {
337 return lazy;
338 }
339
355 void SetLazy(bool lazy)
356 {
357 this->lazy = lazy;
358 }
359
365 bool IsCollocated()
366 {
367 return collocated;
368 }
369
381 void SetCollocated(bool collocated)
382 {
383 this->collocated = collocated;
384 }
385
394 template<typename T>
395 void AddArgument(const T& arg)
396 {
397 args.push_back(new impl::thin::CopyableWritableImpl<T>(arg));
398 }
399
408 template<typename Iter>
409 void AddInt8ArrayArgument(Iter begin, Iter end)
410 {
411 args.push_back(new impl::thin::CopyableWritableInt8ArrayImpl<Iter>(begin, end));
412 }
413
417 void ClearArguments()
418 {
419 std::vector<impl::thin::CopyableWritable*>::iterator iter;
420 for (iter = args.begin(); iter != args.end(); ++iter)
421 delete *iter;
422
423 args.clear();
424 }
425
426 private:
428 std::string sql;
429
431 std::string schema;
432
434 int32_t pageSize;
435
437 int32_t maxRows;
438
440 int64_t timeout;
441
443 bool loc;
444
446 bool distributedJoins;
447
449 bool enforceJoinOrder;
450
452 bool lazy;
453
455 bool collocated;
456
458 std::vector<impl::thin::CopyableWritable*> args;
459 };
460 }
461 }
462 }
463 }
464
465 #endif //_IGNITE_THIN_CACHE_QUERY_QUERY_SQL_FIELDS
ignite::thin::cache::query::SqlFieldsQuery::Swap
void Swap(SqlFieldsQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:134
ignite::thin::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:83
ignite::thin::cache::query::SqlFieldsQuery::IsCollocated
bool IsCollocated()
Checks if this query is collocated.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:365
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::thin::cache::query::SqlFieldsQuery::SetMaxRows
void SetMaxRows(int32_t maxRows)
Set maximum number of rows.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:224
ignite::thin::cache::query::SqlFieldsQuery::GetTimeout
int64_t GetTimeout() const
Get query execution timeout in milliseconds.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:254
ignite::thin::cache::query::SqlFieldsQuery::IsLazy
bool IsLazy() const
Gets lazy query execution flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:335
ignite::thin::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:62
ignite::thin::cache::query::SqlFieldsQuery::SetSql
void SetSql(const std::string &sql)
Set SQL string.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:169
ignite::thin::cache::query::SqlFieldsQuery::~SqlFieldsQuery
~SqlFieldsQuery()
Destructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:124
ignite::thin::cache::query::SqlFieldsQuery::SetCollocated
void SetCollocated(bool collocated)
Sets flag defining if this query is collocated.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:381
ignite::thin::cache::query::SqlFieldsQuery
SQL fields query for thin client.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:52
ignite::thin::cache::query::SqlFieldsQuery::SetLocal
void SetLocal(bool loc)
Set local flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:274
ignite::thin::cache::query::SqlFieldsQuery::GetSql
const std::string & GetSql() const
Get SQL string.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:159
ignite::thin::cache::query::SqlFieldsQuery::operator=
SqlFieldsQuery & operator=(const SqlFieldsQuery &other)
Assignment operator.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:109
ignite::thin::cache::query::SqlFieldsQuery::AddInt8ArrayArgument
void AddInt8ArrayArgument(Iter begin, Iter end)
Add int8_t array as an argument.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:409
ignite::thin::cache::query::SqlFieldsQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:417
ignite::thin::cache::query::SqlFieldsQuery::IsEnforceJoinOrder
bool IsEnforceJoinOrder() const
Checks if join order of tables if enforced.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:307
ignite::thin::cache::query::SqlFieldsQuery::IsLocal
bool IsLocal() const
Get local flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:264
ignite::thin::cache::query::SqlFieldsQuery::SetEnforceJoinOrder
void SetEnforceJoinOrder(bool enforce)
Sets flag to enforce join order of tables in the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:323
ignite::thin::cache::query::SqlFieldsQuery::SetDistributedJoins
void SetDistributedJoins(bool enabled)
Specify if distributed joins are enabled for this query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:297
ignite::thin::cache::query::SqlFieldsQuery::SetSchema
void SetSchema(const std::string &schema)
Set schema name for the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:181
ignite::thin::cache::query::SqlFieldsQuery::AddArgument
void AddArgument(const T &arg)
Add argument for the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:395
ignite::thin::cache::query::SqlFieldsQuery::SetPageSize
void SetPageSize(int32_t pageSize)
Set page size.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:214
ignite::thin::cache::query::SqlFieldsQuery::GetMaxRows
int32_t GetMaxRows() const
Get maximum number of rows.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:234
ignite::thin::cache::query::SqlFieldsQuery::GetPageSize
int32_t GetPageSize() const
Get page size.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:204
ignite::thin::cache::query::SqlFieldsQuery::SetLazy
void SetLazy(bool lazy)
Sets lazy query execution flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:355
ignite::thin::cache::query::SqlFieldsQuery::SetTimeout
void SetTimeout(int64_t timeout)
Set query execution timeout in milliseconds.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:244
ignite::thin::cache::query::SqlFieldsQuery::GetSchema
const std::string & GetSchema() const
Get schema name for the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:194
ignite::thin::cache::query::SqlFieldsQuery::IsDistributedJoins
bool IsDistributedJoins() const
Check if distributed joins are enabled for this query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:284