| 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/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 {
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::cache::query::QueryArgumentBase*>::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::cache::query::QueryArgumentBase*>::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
206 void SetLocal(bool loc)
207 {
208 this->loc = loc;
209 }
210
216 bool IsDistributedJoins() const
217 {
218 return distributedJoins;
219 }
220
229 void SetDistributedJoins(bool enabled)
230 {
231 distributedJoins = enabled;
232 }
233
243 template<typename T>
244 void AddArgument(const T& arg)
245 {
246 args.push_back(new impl::cache::query::QueryArgument<T>(arg));
247 }
248
252 void ClearArguments()
253 {
254 std::vector<impl::cache::query::QueryArgumentBase*>::iterator iter;
255 for (iter = args.begin(); iter != args.end(); ++iter)
256 delete *iter;
257
258 args.clear();
259 }
260
266 void Write(binary::BinaryRawWriter& writer) const
267 {
268 writer.WriteBool(loc);
269 writer.WriteString(sql);
270 writer.WriteString(type);
271 writer.WriteInt32(pageSize);
272
273 writer.WriteInt32(static_cast<int32_t>(args.size()));
274
275 std::vector<impl::cache::query::QueryArgumentBase*>::const_iterator it;
276
277 for (it = args.begin(); it != args.end(); ++it)
278 (*it)->Write(writer);
279
280 writer.WriteBool(distributedJoins);
281 writer.WriteInt32(0); // Timeout, ms
282 writer.WriteBool(false); // ReplicatedOnly
283 }
284
285 private:
287 std::string type;
288
290 std::string sql;
291
293 int32_t pageSize;
294
296 bool loc;
297
299 bool distributedJoins;
300
302 std::vector<impl::cache::query::QueryArgumentBase*> args;
303 };
304 }
305 }
306 }
307
308 #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:206
ignite::cache::query::SqlQuery::AddArgument
void AddArgument(const T &arg)
Add argument.
Definition: query_sql.h:244
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:55
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:266
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:252
ignite::cache::query::SqlQuery::SetDistributedJoins
void SetDistributedJoins(bool enabled)
Specify if distributed joins are enabled for this query.
Definition: query_sql.h:229
ignite::cache::query::SqlQuery::IsDistributedJoins
bool IsDistributedJoins() const
Check if distributed joins are enabled for this query.
Definition: query_sql.h:216
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