FSTWriteGroup.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #ifdef __cplusplus
  18. #include <memory>
  19. #include "Firestore/Source/Local/StringView.h"
  20. namespace leveldb {
  21. class DB;
  22. class Status;
  23. }
  24. #endif
  25. NS_ASSUME_NONNULL_BEGIN
  26. @class GPBMessage;
  27. /**
  28. * A group of writes that will be applied together atomically to persistent storage.
  29. *
  30. * This class is usable by both Objective-C and Objective-C++ clients. Objective-C clients are able
  31. * to create a new group and commit it. Objective-C++ clients can additionally add to the group
  32. * using deleteKey: and putKey:value:.
  33. *
  34. * Note that this is a write "group" even though the underlying LevelDB concept is a write "batch"
  35. * because Firestore already has a concept of mutation batches, which are user-specified groups of
  36. * changes. This means that an FSTWriteGroup may contain the application of multiple user-specified
  37. * mutation batches.
  38. */
  39. @interface FSTWriteGroup : NSObject
  40. /**
  41. * Creates a new, empty write group.
  42. *
  43. * @param action A description of the action performed by this group, used for logging.
  44. */
  45. + (instancetype)groupWithAction:(NSString *)action;
  46. - (instancetype)init __attribute__((unavailable("Use a static constructor instead")));
  47. /** The action description assigned to this write group. */
  48. @property(nonatomic, copy, readonly) NSString *action;
  49. /** Returns YES if the write group has no messages in it. */
  50. - (BOOL)isEmpty;
  51. #ifdef __cplusplus
  52. /**
  53. * Marks the given key for deletion.
  54. *
  55. * @param key The LevelDB key of the row to delete
  56. */
  57. - (void)removeMessageForKey:(Firestore::StringView)key;
  58. /**
  59. * Sets the row identified by the given key to the value of the given protocol buffer message.
  60. *
  61. * @param key The LevelDB Key of the row to set.
  62. * @param message The protocol buffer message whose serialized contents should be used for the
  63. * value associated with the key.
  64. */
  65. - (void)setMessage:(GPBMessage *)message forKey:(Firestore::StringView)key;
  66. /**
  67. * Sets the row identified by the given key to the value of the given data bytes.
  68. *
  69. * @param key The LevelDB Key of the row to set.
  70. * @param data The exact value to be associated with the key.
  71. */
  72. - (void)setData:(Firestore::StringView)data forKey:(Firestore::StringView)key;
  73. /** Writes the contents to the given LevelDB. */
  74. - (leveldb::Status)writeToDB:(std::shared_ptr<leveldb::DB>)db;
  75. #endif
  76. @end
  77. NS_ASSUME_NONNULL_END