| 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 parts(),
74 updateBatchSize(1),
75 args()
76 {
77 // No-op.
78 }
79
85 SqlFieldsQuery(const SqlFieldsQuery& other) :
86 sql(other.sql),
87 schema(other.schema),
88 pageSize(other.pageSize),
89 maxRows(other.maxRows),
90 timeout(other.timeout),
91 loc(other.loc),
92 distributedJoins(other.distributedJoins),
93 enforceJoinOrder(other.enforceJoinOrder),
94 lazy(other.lazy),
95 collocated(other.collocated),
96 parts(other.parts),
97 updateBatchSize(other.updateBatchSize),
98 args()
99 {
100 args.reserve(other.args.size());
101
102 typedef std::vector<impl::thin::CopyableWritable*>::const_iterator Iter;
103
104 for (Iter i = other.args.begin(); i != other.args.end(); ++i)
105 args.push_back((*i)->Copy());
106 }
107
113 SqlFieldsQuery& operator=(const SqlFieldsQuery& other)
114 {
115 if (this != &other)
116 {
117 SqlFieldsQuery tmp(other);
118
119 Swap(tmp);
120 }
121
122 return *this;
123 }
124
128 ~SqlFieldsQuery()
129 {
130 ClearArguments();
131 }
132
138 void Swap(SqlFieldsQuery& other)
139 {
140 if (this != &other)
141 {
142 using std::swap;
143
144 swap(sql, other.sql);
145 swap(schema, other.schema);
146 swap(pageSize, other.pageSize);
147 swap(maxRows, other.maxRows);
148 swap(timeout, other.timeout);
149 swap(loc, other.loc);
150 swap(distributedJoins, other.distributedJoins);
151 swap(enforceJoinOrder, other.enforceJoinOrder);
152 swap(lazy, other.lazy);
153 swap(collocated, other.collocated);
154 swap(parts, other.parts);
155 swap(args, other.args);
156 }
157 }
158
164 const std::string& GetSql() const
165 {
166 return sql;
167 }
168
174 void SetSql(const std::string& sql)
175 {
176 this->sql = sql;
177 }
178
186 void SetSchema(const std::string& schema)
187 {
188 this->schema = schema;
189 }
190
199 const std::string& GetSchema() const
200 {
201 return schema;
202 }
203
209 int32_t GetPageSize() const
210 {
211 return pageSize;
212 }
213
219 void SetPageSize(int32_t pageSize)
220 {
221 this->pageSize = pageSize;
222 }
223
229 void SetMaxRows(int32_t maxRows)
230 {
231 this->maxRows = maxRows;
232 }
233
239 int32_t GetMaxRows() const
240 {
241 return maxRows;
242 }
243
249 void SetTimeout(int64_t timeout)
250 {
251 this->timeout = timeout;
252 }
253
259 int64_t GetTimeout() const
260 {
261 return timeout;
262 }
263
271 bool IsLocal() const
272 {
273 return loc;
274 }
275
283 void SetLocal(bool loc)
284 {
285 this->loc = loc;
286 }
287
293 bool IsDistributedJoins() const
294 {
295 return distributedJoins;
296 }
297
306 void SetDistributedJoins(bool enabled)
307 {
308 distributedJoins = enabled;
309 }
310
316 bool IsEnforceJoinOrder() const
317 {
318 return enforceJoinOrder;
319 }
320
332 void SetEnforceJoinOrder(bool enforce)
333 {
334 enforceJoinOrder = enforce;
335 }
336
344 bool IsLazy() const
345 {
346 return lazy;
347 }
348
364 void SetLazy(bool lazy)
365 {
366 this->lazy = lazy;
367 }
368
374 bool IsCollocated()
375 {
376 return collocated;
377 }
378
390 void SetCollocated(bool collocated)
391 {
392 this->collocated = collocated;
393 }
394
402 const std::vector<int32_t>& GetPartitions() const
403 {
404 return parts;
405 }
406
414 void SetPartitions(const std::vector<int32_t>& partitions)
415 {
416 this->parts = partitions;
417 }
418
424 void SetUpdateBatchSize(int32_t size)
425 {
426 updateBatchSize = size;
427 }
428
434 int32_t GetUpdateBatchSize() const
435 {
436 return updateBatchSize;
437 }
438
447 template<typename T>
448 void AddArgument(const T& arg)
449 {
450 args.push_back(new impl::thin::CopyableWritableImpl<T>(arg));
451 }
452
461 template<typename Iter>
462 void AddInt8ArrayArgument(Iter begin, Iter end)
463 {
464 args.push_back(new impl::thin::CopyableWritableInt8ArrayImpl<Iter>(begin, end));
465 }
466
470 void ClearArguments()
471 {
472 std::vector<impl::thin::CopyableWritable*>::iterator iter;
473 for (iter = args.begin(); iter != args.end(); ++iter)
474 delete *iter;
475
476 args.clear();
477 }
478
479 private:
481 std::string sql;
482
484 std::string schema;
485
487 int32_t pageSize;
488
490 int32_t maxRows;
491
493 int64_t timeout;
494
496 bool loc;
497
499 bool distributedJoins;
500
502 bool enforceJoinOrder;
503
505 bool lazy;
506
508 bool collocated;
509
511 std::vector<int32_t> parts;
512
514 int32_t updateBatchSize;
515
517 std::vector<impl::thin::CopyableWritable*> args;
518 };
519 }
520 }
521 }
522 }
523
524 #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:138
ignite::thin::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:85
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:374
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:229
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:259
ignite::thin::cache::query::SqlFieldsQuery::SetUpdateBatchSize
void SetUpdateBatchSize(int32_t size)
Set batch size for update queries.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:424
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:344
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:174
ignite::thin::cache::query::SqlFieldsQuery::~SqlFieldsQuery
~SqlFieldsQuery()
Destructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:128
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:390
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:283
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:164
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:113
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:462
ignite::thin::cache::query::SqlFieldsQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:470
ignite::thin::cache::query::SqlFieldsQuery::GetUpdateBatchSize
int32_t GetUpdateBatchSize() const
Get batch size for update queries.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:434
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:316
ignite::thin::cache::query::SqlFieldsQuery::IsLocal
bool IsLocal() const
Get local flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:271
ignite::thin::cache::query::SqlFieldsQuery::SetPartitions
void SetPartitions(const std::vector< int32_t > &partitions)
Set partitions for the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:414
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:332
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:306
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:186
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:448
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:219
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:239
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:209
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:364
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:249
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:199
ignite::thin::cache::query::SqlFieldsQuery::GetPartitions
const std::vector< int32_t > & GetPartitions() const
Get partitions for the query.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:402
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:293