GPUdb C++ API  Version 5.2.0.0
GPUdb.hpp
Go to the documentation of this file.
1 #ifndef __GPUDB_HPP__
2 #define __GPUDB_HPP__
3 
5 
6 #include <boost/thread/mutex.hpp>
7 
8 namespace gpudb
9 {
10  class GPUdb;
11 }
12 
13 #include "gpudb/Avro.hpp"
14 #include "gpudb/GenericRecord.hpp"
15 #include "gpudb/GPUdbException.hpp"
16 #include "gpudb/Type.hpp"
18 
19 namespace gpudb
20 {
21  class GPUdb : private boost::noncopyable
22  {
23  public:
24  class Options
25  {
26  public:
27  Options();
28  std::string getUsername() const;
29  std::string getPassword() const;
30  bool getUseSnappy() const;
31  size_t getThreadCount() const;
32  avro::ExecutorPtr getExecutor() const;
33  Options& setUsername(const std::string& value);
34  Options& setPassword(const std::string& value);
35  Options& setUseSnappy(const bool value);
36  Options& setThreadCount(const size_t value);
37  Options& setExecutor(const avro::ExecutorPtr value);
38 
39  private:
40  std::string username;
41  std::string password;
42  bool useSnappy;
43  size_t threadCount;
44  avro::ExecutorPtr executor;
45  };
46 
47  static const int64_t END_OF_SET = -9999;
48 
49  static inline std::string getApiVersion() { return GPUdb::API_VERSION; }
50 
51  GPUdb(const std::string& url, const Options& options = Options());
52  std::string getUrl() const;
53  std::string getUsername() const;
54  std::string getPassword() const;
55  bool getUseSnappy() const;
56  size_t getThreadCount() const;
57  avro::ExecutorPtr getExecutor() const;
58 
59  template<typename TRequest, typename TResponse> TResponse& submitRequest(const std::string& endpoint, const TRequest& request, TResponse& response, const bool enableCompression = false) const
60  {
61  std::vector<uint8_t> requestBytes;
62  avro::encode(requestBytes, request);
63  GpudbResponse gpudbResponse;
64  submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
65  avro::decode(response, gpudbResponse.data);
66  return response;
67  }
68 
69  #include "gpudb/GPUdbFunctions.hpp"
70 
71  void addKnownType(const std::string& typeId, const avro::DecoderPtr& decoder);
72 
73  template<typename T> void addKnownType(const std::string& typeId)
74  {
75  addKnownType(typeId, avro::createDecoder<T>());
76  }
77 
78  template<typename T> void addKnownType(const std::string& typeId, const std::string& schemaString)
79  {
80  addKnownType(typeId, avro::createDecoder<T>(schemaString));
81  }
82 
83  template<typename T> void addKnownType(const std::string& typeId, const ::avro::ValidSchema& schema)
84  {
85  addKnownType(typeId, avro::createDecoder<T>(schema));
86  }
87 
88  void addKnownTypeFromTable(const std::string& tableName, const avro::DecoderPtr& decoder);
89 
90  template<typename T> void addKnownTypeFromTable(const std::string& tableName)
91  {
92  addKnownTypeFromTable(tableName, avro::createDecoder<T>());
93  }
94 
95  template<typename T> void addKnownTypeFromTable(const std::string& tableName, const std::string& schemaString)
96  {
97  addKnownTypeFromTable(tableName, avro::createDecoder<T>(schemaString));
98  }
99 
100  template<typename T> void addKnownTypeFromTable(const std::string& tableName, const ::avro::ValidSchema& schema)
101  {
102  addKnownTypeFromTable(tableName, avro::createDecoder<T>(schema));
103  }
104 
105  private:
106  static const std::string API_VERSION;
107 
108  std::string url;
109  std::string host;
110  std::string service;
111  std::string path;
112  bool secure;
113  std::string username;
114  std::string password;
115  std::string authorization;
116  bool useSnappy;
117  size_t threadCount;
118  avro::ExecutorPtr executor;
119  mutable std::map<std::string, avro::DecoderPtr> knownTypes;
120  mutable boost::mutex knownTypesMutex;
121 
122  void submitRequestRaw(const std::string& endpoint, const std::vector<uint8_t>& request, GpudbResponse& response, const bool enableCompression) const;
123  avro::DecoderPtr getDecoder(const std::string& typeId) const;
124  void setDecoderIfMissing(const std::string& typeId, const std::string& label, const std::string& schemaString, const std::map<std::string, std::vector<std::string> >& properties) const;
125  };
126 
127  #include "gpudb/GPUdbTemplates.hpp"
128 }
129 
130 #endif
void addKnownType(const std::string &typeId, const avro::DecoderPtr &decoder)
void addKnownTypeFromTable(const std::string &tableName, const ::avro::ValidSchema &schema)
Definition: GPUdb.hpp:100
void addKnownType(const std::string &typeId)
Definition: GPUdb.hpp:73
void addKnownTypeFromTable(const std::string &tableName)
Definition: GPUdb.hpp:90
std::string getPassword() const
Options & setUsername(const std::string &value)
GPUdb(const std::string &url, const Options &options=Options())
size_t getThreadCount() const
A set of output parameters forendpoint /gpudbresponse}.
Definition: gpudb_wrapper.h:17
void addKnownTypeFromTable(const std::string &tableName, const avro::DecoderPtr &decoder)
TResponse & submitRequest(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Definition: GPUdb.hpp:59
void addKnownType(const std::string &typeId, const ::avro::ValidSchema &schema)
Definition: GPUdb.hpp:83
static std::string getApiVersion()
Definition: GPUdb.hpp:49
Options & setExecutor(const avro::ExecutorPtr value)
std::string getUsername() const
static const int64_t END_OF_SET
Definition: GPUdb.hpp:47
avro::ExecutorPtr getExecutor() const
Options & setThreadCount(const size_t value)
void addKnownTypeFromTable(const std::string &tableName, const std::string &schemaString)
Definition: GPUdb.hpp:95
bool getUseSnappy() const
std::string getUrl() const
Options & setUseSnappy(const bool value)
Options & setPassword(const std::string &value)
void addKnownType(const std::string &typeId, const std::string &schemaString)
Definition: GPUdb.hpp:78
std::vector< uint8_t > data
Definition: gpudb_wrapper.h:35