1 //  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 #include "rocksdb/write_batch_base.h"
7 
8 #include <string>
9 
10 #include "rocksdb/slice.h"
11 #include "rocksdb/status.h"
12 
13 namespace ROCKSDB_NAMESPACE {
14 
15 // Simple implementation of SlicePart variants of Put().  Child classes
16 // can override these method with more performant solutions if they choose.
Put(ColumnFamilyHandle * column_family,const SliceParts & key,const SliceParts & value)17 Status WriteBatchBase::Put(ColumnFamilyHandle* column_family,
18                            const SliceParts& key, const SliceParts& value) {
19   std::string key_buf, value_buf;
20   Slice key_slice(key, &key_buf);
21   Slice value_slice(value, &value_buf);
22 
23   return Put(column_family, key_slice, value_slice);
24 }
25 
Put(const SliceParts & key,const SliceParts & value)26 Status WriteBatchBase::Put(const SliceParts& key, const SliceParts& value) {
27   std::string key_buf, value_buf;
28   Slice key_slice(key, &key_buf);
29   Slice value_slice(value, &value_buf);
30 
31   return Put(key_slice, value_slice);
32 }
33 
Delete(ColumnFamilyHandle * column_family,const SliceParts & key)34 Status WriteBatchBase::Delete(ColumnFamilyHandle* column_family,
35                               const SliceParts& key) {
36   std::string key_buf;
37   Slice key_slice(key, &key_buf);
38   return Delete(column_family, key_slice);
39 }
40 
Delete(const SliceParts & key)41 Status WriteBatchBase::Delete(const SliceParts& key) {
42   std::string key_buf;
43   Slice key_slice(key, &key_buf);
44   return Delete(key_slice);
45 }
46 
SingleDelete(ColumnFamilyHandle * column_family,const SliceParts & key)47 Status WriteBatchBase::SingleDelete(ColumnFamilyHandle* column_family,
48                                     const SliceParts& key) {
49   std::string key_buf;
50   Slice key_slice(key, &key_buf);
51   return SingleDelete(column_family, key_slice);
52 }
53 
SingleDelete(const SliceParts & key)54 Status WriteBatchBase::SingleDelete(const SliceParts& key) {
55   std::string key_buf;
56   Slice key_slice(key, &key_buf);
57   return SingleDelete(key_slice);
58 }
59 
DeleteRange(ColumnFamilyHandle * column_family,const SliceParts & begin_key,const SliceParts & end_key)60 Status WriteBatchBase::DeleteRange(ColumnFamilyHandle* column_family,
61                                    const SliceParts& begin_key,
62                                    const SliceParts& end_key) {
63   std::string begin_key_buf, end_key_buf;
64   Slice begin_key_slice(begin_key, &begin_key_buf);
65   Slice end_key_slice(end_key, &end_key_buf);
66   return DeleteRange(column_family, begin_key_slice, end_key_slice);
67 }
68 
DeleteRange(const SliceParts & begin_key,const SliceParts & end_key)69 Status WriteBatchBase::DeleteRange(const SliceParts& begin_key,
70                                    const SliceParts& end_key) {
71   std::string begin_key_buf, end_key_buf;
72   Slice begin_key_slice(begin_key, &begin_key_buf);
73   Slice end_key_slice(end_key, &end_key_buf);
74   return DeleteRange(begin_key_slice, end_key_slice);
75 }
76 
Merge(ColumnFamilyHandle * column_family,const SliceParts & key,const SliceParts & value)77 Status WriteBatchBase::Merge(ColumnFamilyHandle* column_family,
78                              const SliceParts& key, const SliceParts& value) {
79   std::string key_buf, value_buf;
80   Slice key_slice(key, &key_buf);
81   Slice value_slice(value, &value_buf);
82 
83   return Merge(column_family, key_slice, value_slice);
84 }
85 
Merge(const SliceParts & key,const SliceParts & value)86 Status WriteBatchBase::Merge(const SliceParts& key, const SliceParts& value) {
87   std::string key_buf, value_buf;
88   Slice key_slice(key, &key_buf);
89   Slice value_slice(value, &value_buf);
90 
91   return Merge(key_slice, value_slice);
92 }
93 
94 }  // namespace ROCKSDB_NAMESPACE
95