00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KUDU_CLIENT_WRITE_OP_H
00018 #define KUDU_CLIENT_WRITE_OP_H
00019
00020 #include <string>
00021
00022 #include "kudu/client/shared_ptr.h"
00023 #include "kudu/common/partial_row.h"
00024 #include "kudu/util/kudu_export.h"
00025
00026 namespace kudu {
00027
00028 class EncodedKey;
00029
00030 namespace client {
00031
00032 namespace internal {
00033 class Batcher;
00034 class WriteRpc;
00035 }
00036
00037 class KuduTable;
00038
00055 class KUDU_EXPORT KuduWriteOperation {
00056 public:
00058 enum Type {
00059 INSERT = 1,
00060 UPDATE = 2,
00061 DELETE = 3,
00062 UPSERT = 4
00063 };
00064 virtual ~KuduWriteOperation();
00065
00069 const KuduPartialRow& row() const { return row_; }
00070
00074 KuduPartialRow* mutable_row() { return &row_; }
00075
00077 virtual std::string ToString() const = 0;
00078 protected:
00080
00085 explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
00086
00088 virtual Type type() const = 0;
00089
00093 sp::shared_ptr<KuduTable> const table_;
00094
00096 KuduPartialRow row_;
00097
00099
00100 private:
00101 friend class internal::Batcher;
00102 friend class internal::WriteRpc;
00103
00104
00105
00106
00107 EncodedKey* CreateKey() const;
00108
00109 const KuduTable* table() const { return table_.get(); }
00110
00111
00112
00113
00114 int64_t SizeInBuffer() const;
00115
00116 mutable int64_t size_in_buffer_;
00117
00118 DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
00119 };
00120
00121
00126 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
00127 public:
00128 virtual ~KuduInsert();
00129
00131 virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
00132
00133 protected:
00135
00137 virtual Type type() const OVERRIDE {
00138 return INSERT;
00139 }
00140
00142
00143 private:
00144 friend class KuduTable;
00145 explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
00146 };
00147
00151 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
00152 public:
00153 virtual ~KuduUpsert();
00154
00156 virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
00157
00158 protected:
00160
00162 virtual Type type() const OVERRIDE {
00163 return UPSERT;
00164 }
00165
00167
00168 private:
00169 friend class KuduTable;
00170 explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
00171 };
00172
00173
00178 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
00179 public:
00180 virtual ~KuduUpdate();
00181
00183 virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
00184
00185 protected:
00187
00189 virtual Type type() const OVERRIDE {
00190 return UPDATE;
00191 }
00192
00194
00195 private:
00196 friend class KuduTable;
00197 explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
00198 };
00199
00200
00205 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
00206 public:
00207 virtual ~KuduDelete();
00208
00210 virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
00211
00212 protected:
00214
00216 virtual Type type() const OVERRIDE {
00217 return DELETE;
00218 }
00219
00221
00222 private:
00223 friend class KuduTable;
00224 explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
00225 };
00226
00227 }
00228 }
00229
00230 #endif