GridGain C++
thin-client/include/ignite/thin/cache/query/query_sql_fields.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_THIN_CACHE_QUERY_QUERY_SQL_FIELDS
23 #define _IGNITE_THIN_CACHE_QUERY_QUERY_SQL_FIELDS
24 
25 #include <stdint.h>
26 #include <string>
27 #include <vector>
28 
29 #include <ignite/impl/thin/copyable_writable.h>
30 
31 namespace ignite
32 {
33  namespace impl
34  {
35  namespace thin
36  {
37  // Forward declaration
38  class SqlFieldsQueryRequest;
39  }
40  }
41 
42  namespace thin
43  {
44  namespace cache
45  {
46  namespace query
47  {
52  {
53  public:
54  friend class ignite::impl::thin::SqlFieldsQueryRequest;
55 
61  explicit SqlFieldsQuery(const std::string& sql) :
62  sql(sql),
63  schema(),
64  pageSize(1024),
65  maxRows(0),
66  timeout(0),
67  loc(false),
68  distributedJoins(false),
69  enforceJoinOrder(false),
70  lazy(false),
71  collocated(false),
72  parts(),
73  updateBatchSize(1),
74  args()
75  {
76  // No-op.
77  }
78 
85  sql(other.sql),
86  schema(other.schema),
87  pageSize(other.pageSize),
88  maxRows(other.maxRows),
89  timeout(other.timeout),
90  loc(other.loc),
91  distributedJoins(other.distributedJoins),
92  enforceJoinOrder(other.enforceJoinOrder),
93  lazy(other.lazy),
94  collocated(other.collocated),
95  parts(other.parts),
96  updateBatchSize(other.updateBatchSize),
97  args()
98  {
99  args.reserve(other.args.size());
100 
101  typedef std::vector<impl::thin::CopyableWritable*>::const_iterator Iter;
102 
103  for (Iter i = other.args.begin(); i != other.args.end(); ++i)
104  args.push_back((*i)->Copy());
105  }
106 
113  {
114  if (this != &other)
115  {
116  SqlFieldsQuery tmp(other);
117 
118  Swap(tmp);
119  }
120 
121  return *this;
122  }
123 
128  {
129  ClearArguments();
130  }
131 
137  void Swap(SqlFieldsQuery& other)
138  {
139  if (this != &other)
140  {
141  using std::swap;
142 
143  swap(sql, other.sql);
144  swap(schema, other.schema);
145  swap(pageSize, other.pageSize);
146  swap(maxRows, other.maxRows);
147  swap(timeout, other.timeout);
148  swap(loc, other.loc);
149  swap(distributedJoins, other.distributedJoins);
150  swap(enforceJoinOrder, other.enforceJoinOrder);
151  swap(lazy, other.lazy);
152  swap(collocated, other.collocated);
153  swap(parts, other.parts);
154  swap(args, other.args);
155  }
156  }
157 
163  const std::string& GetSql() const
164  {
165  return sql;
166  }
167 
173  void SetSql(const std::string& sql)
174  {
175  this->sql = sql;
176  }
177 
185  void SetSchema(const std::string& schema)
186  {
187  this->schema = schema;
188  }
189 
198  const std::string& GetSchema() const
199  {
200  return schema;
201  }
202 
208  int32_t GetPageSize() const
209  {
210  return pageSize;
211  }
212 
218  void SetPageSize(int32_t pageSize)
219  {
220  this->pageSize = pageSize;
221  }
222 
228  void SetMaxRows(int32_t maxRows)
229  {
230  this->maxRows = maxRows;
231  }
232 
238  int32_t GetMaxRows() const
239  {
240  return maxRows;
241  }
242 
248  void SetTimeout(int64_t timeout)
249  {
250  this->timeout = timeout;
251  }
252 
258  int64_t GetTimeout() const
259  {
260  return timeout;
261  }
262 
270  bool IsLocal() const
271  {
272  return loc;
273  }
274 
282  void SetLocal(bool loc)
283  {
284  this->loc = loc;
285  }
286 
292  bool IsDistributedJoins() const
293  {
294  return distributedJoins;
295  }
296 
305  void SetDistributedJoins(bool enabled)
306  {
307  distributedJoins = enabled;
308  }
309 
315  bool IsEnforceJoinOrder() const
316  {
317  return enforceJoinOrder;
318  }
319 
331  void SetEnforceJoinOrder(bool enforce)
332  {
333  enforceJoinOrder = enforce;
334  }
335 
343  bool IsLazy() const
344  {
345  return lazy;
346  }
347 
363  void SetLazy(bool lazy)
364  {
365  this->lazy = lazy;
366  }
367 
374  {
375  return collocated;
376  }
377 
389  void SetCollocated(bool collocated)
390  {
391  this->collocated = collocated;
392  }
393 
401  const std::vector<int32_t>& GetPartitions() const
402  {
403  return parts;
404  }
405 
413  void SetPartitions(const std::vector<int32_t>& partitions)
414  {
415  this->parts = partitions;
416  }
417 
423  void SetUpdateBatchSize(int32_t size)
424  {
425  updateBatchSize = size;
426  }
427 
433  int32_t GetUpdateBatchSize() const
434  {
435  return updateBatchSize;
436  }
437 
446  template<typename T>
447  void AddArgument(const T& arg)
448  {
449  args.push_back(new impl::thin::CopyableWritableImpl<T>(arg));
450  }
451 
460  template<typename Iter>
461  void AddInt8ArrayArgument(Iter begin, Iter end)
462  {
463  args.push_back(new impl::thin::CopyableWritableInt8ArrayImpl<Iter>(begin, end));
464  }
465 
470  {
471  std::vector<impl::thin::CopyableWritable*>::iterator iter;
472  for (iter = args.begin(); iter != args.end(); ++iter)
473  delete *iter;
474 
475  args.clear();
476  }
477 
478  private:
480  std::string sql;
481 
483  std::string schema;
484 
486  int32_t pageSize;
487 
489  int32_t maxRows;
490 
492  int64_t timeout;
493 
495  bool loc;
496 
498  bool distributedJoins;
499 
501  bool enforceJoinOrder;
502 
504  bool lazy;
505 
507  bool collocated;
508 
510  std::vector<int32_t> parts;
511 
513  int32_t updateBatchSize;
514 
516  std::vector<impl::thin::CopyableWritable*> args;
517  };
518  }
519  }
520  }
521 }
522 
523 #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:137
ignite::thin::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:84
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:373
ignite
Ignite API.
Definition: cache.h:47
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:228
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:258
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:423
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:343
ignite::thin::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:61
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:173
ignite::thin::cache::query::SqlFieldsQuery::~SqlFieldsQuery
~SqlFieldsQuery()
Destructor.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:127
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:389
ignite::thin::cache::query::SqlFieldsQuery
SQL fields query for thin client.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:51
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:282
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:163
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:112
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:461
ignite::thin::cache::query::SqlFieldsQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:469
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:433
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:315
ignite::thin::cache::query::SqlFieldsQuery::IsLocal
bool IsLocal() const
Get local flag.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:270
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:413
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:331
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:305
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:185
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:447
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:218
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:238
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:208
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:363
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:248
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:198
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:401
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:292