| 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(true),
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(true),
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
225 bool IsLazy() const
226 {
227 return lazy;
228 }
229
246 void SetLazy(bool lazy)
247 {
248 this->lazy = lazy;
249 }
250
256 bool IsEnforceJoinOrder() const
257 {
258 return enforceJoinOrder;
259 }
260
271 void SetEnforceJoinOrder(bool enforce)
272 {
273 enforceJoinOrder = enforce;
274 }
275
281 bool IsDistributedJoins() const
282 {
283 return distributedJoins;
284 }
285
294 void SetDistributedJoins(bool enabled)
295 {
296 distributedJoins = enabled;
297 }
298
307 template<typename T>
308 void AddArgument(const T& arg)
309 {
310 args.push_back(new impl::WritableObject<T>(arg));
311 }
312
319 void AddInt8ArrayArgument(const int8_t* src, int32_t len)
320 {
321 args.push_back(new impl::WritableObjectInt8Array(src, len));
322 }
323
327 void ClearArguments()
328 {
329 std::vector<impl::WritableObjectBase*>::iterator iter;
330 for (iter = args.begin(); iter != args.end(); ++iter)
331 delete *iter;
332
333 args.clear();
334 }
335
343 void SetSchema(const std::string& schema)
344 {
345 this->schema = schema;
346 }
347
356 const std::string& GetSchema() const
357 {
358 return schema;
359 }
360
366 void Write(binary::BinaryRawWriter& writer) const
367 {
368 writer.WriteBool(loc);
369 writer.WriteString(sql);
370 writer.WriteInt32(pageSize);
371
372 writer.WriteInt32(static_cast<int32_t>(args.size()));
373
374 std::vector<impl::WritableObjectBase*>::const_iterator it;
375
376 for (it = args.begin(); it != args.end(); ++it)
377 (*it)->Write(writer);
378
379 writer.WriteBool(distributedJoins);
380 writer.WriteBool(enforceJoinOrder);
381 writer.WriteBool(lazy);
382 writer.WriteInt32(0); // Timeout, ms
383 writer.WriteBool(false); // ReplicatedOnly
384 writer.WriteBool(false); // Colocated
385
386 if (schema.empty())
387 writer.WriteNull();
388 else
389 writer.WriteString(schema);
390
391 writer.WriteInt32Array(NULL, 0); // Partitions
392 writer.WriteInt32(1); // UpdateBatchSize
393 }
394
395 private:
397 std::string sql;
398
400 std::string schema;
401
403 int32_t pageSize;
404
406 bool loc;
407
409 bool distributedJoins;
410
412 bool enforceJoinOrder;
413
415 bool lazy;
416
418 std::vector<impl::WritableObjectBase*> args;
419 };
420 }
421 }
422 }
423
424 #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:246
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:281
ignite::cache::query::SqlFieldsQuery::AddArgument
void AddArgument(const T &arg)
Add argument.
Definition: core/include/ignite/cache/query/query_sql_fields.h:308
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:343
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:319
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:366
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:271
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:356
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:327
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:256
ignite::cache::query::SqlFieldsQuery::IsLazy
bool IsLazy() const
Gets lazy query execution flag.
Definition: core/include/ignite/cache/query/query_sql_fields.h:225
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:294
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