1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 16 #ifndef OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_UPGRADE_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_UPGRADE_H 18 #include <functional> 19 #include <memory> 20 #include "kv_store_delegate_manager.h" 21 #include "kv_store_nb_delegate.h" 22 #include "metadata/store_meta_data.h" 23 #include "types.h" 24 namespace OHOS::DistributedKv { 25 class Upgrade { 26 public: 27 using StoreMeta = DistributedData::StoreMetaData; 28 using DBPassword = DistributedDB::CipherPassword; 29 using DBStatus = DistributedDB::DBStatus; 30 using DBStore = DistributedDB::KvStoreNbDelegate; 31 using DBManager = DistributedDB::KvStoreDelegateManager; 32 using Exporter = std::function<std::string(const StoreMeta &, DBPassword &)>; 33 using Cleaner = std::function<Status(const StoreMeta &)>; 34 API_EXPORT static Upgrade &GetInstance(); 35 API_EXPORT bool RegisterExporter(uint32_t version, Exporter exporter); 36 API_EXPORT bool RegisterCleaner(uint32_t version, Cleaner cleaner); 37 38 DBStatus UpdateStore(const StoreMeta &old, const StoreMeta &metaData, const std::vector<uint8_t> &pwd); 39 DBStatus ExportStore(const StoreMeta &old, const StoreMeta &meta); 40 void UpdatePassword(const StoreMeta &meta, const std::vector<uint8_t> &password); 41 42 private: 43 using AutoStore = std::unique_ptr<DBStore, std::function<void(DBStore *)>>; 44 AutoStore GetDBStore(const StoreMeta &meta, const std::vector<uint8_t> &pwd); 45 Exporter exporter_; 46 Cleaner cleaner_; 47 }; 48 } // namespace OHOS::DistributedKv 49 #endif // OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_UPGRADE_H 50