| 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/writable_object.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::WritableObjectBase*>::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::WritableObjectBase*>::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
212 void SetLocal(bool loc)
213 {
214 this->loc = loc;
215 }
216
224 bool IsLazy() const
225 {
226 return lazy;
227 }
228
244 void SetLazy(bool lazy)
245 {
246 this->lazy = lazy;
247 }
248
254 bool IsEnforceJoinOrder() const
255 {
256 return enforceJoinOrder;
257 }
258
269 void SetEnforceJoinOrder(bool enforce)
270 {
271 enforceJoinOrder = enforce;
272 }
273
279 bool IsDistributedJoins() const
280 {
281 return distributedJoins;
282 }
283
292 void SetDistributedJoins(bool enabled)
293 {
294 distributedJoins = enabled;
295 }
296
305 template<typename T>
306 void AddArgument(const T& arg)
307 {
308 args.push_back(new impl::WritableObject<T>(arg));
309 }
310
317 void AddInt8ArrayArgument(const int8_t* src, int32_t len)
318 {
319 args.push_back(new impl::WritableObjectInt8Array(src, len));
320 }
321
325 void ClearArguments()
326 {
327 std::vector<impl::WritableObjectBase*>::iterator iter;
328 for (iter = args.begin(); iter != args.end(); ++iter)
329 delete *iter;
330
331 args.clear();
332 }
333
341 void SetSchema(const std::string& schema)
342 {
343 this->schema = schema;
344 }
345
354 const std::string& GetSchema() const
355 {
356 return schema;
357 }
358
364 void Write(binary::BinaryRawWriter& writer) const
365 {
366 writer.WriteBool(loc);
367 writer.WriteString(sql);
368 writer.WriteInt32(pageSize);
369
370 writer.WriteInt32(static_cast<int32_t>(args.size()));
371
372 std::vector<impl::WritableObjectBase*>::const_iterator it;
373
374 for (it = args.begin(); it != args.end(); ++it)
375 (*it)->Write(writer);
376
377 writer.WriteBool(distributedJoins);
378 writer.WriteBool(enforceJoinOrder);
379 writer.WriteBool(lazy);
380 writer.WriteInt32(0); // Timeout, ms
381 writer.WriteBool(false); // ReplicatedOnly
382 writer.WriteBool(false); // Colocated
383
384 if (schema.empty())
385 writer.WriteNull();
386 else
387 writer.WriteString(schema);
388
389 writer.WriteInt32Array(NULL, 0); // Partitions
390 writer.WriteInt32(1); // UpdateBatchSize
391 }
392
393 private:
395 std::string sql;
396
398 std::string schema;
399
401 int32_t pageSize;
402
404 bool loc;
405
407 bool distributedJoins;
408
410 bool enforceJoinOrder;
411
413 bool lazy;
414
416 std::vector<impl::WritableObjectBase*> args;
417 };
418 }
419 }
420 }
421
422 #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:244
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:279
ignite::cache::query::SqlFieldsQuery::AddArgument
void AddArgument(const T &arg)
Add argument.
Definition: core/include/ignite/cache/query/query_sql_fields.h:306
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:341
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:317
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:364
ignite::cache::query::SqlFieldsQuery::SetLocal
void SetLocal(bool loc)
Set local flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:212
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:62
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:269
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:354
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:325
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:254
ignite::cache::query::SqlFieldsQuery::IsLazy
bool IsLazy() const
Gets lazy query execution flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:224
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:292
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