| Apache Ignite C++

core/include/ignite/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_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
30 #include <ignite/impl/cache/query/query_argument.h>
31 #include <ignite/binary/binary_raw_writer.h>
32
33 namespace ignite
34 {
35 namespace cache
36 {
37 namespace query
38 {
42 class SqlFieldsQuery
43 {
44 public:
50 SqlFieldsQuery(const std::string& sql) :
51 sql(sql),
52 schema(),
53 pageSize(1024),
54 loc(false),
55 distributedJoins(false),
56 enforceJoinOrder(false),
57 lazy(false),
58 args()
59 {
60 // No-op.
61 }
62
69 SqlFieldsQuery(const std::string& sql, bool loc) :
70 sql(sql),
71 schema(),
72 pageSize(1024),
73 loc(loc),
74 distributedJoins(false),
75 enforceJoinOrder(false),
76 lazy(false),
77 args()
78 {
79 // No-op.
80 }
81
87 SqlFieldsQuery(const SqlFieldsQuery& other) :
88 sql(other.sql),
89 schema(other.schema),
90 pageSize(other.pageSize),
91 loc(other.loc),
92 distributedJoins(other.distributedJoins),
93 enforceJoinOrder(other.enforceJoinOrder),
94 lazy(other.lazy),
95 args()
96 {
97 args.reserve(other.args.size());
98
99 typedef std::vector<impl::cache::query::QueryArgumentBase*>::const_iterator Iter;
100
101 for (Iter i = other.args.begin(); i != other.args.end(); ++i)
102 args.push_back((*i)->Copy());
103 }
104
110 SqlFieldsQuery& operator=(const SqlFieldsQuery& other)
111 {
112 if (this != &other)
113 {
114 SqlFieldsQuery tmp(other);
115
116 Swap(tmp);
117 }
118
119 return *this;
120 }
121
125 ~SqlFieldsQuery()
126 {
127 typedef std::vector<impl::cache::query::QueryArgumentBase*>::const_iterator Iter;
128
129 for (Iter it = args.begin(); it != args.end(); ++it)
130 delete *it;
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(loc, other.loc);
148 swap(distributedJoins, other.distributedJoins);
149 swap(enforceJoinOrder, other.enforceJoinOrder);
150 swap(lazy, other.lazy);
151 swap(args, other.args);
152 }
153 }
154
160 const std::string& GetSql() const
161 {
162 return sql;
163 }
164
170 void SetSql(const std::string& sql)
171 {
172 this->sql = sql;
173 }
174
180 int32_t GetPageSize() const
181 {
182 return pageSize;
183 }
184
190 void SetPageSize(int32_t pageSize)
191 {
192 this->pageSize = pageSize;
193 }
194
200 bool IsLocal() const
201 {
202 return loc;
203 }
204
210 void SetLocal(bool loc)
211 {
212 this->loc = loc;
213 }
214
222 bool IsLazy() const
223 {
224 return lazy;
225 }
226
242 void SetLazy(bool lazy)
243 {
244 this->lazy = lazy;
245 }
246
252 bool IsEnforceJoinOrder() const
253 {
254 return enforceJoinOrder;
255 }
256
267 void SetEnforceJoinOrder(bool enforce)
268 {
269 enforceJoinOrder = enforce;
270 }
271
277 bool IsDistributedJoins() const
278 {
279 return distributedJoins;
280 }
281
290 void SetDistributedJoins(bool enabled)
291 {
292 distributedJoins = enabled;
293 }
294
303 template<typename T>
304 void AddArgument(const T& arg)
305 {
306 args.push_back(new impl::cache::query::QueryArgument<T>(arg));
307 }
308
315 void AddInt8ArrayArgument(const int8_t* src, int32_t len)
316 {
317 args.push_back(new impl::cache::query::QueryInt8ArrayArgument(src, len));
318 }
319
323 void ClearArguments()
324 {
325 std::vector<impl::cache::query::QueryArgumentBase*>::iterator iter;
326 for (iter = args.begin(); iter != args.end(); ++iter)
327 delete *iter;
328
329 args.clear();
330 }
331
339 void SetSchema(const std::string& schema)
340 {
341 this->schema = schema;
342 }
343
352 const std::string& GetSchema() const
353 {
354 return schema;
355 }
356
362 void Write(binary::BinaryRawWriter& writer) const
363 {
364 writer.WriteBool(loc);
365 writer.WriteString(sql);
366 writer.WriteInt32(pageSize);
367
368 writer.WriteInt32(static_cast<int32_t>(args.size()));
369
370 std::vector<impl::cache::query::QueryArgumentBase*>::const_iterator it;
371
372 for (it = args.begin(); it != args.end(); ++it)
373 (*it)->Write(writer);
374
375 writer.WriteBool(distributedJoins);
376 writer.WriteBool(enforceJoinOrder);
377 writer.WriteBool(lazy);
378 writer.WriteInt32(0); // Timeout, ms
379 writer.WriteBool(false); // ReplicatedOnly
380 writer.WriteBool(false); // Colocated
381
382 if (schema.empty())
383 writer.WriteNull();
384 else
385 writer.WriteString(schema);
386
387 writer.WriteInt32Array(NULL, 0); // Partitions
388 writer.WriteInt32(1); // UpdateBatchSize
389 }
390
391 private:
393 std::string sql;
394
396 std::string schema;
397
399 int32_t pageSize;
400
402 bool loc;
403
405 bool distributedJoins;
406
408 bool enforceJoinOrder;
409
411 bool lazy;
412
414 std::vector<impl::cache::query::QueryArgumentBase*> args;
415 };
416 }
417 }
418 }
419
420 #endif //_IGNITE_CACHE_QUERY_QUERY_SQL_FIELDS
ignite::cache::query::SqlFieldsQuery::SetLazy
void SetLazy(bool lazy)
Sets lazy query execution flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:242
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: core/include/ignite/cache/query/query_sql_fields.h:87
ignite::binary::BinaryRawWriter::WriteInt32
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: binary_raw_writer.cpp:72
ignite::cache::query::SqlFieldsQuery::IsDistributedJoins
bool IsDistributedJoins() const
Check if distributed joins are enabled for this query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:277
ignite::cache::query::SqlFieldsQuery::AddArgument
void AddArgument(const T &arg)
Add argument.
Definition: core/include/ignite/cache/query/query_sql_fields.h:304
ignite::cache::query::SqlFieldsQuery::GetSql
const std::string & GetSql() const
Get SQL string.
Definition: core/include/ignite/cache/query/query_sql_fields.h:160
ignite::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const std::string &sql, bool loc)
Constructor.
Definition: core/include/ignite/cache/query/query_sql_fields.h:69
ignite::cache::query::SqlFieldsQuery::Swap
void Swap(SqlFieldsQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: core/include/ignite/cache/query/query_sql_fields.h:138
ignite::cache::query::SqlFieldsQuery::SetSchema
void SetSchema(const std::string &schema)
Set schema name for the query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:339
ignite::cache::query::SqlFieldsQuery::SetPageSize
void SetPageSize(int32_t pageSize)
Set page size.
Definition: core/include/ignite/cache/query/query_sql_fields.h:190
ignite::binary::BinaryRawWriter::WriteInt32Array
void WriteInt32Array(const int32_t *val, int32_t len)
Write array of 32-byte signed integers.
Definition: binary_raw_writer.cpp:77
ignite::cache::query::SqlFieldsQuery::AddInt8ArrayArgument
void AddInt8ArrayArgument(const int8_t *src, int32_t len)
Add array of bytes as an argument.
Definition: core/include/ignite/cache/query/query_sql_fields.h:315
ignite::cache::query::SqlFieldsQuery::Write
void Write(binary::BinaryRawWriter &writer) const
Write query info to the stream.
Definition: core/include/ignite/cache/query/query_sql_fields.h:362
ignite::cache::query::SqlFieldsQuery::SetLocal
void SetLocal(bool loc)
Set local flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:210
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:55
ignite::cache::query::SqlFieldsQuery::operator=
SqlFieldsQuery & operator=(const SqlFieldsQuery &other)
Assignment operator.
Definition: core/include/ignite/cache/query/query_sql_fields.h:110
ignite::cache::query::SqlFieldsQuery::SetEnforceJoinOrder
void SetEnforceJoinOrder(bool enforce)
Sets flag to enforce join order of tables in the query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:267
ignite::binary::BinaryRawWriter::WriteString
void WriteString(const char *val)
Write string.
Definition: binary_raw_writer.cpp:152
ignite::cache::query::SqlFieldsQuery::~SqlFieldsQuery
~SqlFieldsQuery()
Destructor.
Definition: core/include/ignite/cache/query/query_sql_fields.h:125
ignite::cache::query::SqlFieldsQuery::GetSchema
const std::string & GetSchema() const
Get schema name for the query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:352
ignite::binary::BinaryRawWriter::WriteBool
void WriteBool(bool val)
Write bool.
Definition: binary_raw_writer.cpp:42
ignite::cache::query::SqlFieldsQuery::SetSql
void SetSql(const std::string &sql)
Set SQL string.
Definition: core/include/ignite/cache/query/query_sql_fields.h:170
ignite::cache::query::SqlFieldsQuery::SqlFieldsQuery
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: core/include/ignite/cache/query/query_sql_fields.h:50
ignite::cache::query::SqlFieldsQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: core/include/ignite/cache/query/query_sql_fields.h:323
ignite::cache::query::SqlFieldsQuery
Sql fields query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:42
ignite::cache::query::SqlFieldsQuery::GetPageSize
int32_t GetPageSize() const
Get page size.
Definition: core/include/ignite/cache/query/query_sql_fields.h:180
binary_raw_writer.h
ignite::cache::query::SqlFieldsQuery::IsEnforceJoinOrder
bool IsEnforceJoinOrder() const
Checks if join order of tables if enforced.
Definition: core/include/ignite/cache/query/query_sql_fields.h:252
ignite::cache::query::SqlFieldsQuery::IsLazy
bool IsLazy() const
Gets lazy query execution flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:222
ignite::cache::query::SqlFieldsQuery::SetDistributedJoins
void SetDistributedJoins(bool enabled)
Specify if distributed joins are enabled for this query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:290
ignite::binary::BinaryRawWriter::WriteNull
void WriteNull()
Write NULL value.
Definition: binary_raw_writer.cpp:177
ignite::cache::query::SqlFieldsQuery::IsLocal
bool IsLocal() const
Get local flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:200