GridGain C++ Client Library
query_sql.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) GridGain Systems. All Rights Reserved.
3 * _________ _____ __________________ _____
4 * __ ____/___________(_)______ /__ ____/______ ____(_)_______
5 * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
6 * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
7 * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
8 */
9 
15 #ifndef _GRIDGAIN_CACHE_QUERY_SQL
16 #define _GRIDGAIN_CACHE_QUERY_SQL
17 
18 #include <stdint.h>
19 #include <string>
20 #include <vector>
21 
24 
25 namespace gridgain
26 {
27  namespace cache
28  {
29  namespace query
30  {
34  class SqlQuery
35  {
36  public:
43  SqlQuery(const std::string& type, const std::string& sql) : type(type), sql(sql), pageSize(1024),
44  loc(false), args(NULL)
45  {
46  // No-op.
47  }
48 
54  SqlQuery(const SqlQuery& other) : type(other.type), sql(other.sql), pageSize(other.pageSize),
55  loc(other.loc), args()
56  {
57  args.reserve(other.args.size());
58 
59  for (std::vector<QueryArgumentBase*>::const_iterator i = other.args.begin(); i != other.args.end(); ++i)
60  {
61  args.push_back((*i)->Copy());
62  }
63  }
64 
70  SqlQuery& operator=(const SqlQuery& other)
71  {
72  if (this != &other)
73  {
74  SqlQuery tmp(other);
75 
76  Swap(tmp);
77  }
78 
79  return *this;
80  }
81 
86  {
87  for (std::vector<QueryArgumentBase*>::iterator it = args.begin(); it != args.end(); ++it)
88  delete *it;
89  }
90 
96  void Swap(SqlQuery& other)
97  {
98  if (this != &other)
99  {
100  std::swap(type, other.type);
101  std::swap(sql, other.sql);
102  std::swap(pageSize, other.pageSize);
103  std::swap(loc, other.loc);
104  std::swap(args, other.args);
105  }
106  }
107 
113  const std::string& GetType() const
114  {
115  return type;
116  }
117 
123  void SetType(const std::string& type)
124  {
125  this->type = type;
126  }
127 
133  const std::string& GetSql() const
134  {
135  return sql;
136  }
137 
143  void SetSql(const std::string& sql)
144  {
145  this->sql = sql;
146  }
147 
153  int32_t GetPageSize() const
154  {
155  return pageSize;
156  }
157 
163  void SetPageSize(int32_t pageSize)
164  {
165  this->pageSize = pageSize;
166  }
167 
173  bool IsLocal() const
174  {
175  return loc;
176  }
177 
183  void SetLocal(bool loc)
184  {
185  this->loc = loc;
186  }
187 
193  template<typename T>
194  void AddArgument(const T& arg)
195  {
196  args.push_back(new QueryArgument<T>(arg));
197  }
198 
204  void Write(portable::PortableRawWriter& writer) const
205  {
206  writer.WriteBool(loc);
207  writer.WriteString(sql);
208  writer.WriteString(type);
209  writer.WriteInt32(pageSize);
210 
211  writer.WriteInt32(static_cast<int32_t>(args.size()));
212 
213  for (std::vector<QueryArgumentBase*>::const_iterator it = args.begin(); it != args.end(); ++it)
214  (*it)->Write(writer);
215 
216  writer.WriteBool(false); // distributed joins
217  }
218 
219  private:
221  std::string type;
222 
224  std::string sql;
225 
227  int32_t pageSize;
228 
230  bool loc;
231 
233  std::vector<QueryArgumentBase*> args;
234  };
235  }
236  }
237 }
238 
239 #endif
void Write(portable::PortableRawWriter &writer) const
Write query info to the stream.
Definition: query_sql.h:204
Sql query.
Definition: query_sql.h:34
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: portable_raw_writer.cpp:64
SqlQuery(const std::string &type, const std::string &sql)
Constructor.
Definition: query_sql.h:43
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql.h:163
Query argument.
Definition: query_argument.h:58
void Swap(SqlQuery &other)
Efficiently swaps contents with another SqlQuery instance.
Definition: query_sql.h:96
SqlQuery(const SqlQuery &other)
Copy constructor.
Definition: query_sql.h:54
void WriteString(const char *val)
Write string.
Definition: portable_raw_writer.cpp:114
Declares gridgain::cache::query::QueryArgument class template and gridgain::cache::query::QueryArgume...
bool IsLocal() const
Get local flag.
Definition: query_sql.h:173
void WriteBool(bool val)
Write bool.
Definition: portable_raw_writer.cpp:34
int32_t GetPageSize() const
Get page size.
Definition: query_sql.h:153
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql.h:143
void AddArgument(const T &arg)
Add argument.
Definition: query_sql.h:194
void SetType(const std::string &type)
Set type name.
Definition: query_sql.h:123
void SetLocal(bool loc)
Set local flag.
Definition: query_sql.h:183
Declares gridgain::portable::PortableRawWriter class.
~SqlQuery()
Destructor.
Definition: query_sql.h:85
Portable raw writer.
Definition: portable_raw_writer.h:34
SqlQuery & operator=(const SqlQuery &other)
Assignment operator.
Definition: query_sql.h:70
const std::string & GetType() const
Get type name.
Definition: query_sql.h:113
const std::string & GetSql() const
Get SQL string.
Definition: query_sql.h:133
GridGain API.
Definition: cache.h:35