| 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(true),
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
345 bool IsLazy() const
346 {
347 return lazy;
348 }
349
366 void SetLazy(bool lazy)
367 {
368 this->lazy = lazy;
369 }
370
376 bool IsCollocated()
377 {
378 return collocated;
379 }
380
392 void SetCollocated(bool collocated)
393 {
394 this->collocated = collocated;
395 }
396
404 const std::vector<int32_t>& GetPartitions() const
405 {
406 return parts;
407 }
408
416 void SetPartitions(const std::vector<int32_t>& partitions)
417 {
418 this->parts = partitions;
419 }
420
426 void SetUpdateBatchSize(int32_t size)
427 {
428 updateBatchSize = size;
429 }
430
436 int32_t GetUpdateBatchSize() const
437 {
438 return updateBatchSize;
439 }
440
449 template<typename T>
450 void AddArgument(const T& arg)
451 {
452 args.push_back(new impl::thin::CopyableWritableImpl<T>(arg));
453 }
454
463 template<typename Iter>
464 void AddInt8ArrayArgument(Iter begin, Iter end)
465 {
466 args.push_back(new impl::thin::CopyableWritableInt8ArrayImpl<Iter>(begin, end));
467 }
468
472 void ClearArguments()
473 {
474 std::vector<impl::thin::CopyableWritable*>::iterator iter;
475 for (iter = args.begin(); iter != args.end(); ++iter)
476 delete *iter;
477
478 args.clear();
479 }
480
481 private:
483 std::string sql;
484
486 std::string schema;
487
489 int32_t pageSize;
490
492 int32_t maxRows;
493
495 int64_t timeout;
496
498 bool loc;
499
501 bool distributedJoins;
502
504 bool enforceJoinOrder;
505
507 bool lazy;
508
510 bool collocated;
511
513 std::vector<int32_t> parts;
514
516 int32_t updateBatchSize;
517
519 std::vector<impl::thin::CopyableWritable*> args;
520 };
521 }
522 }
523 }
524 }
525
526 #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:376
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:426
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:345
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:392
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:464
ignite::thin::cache::query::SqlFieldsQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:472
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:436
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:416
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:450
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:366
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:404
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