| Apache Ignite C++

query_sql.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
24 #define _IGNITE_CACHE_QUERY_QUERY_SQL
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 {
44 class SqlQuery
45 {
46 public:
53 SqlQuery(const std::string& type, const std::string& sql) :
54 type(type),
55 sql(sql),
56 pageSize(1024),
57 loc(false),
58 distributedJoins(false),
59 args()
60 {
61 // No-op.
62 }
63
69 SqlQuery(const SqlQuery& other) :
70 type(other.type),
71 sql(other.sql),
72 pageSize(other.pageSize),
73 loc(other.loc),
74 distributedJoins(other.distributedJoins),
75 args()
76 {
77 args.reserve(other.args.size());
78
79 typedef std::vector<impl::WritableObjectBase*>::const_iterator Iter;
80
81 for (Iter i = other.args.begin(); i != other.args.end(); ++i)
82 args.push_back((*i)->Copy());
83 }
84
90 SqlQuery& operator=(const SqlQuery& other)
91 {
92 if (this != &other)
93 {
94 SqlQuery tmp(other);
95
96 Swap(tmp);
97 }
98
99 return *this;
100 }
101
105 ~SqlQuery()
106 {
107 typedef std::vector<impl::WritableObjectBase*>::const_iterator Iter;
108
109 for (Iter it = args.begin(); it != args.end(); ++it)
110 delete *it;
111 }
112
118 void Swap(SqlQuery& other)
119 {
120 if (this != &other)
121 {
122 std::swap(type, other.type);
123 std::swap(sql, other.sql);
124 std::swap(pageSize, other.pageSize);
125 std::swap(loc, other.loc);
126 std::swap(distributedJoins, other.distributedJoins);
127 std::swap(args, other.args);
128 }
129 }
130
136 const std::string& GetType() const
137 {
138 return type;
139 }
140
146 void SetType(const std::string& type)
147 {
148 this->type = type;
149 }
150
156 const std::string& GetSql() const
157 {
158 return sql;
159 }
160
166 void SetSql(const std::string& sql)
167 {
168 this->sql = sql;
169 }
170
176 int32_t GetPageSize() const
177 {
178 return pageSize;
179 }
180
186 void SetPageSize(int32_t pageSize)
187 {
188 this->pageSize = pageSize;
189 }
190
196 bool IsLocal() const
197 {
198 return loc;
199 }
200
208 void SetLocal(bool loc)
209 {
210 this->loc = loc;
211 }
212
218 bool IsDistributedJoins() const
219 {
220 return distributedJoins;
221 }
222
231 void SetDistributedJoins(bool enabled)
232 {
233 distributedJoins = enabled;
234 }
235
245 template<typename T>
246 void AddArgument(const T& arg)
247 {
248 args.push_back(new impl::WritableObject<T>(arg));
249 }
250
254 void ClearArguments()
255 {
256 std::vector<impl::WritableObjectBase*>::iterator iter;
257 for (iter = args.begin(); iter != args.end(); ++iter)
258 delete *iter;
259
260 args.clear();
261 }
262
268 void Write(binary::BinaryRawWriter& writer) const
269 {
270 writer.WriteBool(loc);
271 writer.WriteString(sql);
272 writer.WriteString(type);
273 writer.WriteInt32(pageSize);
274
275 writer.WriteInt32(static_cast<int32_t>(args.size()));
276
277 std::vector<impl::WritableObjectBase*>::const_iterator it;
278
279 for (it = args.begin(); it != args.end(); ++it)
280 (*it)->Write(writer);
281
282 writer.WriteBool(distributedJoins);
283 writer.WriteInt32(0); // Timeout, ms
284 writer.WriteBool(false); // ReplicatedOnly
285 }
286
287 private:
289 std::string type;
290
292 std::string sql;
293
295 int32_t pageSize;
296
298 bool loc;
299
301 bool distributedJoins;
302
304 std::vector<impl::WritableObjectBase*> args;
305 };
306 }
307 }
308 }
309
310 #endif //_IGNITE_CACHE_QUERY_QUERY_SQL
ignite::cache::query::SqlQuery::SetType
void SetType(const std::string &type)
Set type name.
Definition: query_sql.h:146
ignite::cache::query::SqlQuery::SetPageSize
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql.h:186
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::cache::query::SqlQuery::~SqlQuery
~SqlQuery()
Destructor.
Definition: query_sql.h:105
ignite::binary::BinaryRawWriter::WriteInt32
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: binary_raw_writer.cpp:72
ignite::cache::query::SqlQuery::GetType
const std::string & GetType() const
Get type name.
Definition: query_sql.h:136
ignite::cache::query::SqlQuery::operator=
SqlQuery & operator=(const SqlQuery &other)
Assignment operator.
Definition: query_sql.h:90
ignite::cache::query::SqlQuery::SqlQuery
SqlQuery(const SqlQuery &other)
Copy constructor.
Definition: query_sql.h:69
ignite::cache::query::SqlQuery::GetPageSize
int32_t GetPageSize() const
Get page size.
Definition: query_sql.h:176
ignite::cache::query::SqlQuery::SetLocal
void SetLocal(bool loc)
Set local flag.
Definition: query_sql.h:208
ignite::cache::query::SqlQuery::AddArgument
void AddArgument(const T &arg)
Add argument.
Definition: query_sql.h:246
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:62
ignite::cache::query::SqlQuery::GetSql
const std::string & GetSql() const
Get SQL string.
Definition: query_sql.h:156
ignite::cache::query::SqlQuery::SetSql
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql.h:166
ignite::cache::query::SqlQuery::Write
void Write(binary::BinaryRawWriter &writer) const
Write query info to the stream.
Definition: query_sql.h:268
ignite::cache::query::SqlQuery::Swap
void Swap(SqlQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: query_sql.h:118
ignite::binary::BinaryRawWriter::WriteString
void WriteString(const char *val)
Write string.
Definition: binary_raw_writer.cpp:152
ignite::cache::query::SqlQuery::IsLocal
bool IsLocal() const
Get local flag.
Definition: query_sql.h:196
ignite::binary::BinaryRawWriter::WriteBool
void WriteBool(bool val)
Write bool.
Definition: binary_raw_writer.cpp:42
ignite::cache::query::SqlQuery::ClearArguments
void ClearArguments()
Remove all added arguments.
Definition: query_sql.h:254
ignite::cache::query::SqlQuery::SetDistributedJoins
void SetDistributedJoins(bool enabled)
Specify if distributed joins are enabled for this query.
Definition: query_sql.h:231
ignite::cache::query::SqlQuery::IsDistributedJoins
bool IsDistributedJoins() const
Check if distributed joins are enabled for this query.
Definition: query_sql.h:218
ignite::cache::query::SqlQuery::SqlQuery
SqlQuery(const std::string &type, const std::string &sql)
Constructor.
Definition: query_sql.h:53
binary_raw_writer.h
ignite::cache::query::SqlQuery
Sql query.
Definition: query_sql.h:44