GridGain C++ Client Library
query_sql_fields.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_FIELDS
16 #define _GRIDGAIN_CACHE_QUERY_SQL_FIELDS
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  {
35  {
36  public:
42  SqlFieldsQuery(const std::string& sql) : sql(sql), pageSize(1024), loc(false), args()
43  {
44  // No-op.
45  }
46 
53  SqlFieldsQuery(const std::string& sql, bool loc) : sql(sql), pageSize(1024), loc(false), args()
54  {
55  // No-op.
56  }
57 
63  SqlFieldsQuery(const SqlFieldsQuery& other) : sql(other.sql), pageSize(other.pageSize), loc(other.loc),
64  args()
65  {
66  args.reserve(other.args.size());
67 
68  for (std::vector<QueryArgumentBase*>::const_iterator i = other.args.begin(); i != other.args.end(); ++i)
69  {
70  args.push_back((*i)->Copy());
71  }
72  }
73 
80  {
81  if (this != &other)
82  {
83  SqlFieldsQuery tmp(other);
84 
85  Swap(tmp);
86  }
87 
88  return *this;
89  }
90 
95  {
96  for (std::vector<QueryArgumentBase*>::iterator it = args.begin(); it != args.end(); ++it)
97  delete *it;
98  }
99 
105  void Swap(SqlFieldsQuery& other)
106  {
107  if (this != &other)
108  {
109  std::swap(sql, other.sql);
110  std::swap(pageSize, other.pageSize);
111  std::swap(loc, other.loc);
112  std::swap(args, other.args);
113  }
114  }
115 
121  const std::string& GetSql() const
122  {
123  return sql;
124  }
125 
131  void SetSql(const std::string& sql)
132  {
133  this->sql = sql;
134  }
135 
141  int32_t GetPageSize() const
142  {
143  return pageSize;
144  }
145 
151  void SetPageSize(int32_t pageSize)
152  {
153  this->pageSize = pageSize;
154  }
155 
161  bool IsLocal() const
162  {
163  return loc;
164  }
165 
171  void SetLocal(bool loc)
172  {
173  this->loc = loc;
174  }
175 
181  template<typename T>
182  void AddArgument(const T& arg)
183  {
184  args.push_back(new QueryArgument<T>(arg));
185  }
186 
192  void Write(portable::PortableRawWriter& writer) const
193  {
194  writer.WriteBool(loc);
195  writer.WriteString(sql);
196  writer.WriteInt32(pageSize);
197 
198  writer.WriteInt32(static_cast<int32_t>(args.size()));
199 
200  for (std::vector<QueryArgumentBase*>::const_iterator it = args.begin(); it != args.end(); ++it)
201  (*it)->Write(writer);
202 
203  writer.WriteBool(false); // distributed joins
204  writer.WriteBool(false); // enforce join order
205  }
206 
207  private:
209  std::string sql;
210 
212  int32_t pageSize;
213 
215  bool loc;
216 
218  std::vector<QueryArgumentBase*> args;
219  };
220  }
221  }
222 }
223 
224 #endif
void SetLocal(bool loc)
Set local flag.
Definition: query_sql_fields.h:171
void AddArgument(const T &arg)
Add argument.
Definition: query_sql_fields.h:182
void SetSql(const std::string &sql)
Set SQL string.
Definition: query_sql_fields.h:131
SqlFieldsQuery(const std::string &sql, bool loc)
Constructor.
Definition: query_sql_fields.h:53
void WriteInt32(int32_t val)
Write 32-byte signed integer.
Definition: portable_raw_writer.cpp:64
void Write(portable::PortableRawWriter &writer) const
Write query info to the stream.
Definition: query_sql_fields.h:192
void Swap(SqlFieldsQuery &other)
Efficiently swaps contents with another SqlFieldsQuery instance.
Definition: query_sql_fields.h:105
Query argument.
Definition: query_argument.h:58
Sql fields query.
Definition: query_sql_fields.h:34
int32_t GetPageSize() const
Get page size.
Definition: query_sql_fields.h:141
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...
SqlFieldsQuery(const SqlFieldsQuery &other)
Copy constructor.
Definition: query_sql_fields.h:63
SqlFieldsQuery & operator=(const SqlFieldsQuery &other)
Assignment operator.
Definition: query_sql_fields.h:79
void SetPageSize(int32_t pageSize)
Set page size.
Definition: query_sql_fields.h:151
void WriteBool(bool val)
Write bool.
Definition: portable_raw_writer.cpp:34
~SqlFieldsQuery()
Destructor.
Definition: query_sql_fields.h:94
SqlFieldsQuery(const std::string &sql)
Constructor.
Definition: query_sql_fields.h:42
Declares gridgain::portable::PortableRawWriter class.
const std::string & GetSql() const
Get SQL string.
Definition: query_sql_fields.h:121
Portable raw writer.
Definition: portable_raw_writer.h:34
bool IsLocal() const
Get local flag.
Definition: query_sql_fields.h:161
GridGain API.
Definition: cache.h:35