Apache Ignite C++
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_CACHE_QUERY_QUERY_SQL_FIELDS
24 #define _IGNITE_CACHE_QUERY_QUERY_SQL_FIELDS
25 
26 #include <stdint.h>
27 #include <string>
28 #include <vector>
29 
32 
33 namespace ignite
34 {
35  namespace cache
36  {
37  namespace query
38  {
43  {
44  public:
50  SqlFieldsQuery(const std::string& sql) :
51  sql(sql),
52  pageSize(1024),
53  loc(false),
54  distributedJoins(false),
55  enforceJoinOrder(false),
56  args()
57  {
58  // No-op.
59  }
60 
67  SqlFieldsQuery(const std::string& sql, bool loc) :
68  sql(sql),
69  pageSize(1024),
70  loc(false),
71  distributedJoins(false),
72  enforceJoinOrder(false),
73  args()
74  {
75  // No-op.
76  }
77 
84  sql(other.sql),
85  pageSize(other.pageSize),
86  loc(other.loc),
87  distributedJoins(other.distributedJoins),
88  enforceJoinOrder(other.enforceJoinOrder),
89  args()
90  {
91  args.reserve(other.args.size());
92 
93  typedef std::vector<QueryArgumentBase*>::const_iterator Iter;
94 
95  for (Iter i = other.args.begin(); i != other.args.end(); ++i)
96  args.push_back((*i)->Copy());
97  }
98 
105  {
106  if (this != &other)
107  {
108  SqlFieldsQuery tmp(other);
109 
110  Swap(tmp);
111  }
112 
113  return *this;
114  }
115 
120  {
121  typedef std::vector<QueryArgumentBase*>::const_iterator Iter;
122 
123  for (Iter it = args.begin(); it != args.end(); ++it)
124  delete *it;
125  }
126 
132  void Swap(SqlFieldsQuery& other)
133  {
134  if (this != &other)
135  {
136  std::swap(sql, other.sql);
137  std::swap(pageSize, other.pageSize);
138  std::swap(loc, other.loc);
139  std::swap(distributedJoins, other.distributedJoins);
140  std::swap(enforceJoinOrder, other.enforceJoinOrder);
141  std::swap(args, other.args);
142  }
143  }
144 
150  const std::string& GetSql() const
151  {
152  return sql;
153  }
154 
160  void SetSql(const std::string& sql)
161  {
162  this->sql = sql;
163  }
164 
170  int32_t GetPageSize() const
171  {
172  return pageSize;
173  }
174 
180  void SetPageSize(int32_t pageSize)
181  {
182  this->pageSize = pageSize;
183  }
184 
190  bool IsLocal() const
191  {
192  return loc;
193  }
194 
200  void SetLocal(bool loc)
201  {
202  this->loc = loc;
203  }
204 
210  bool IsEnforceJoinOrder() const
211  {
212  return enforceJoinOrder;
213  }
214 
227  void SetEnforceJoinOrder(bool enforce)
228  {
229  enforceJoinOrder = enforce;
230  }
231 
237  bool IsDistributedJoins() const
238  {
239  return distributedJoins;
240  }
241 
250  void SetDistributedJoins(bool enabled)
251  {
252  distributedJoins = enabled;
253  }
254 
264  template<typename T>
265  void AddArgument(const T& arg)
266  {
267  args.push_back(new QueryArgument<T>(arg));
268  }
269 
275  void Write(binary::BinaryRawWriter& writer) const
276  {
277  writer.WriteBool(loc);
278  writer.WriteString(sql);
279  writer.WriteInt32(pageSize);
280 
281  writer.WriteInt32(static_cast<int32_t>(args.size()));
282 
283  for (std::vector<QueryArgumentBase*>::const_iterator it = args.begin(); it != args.end(); ++it)
284  (*it)->Write(writer);
285 
286  writer.WriteBool(distributedJoins);
287  writer.WriteBool(enforceJoinOrder);
288  }
289 
290  private:
292  std::string sql;
293 
295  int32_t pageSize;
296 
298  bool loc;
299 
301  bool distributedJoins;
302 
304  bool enforceJoinOrder;
305 
307  std::vector<QueryArgumentBase*> args;
308  };
309  }
310  }
311 }
312 
313 #endif //_IGNITE_CACHE_QUERY_QUERY_SQL_FIELDS
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql_fields.h:180
bool IsDistributedJoins() const
Check if distributed joins are enabled for this query.
Definition: query_sql_fields.h:237
void Swap(SqlFieldsQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: query_sql_fields.h:132
Declares ignite::binary::BinaryRawWriter class.
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: binary_raw_writer.cpp:72
void AddArgument(const T &arg)
Add argument.
Definition: query_sql_fields.h:265
int32_t GetPageSize() const
Get page size.
Definition: query_sql_fields.h:170
void SetEnforceJoinOrder(bool enforce)
Sets flag to enforce join order of tables in the query.
Definition: query_sql_fields.h:227
SqlFieldsQuery(const std::string &sql, bool loc)
Constructor.
Definition: query_sql_fields.h:67
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql_fields.h:160
void SetLocal(bool loc)
Set local flag.
Definition: query_sql_fields.h:200
Sql fields query.
Definition: query_sql_fields.h:42
void Write(binary::BinaryRawWriter &writer) const
Write query info to the stream.
Definition: query_sql_fields.h:275
void WriteString(const char *val)
Write string.
Definition: binary_raw_writer.cpp:142
bool IsEnforceJoinOrder() const
Checks if join order of tables if enforced.
Definition: query_sql_fields.h:210
Declares ignite::cache::query::QueryArgument class template and ignite::cache::query::QueryArgumentBa...
bool IsLocal() const
Get local flag.
Definition: query_sql_fields.h:190
Binary raw writer.
Definition: binary_raw_writer.h:55
void WriteBool(bool val)
Write bool.
Definition: binary_raw_writer.cpp:42
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: query_sql_fields.h:50
~SqlFieldsQuery()
Destructor.
Definition: query_sql_fields.h:119
const std::string & GetSql() const
Get SQL string.
Definition: query_sql_fields.h:150
Apache Ignite API.
Definition: cache.h:43
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: query_sql_fields.h:83
Query argument class template.
Definition: query_argument.h:72
void SetDistributedJoins(bool enabled)
Specify if distributed joins are enabled for this query.
Definition: query_sql_fields.h:250
SqlFieldsQuery & operator=(const SqlFieldsQuery &other)
Assignment operator.
Definition: query_sql_fields.h:104