FSTWriteGroup.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <memory>
  18. #include "Firestore/Source/Local/StringView.h"
  19. #include "leveldb/db.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @class GPBMessage;
  22. /**
  23. * A group of writes that will be applied together atomically to persistent storage.
  24. *
  25. * This class is usable by both Objective-C and Objective-C++ clients. Objective-C clients are able
  26. * to create a new group and commit it. Objective-C++ clients can additionally add to the group
  27. * using deleteKey: and putKey:value:.
  28. *
  29. * Note that this is a write "group" even though the underlying LevelDB concept is a write "batch"
  30. * because Firestore already has a concept of mutation batches, which are user-specified groups of
  31. * changes. This means that an FSTWriteGroup may contain the application of multiple user-specified
  32. * mutation batches.
  33. */
  34. @interface FSTWriteGroup : NSObject
  35. /**
  36. * Creates a new, empty write group.
  37. *
  38. * @param action A description of the action performed by this group, used for logging.
  39. */
  40. + (instancetype)groupWithAction:(NSString *)action;
  41. - (instancetype)init __attribute__((unavailable("Use a static constructor instead")));
  42. /** The action description assigned to this write group. */
  43. @property(nonatomic, copy, readonly) NSString *action;
  44. /** Returns YES if the write group has no messages in it. */
  45. - (BOOL)isEmpty;
  46. /**
  47. * Marks the given key for deletion.
  48. *
  49. * @param key The LevelDB key of the row to delete
  50. */
  51. - (void)removeMessageForKey:(Firestore::StringView)key;
  52. /**
  53. * Sets the row identified by the given key to the value of the given protocol buffer message.
  54. *
  55. * @param key The LevelDB Key of the row to set.
  56. * @param message The protocol buffer message whose serialized contents should be used for the
  57. * value associated with the key.
  58. */
  59. - (void)setMessage:(GPBMessage *)message forKey:(Firestore::StringView)key;
  60. /**
  61. * Sets the row identified by the given key to the value of the given data bytes.
  62. *
  63. * @param key The LevelDB Key of the row to set.
  64. * @param data The exact value to be associated with the key.
  65. */
  66. - (void)setData:(Firestore::StringView)data forKey:(Firestore::StringView)key;
  67. /** Writes the contents to the given LevelDB. */
  68. - (leveldb::Status)writeToDB:(std::shared_ptr<leveldb::DB>)db;
  69. @end
  70. NS_ASSUME_NONNULL_END