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_SQL
24 #define _IGNITE_CACHE_QUERY_SQL
25 
26 #include <stdint.h>
27 #include <string>
28 #include <vector>
29 
32 
33 namespace ignite
34 {
35  namespace cache
36  {
37  namespace query
38  {
42  class SqlQuery
43  {
44  public:
51  SqlQuery(const std::string& type, const std::string& sql) : type(type), sql(sql), pageSize(1024),
52  loc(false), args(NULL)
53  {
54  // No-op.
55  }
56 
62  SqlQuery(const SqlQuery& other) : type(other.type), sql(other.sql), pageSize(other.pageSize),
63  loc(other.loc), args()
64  {
65  args.reserve(other.args.size());
66 
67  for (std::vector<QueryArgumentBase*>::const_iterator i = other.args.begin();
68  i != other.args.end(); ++i)
69  args.push_back((*i)->Copy());
70  }
71 
77  SqlQuery& operator=(const SqlQuery& other)
78  {
79  if (this != &other)
80  {
81  SqlQuery tmp(other);
82 
83  std::swap(type, tmp.type);
84  std::swap(sql, tmp.sql);
85  std::swap(pageSize, tmp.pageSize);
86  std::swap(loc, tmp.loc);
87  std::swap(args, tmp.args);
88  }
89 
90  return *this;
91  }
92 
97  {
98  for (std::vector<QueryArgumentBase*>::iterator it = args.begin(); it != args.end(); ++it)
99  delete *it;
100  }
101 
107  void Swap(SqlQuery& other)
108  {
109  if (this != &other)
110  {
111  std::swap(type, other.type);
112  std::swap(sql, other.sql);
113  std::swap(pageSize, other.pageSize);
114  std::swap(loc, other.loc);
115  std::swap(args, other.args);
116  }
117  }
118 
124  const std::string& GetType() const
125  {
126  return type;
127  }
128 
134  void SetType(const std::string& type)
135  {
136  this->type = type;
137  }
138 
144  const std::string& GetSql() const
145  {
146  return sql;
147  }
148 
154  void SetSql(const std::string& sql)
155  {
156  this->sql = sql;
157  }
158 
164  int32_t GetPageSize() const
165  {
166  return pageSize;
167  }
168 
174  void SetPageSize(int32_t pageSize)
175  {
176  this->pageSize = pageSize;
177  }
178 
184  bool IsLocal() const
185  {
186  return loc;
187  }
188 
194  void SetLocal(bool loc)
195  {
196  this->loc = loc;
197  }
198 
204  template<typename T>
205  void AddArgument(const T& arg)
206  {
207  args.push_back(new QueryArgument<T>(arg));
208  }
209 
215  void Write(binary::BinaryRawWriter& writer) const
216  {
217  writer.WriteBool(loc);
218  writer.WriteString(sql);
219  writer.WriteString(type);
220  writer.WriteInt32(pageSize);
221 
222  writer.WriteInt32(static_cast<int32_t>(args.size()));
223 
224  for (std::vector<QueryArgumentBase*>::const_iterator it = args.begin(); it != args.end(); ++it)
225  (*it)->Write(writer);
226  }
227 
228  private:
230  std::string type;
231 
233  std::string sql;
234 
236  int32_t pageSize;
237 
239  bool loc;
240 
242  std::vector<QueryArgumentBase*> args;
243  };
244  }
245  }
246 }
247 
248 #endif
int32_t GetPageSize() const
Get page size.
Definition: query_sql.h:164
Declares ignite::binary::BinaryRawWriter class.
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: binary_raw_writer.cpp:72
SqlQuery & operator=(const SqlQuery &other)
Assignment operator.
Definition: query_sql.h:77
Sql query.
Definition: query_sql.h:42
void WriteString(const char *val)
Write string.
Definition: binary_raw_writer.cpp:122
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql.h:174
void SetLocal(bool loc)
Set local flag.
Definition: query_sql.h:194
void Write(binary::BinaryRawWriter &writer) const
Write query info to the stream.
Definition: query_sql.h:215
const std::string & GetType() const
Get type name.
Definition: query_sql.h:124
Declares ignite::cache::query::QueryArgument class template and ignite::cache::query::QueryArgumentBa...
Binary raw writer.
Definition: binary_raw_writer.h:42
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql.h:154
void SetType(const std::string &type)
Set type name.
Definition: query_sql.h:134
void AddArgument(const T &arg)
Add argument.
Definition: query_sql.h:205
void WriteBool(bool val)
Write bool.
Definition: binary_raw_writer.cpp:42
bool IsLocal() const
Get local flag.
Definition: query_sql.h:184
void Swap(SqlQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: query_sql.h:107
SqlQuery(const SqlQuery &other)
Copy constructor.
Definition: query_sql.h:62
~SqlQuery()
Destructor.
Definition: query_sql.h:96
Apache Ignite API.
Definition: binary_consts.h:28
const std::string & GetSql() const
Get SQL string.
Definition: query_sql.h:144
Query argument.
Definition: query_argument.h:66
SqlQuery(const std::string &type, const std::string &sql)
Constructor.
Definition: query_sql.h:51