write_batch_base.cc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "rocksdb/write_batch_base.h"
  6. #include <string>
  7. #include "rocksdb/slice.h"
  8. #include "rocksdb/status.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. // Simple implementation of SlicePart variants of Put(). Child classes
  11. // can override these method with more performant solutions if they choose.
  12. Status WriteBatchBase::Put(ColumnFamilyHandle* column_family,
  13. const SliceParts& key, const SliceParts& value) {
  14. std::string key_buf, value_buf;
  15. Slice key_slice(key, &key_buf);
  16. Slice value_slice(value, &value_buf);
  17. return Put(column_family, key_slice, value_slice);
  18. }
  19. Status WriteBatchBase::Put(const SliceParts& key, const SliceParts& value) {
  20. std::string key_buf, value_buf;
  21. Slice key_slice(key, &key_buf);
  22. Slice value_slice(value, &value_buf);
  23. return Put(key_slice, value_slice);
  24. }
  25. Status WriteBatchBase::Delete(ColumnFamilyHandle* column_family,
  26. const SliceParts& key) {
  27. std::string key_buf;
  28. Slice key_slice(key, &key_buf);
  29. return Delete(column_family, key_slice);
  30. }
  31. Status WriteBatchBase::Delete(const SliceParts& key) {
  32. std::string key_buf;
  33. Slice key_slice(key, &key_buf);
  34. return Delete(key_slice);
  35. }
  36. Status WriteBatchBase::SingleDelete(ColumnFamilyHandle* column_family,
  37. const SliceParts& key) {
  38. std::string key_buf;
  39. Slice key_slice(key, &key_buf);
  40. return SingleDelete(column_family, key_slice);
  41. }
  42. Status WriteBatchBase::SingleDelete(const SliceParts& key) {
  43. std::string key_buf;
  44. Slice key_slice(key, &key_buf);
  45. return SingleDelete(key_slice);
  46. }
  47. Status WriteBatchBase::DeleteRange(ColumnFamilyHandle* column_family,
  48. const SliceParts& begin_key,
  49. const SliceParts& end_key) {
  50. std::string begin_key_buf, end_key_buf;
  51. Slice begin_key_slice(begin_key, &begin_key_buf);
  52. Slice end_key_slice(end_key, &end_key_buf);
  53. return DeleteRange(column_family, begin_key_slice, end_key_slice);
  54. }
  55. Status WriteBatchBase::DeleteRange(const SliceParts& begin_key,
  56. const SliceParts& end_key) {
  57. std::string begin_key_buf, end_key_buf;
  58. Slice begin_key_slice(begin_key, &begin_key_buf);
  59. Slice end_key_slice(end_key, &end_key_buf);
  60. return DeleteRange(begin_key_slice, end_key_slice);
  61. }
  62. Status WriteBatchBase::Merge(ColumnFamilyHandle* column_family,
  63. const SliceParts& key, const SliceParts& value) {
  64. std::string key_buf, value_buf;
  65. Slice key_slice(key, &key_buf);
  66. Slice value_slice(value, &value_buf);
  67. return Merge(column_family, key_slice, value_slice);
  68. }
  69. Status WriteBatchBase::Merge(const SliceParts& key, const SliceParts& value) {
  70. std::string key_buf, value_buf;
  71. Slice key_slice(key, &key_buf);
  72. Slice value_slice(value, &value_buf);
  73. return Merge(key_slice, value_slice);
  74. }
  75. } // namespace ROCKSDB_NAMESPACE