|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_ |
| 16 | +#define FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_ |
| 17 | + |
| 18 | +#include <functional> |
| 19 | +#include <set> |
| 20 | +#include <string> |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +#include "app/memory/unique_ptr.h" |
| 24 | +#include "app/src/mutex.h" |
| 25 | +#include "app/src/path.h" |
| 26 | +#include "database/src/common/query_spec.h" |
| 27 | +#include "database/src/desktop/core/cache_policy.h" |
| 28 | +#include "database/src/desktop/core/tracked_query_manager.h" |
| 29 | +#include "database/src/desktop/persistence/persistence_manager.h" |
| 30 | +#include "database/src/desktop/persistence/persistence_manager_interface.h" |
| 31 | +#include "database/src/desktop/persistence/persistence_storage_engine.h" |
| 32 | +#include "database/src/desktop/view/view_cache.h" |
| 33 | + |
| 34 | +namespace firebase { |
| 35 | +namespace database { |
| 36 | +namespace internal { |
| 37 | + |
| 38 | +class NoopPersistenceManager : public PersistenceManagerInterface { |
| 39 | + public: |
| 40 | + NoopPersistenceManager(); |
| 41 | + |
| 42 | + // Persist a user write to the storage engine. |
| 43 | + // |
| 44 | + // @param path The path for this write. |
| 45 | + // @param variant The variant for this write. |
| 46 | + // @param write_id The write id that was used for this write. |
| 47 | + void SaveUserOverwrite(const Path& path, const Variant& variant, |
| 48 | + WriteId write_id) override; |
| 49 | + |
| 50 | + // Persist a user merge to the storage engine. |
| 51 | + // |
| 52 | + // @param path The path for this merge. |
| 53 | + // @param children The children for this merge. |
| 54 | + // @param write_id The write id that was used for this merge. |
| 55 | + void SaveUserMerge(const Path& path, const CompoundWrite& children, |
| 56 | + WriteId write_id) override; |
| 57 | + |
| 58 | + // Remove the user write with the given write id. |
| 59 | + // |
| 60 | + // @param write_id The write id to remove. |
| 61 | + void RemoveUserWrite(WriteId write_id) override; |
| 62 | + |
| 63 | + // Remove all user writes. |
| 64 | + void RemoveAllUserWrites() override; |
| 65 | + |
| 66 | + // Applies the write to the storage engine so that it can be persisted. |
| 67 | + void ApplyUserWriteToServerCache(const Path& path, |
| 68 | + const Variant& variant) override; |
| 69 | + |
| 70 | + // Applies the merge to the storage engine so that it can be persisted. |
| 71 | + void ApplyUserWriteToServerCache(const Path& path, |
| 72 | + const CompoundWrite& merge) override; |
| 73 | + |
| 74 | + // Return a list of all writes that were persisted |
| 75 | + // |
| 76 | + // @return The list of writes |
| 77 | + std::vector<UserWriteRecord> LoadUserWrites() override; |
| 78 | + |
| 79 | + // Returns any cached variant or children as a CacheNode. The query is *not* |
| 80 | + // used to filter the variant but rather to determine if it can be considered |
| 81 | + // complete. |
| 82 | + // |
| 83 | + // @param query The query at the path |
| 84 | + // @return The cached variant or an empty CacheNode if no cache is available |
| 85 | + CacheNode ServerCache(const QuerySpec& query) override; |
| 86 | + |
| 87 | + // Overwrite the server cache at the location given by the given QuerySpec. |
| 88 | + void UpdateServerCache(const QuerySpec& query, |
| 89 | + const Variant& variant) override; |
| 90 | + |
| 91 | + // Merge the given write into theserver cache at the location given by the |
| 92 | + // given QuerySpec. |
| 93 | + void UpdateServerCache(const Path& path, |
| 94 | + const CompoundWrite& children) override; |
| 95 | + |
| 96 | + // Begin tracking the given QuerySpec. |
| 97 | + void SetQueryActive(const QuerySpec& query) override; |
| 98 | + |
| 99 | + // Stop tracking the given QuerySpec. |
| 100 | + void SetQueryInactive(const QuerySpec& query) override; |
| 101 | + |
| 102 | + // Inform the TrackedQueryManager to mark the tracked query as complete. |
| 103 | + void SetQueryComplete(const QuerySpec& query) override; |
| 104 | + |
| 105 | + // Inform the storage engine which keys should be tracked for a given Query. |
| 106 | + void SetTrackedQueryKeys(const QuerySpec& query, |
| 107 | + const std::set<std::string>& keys) override; |
| 108 | + |
| 109 | + // Updates the set of keys that should be tracked for a given Query. |
| 110 | + void UpdateTrackedQueryKeys(const QuerySpec& query, |
| 111 | + const std::set<std::string>& added, |
| 112 | + const std::set<std::string>& removed) override; |
| 113 | + |
| 114 | + // Run a transaction. Transactions are functions that are going to change |
| 115 | + // values in the database, and they must do so effectively atomically. Two |
| 116 | + // transacations cannot be run at the same time in different threads, they |
| 117 | + // must be scheduled to run by Scheduler. A transaction should return true to |
| 118 | + // signal that it completed successfully, or false if there was an error. |
| 119 | + // Certain actions can only be performed from inside a transaction, and those |
| 120 | + // functions will assert if they are not called between calls to |
| 121 | + // BeingTransaction and EndTransaction. |
| 122 | + bool RunInTransaction(std::function<bool()> func) override; |
| 123 | + |
| 124 | + private: |
| 125 | + bool inside_transaction_; |
| 126 | +}; |
| 127 | + |
| 128 | +} // namespace internal |
| 129 | +} // namespace database |
| 130 | +} // namespace firebase |
| 131 | + |
| 132 | +#endif // FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_PERSISTENCE_NOOP_PERSISTENCE_MANAGER_H_ |
0 commit comments