Apache Ignite C++
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_SQL_FIELDS
24 #define _IGNITE_CACHE_QUERY_SQL_FIELDS
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  {
43  {
44  public:
50  SqlFieldsQuery(const std::string& sql) : sql(sql), pageSize(1024), loc(false), args()
51  {
52  // No-op.
53  }
54 
61  SqlFieldsQuery(const std::string& sql, bool loc) : sql(sql), pageSize(1024), loc(false), args()
62  {
63  // No-op.
64  }
65 
71  SqlFieldsQuery(const SqlFieldsQuery& other) : sql(other.sql), pageSize(other.pageSize), loc(other.loc),
72  args()
73  {
74  args.reserve(other.args.size());
75 
76  for (std::vector<QueryArgumentBase*>::const_iterator i = other.args.begin();
77  i != other.args.end(); ++i)
78  args.push_back((*i)->Copy());
79  }
80 
87  {
88  if (this != &other)
89  {
90  SqlFieldsQuery tmp(other);
91 
92  std::swap(sql, tmp.sql);
93  std::swap(pageSize, tmp.pageSize);
94  std::swap(loc, tmp.loc);
95  std::swap(args, tmp.args);
96  }
97 
98  return *this;
99  }
100 
105  {
106  for (std::vector<QueryArgumentBase*>::iterator it = args.begin(); it != args.end(); ++it)
107  delete *it;
108  }
109 
115  const std::string& GetSql() const
116  {
117  return sql;
118  }
119 
125  void SetSql(const std::string& sql)
126  {
127  this->sql = sql;
128  }
129 
135  int32_t GetPageSize() const
136  {
137  return pageSize;
138  }
139 
145  void SetPageSize(int32_t pageSize)
146  {
147  this->pageSize = pageSize;
148  }
149 
155  bool IsLocal() const
156  {
157  return loc;
158  }
159 
165  void SetLocal(bool loc)
166  {
167  this->loc = loc;
168  }
169 
175  template<typename T>
176  void AddArgument(const T& arg)
177  {
178  args.push_back(new QueryArgument<T>(arg));
179  }
180 
186  void Write(binary::BinaryRawWriter& writer) const
187  {
188  writer.WriteBool(loc);
189  writer.WriteString(sql);
190  writer.WriteInt32(pageSize);
191 
192  writer.WriteInt32(static_cast<int32_t>(args.size()));
193 
194  for (std::vector<QueryArgumentBase*>::const_iterator it = args.begin(); it != args.end(); ++it)
195  (*it)->Write(writer);
196  }
197 
198  private:
200  std::string sql;
201 
203  int32_t pageSize;
204 
206  bool loc;
207 
209  std::vector<QueryArgumentBase*> args;
210  };
211  }
212  }
213 }
214 
215 #endif
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql_fields.h:145
Declares ignite::binary::BinaryRawWriter class.
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: binary_raw_writer.cpp:72
void AddArgument(const T &arg)
Add argument.
Definition: query_sql_fields.h:176
int32_t GetPageSize() const
Get page size.
Definition: query_sql_fields.h:135
SqlFieldsQuery(const std::string &sql, bool loc)
Constructor.
Definition: query_sql_fields.h:61
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql_fields.h:125
void SetLocal(bool loc)
Set local flag.
Definition: query_sql_fields.h:165
Sql fields query.
Definition: query_sql_fields.h:42
void Write(binary::BinaryRawWriter &writer) const
Write query info to the stream.
Definition: query_sql_fields.h:186
void WriteString(const char *val)
Write string.
Definition: binary_raw_writer.cpp:122
Declares ignite::cache::query::QueryArgument class template and ignite::cache::query::QueryArgumentBa...
bool IsLocal() const
Get local flag.
Definition: query_sql_fields.h:155
Binary raw writer.
Definition: binary_raw_writer.h:42
void WriteBool(bool val)
Write bool.
Definition: binary_raw_writer.cpp:42
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: query_sql_fields.h:50
~SqlFieldsQuery()
Destructor.
Definition: query_sql_fields.h:104
const std::string & GetSql() const
Get SQL string.
Definition: query_sql_fields.h:115
Apache Ignite API.
Definition: binary_consts.h:28
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: query_sql_fields.h:71
Query argument.
Definition: query_argument.h:66
SqlFieldsQuery & operator=(const SqlFieldsQuery &other)
Assignment operator.
Definition: query_sql_fields.h:86