1 /* 2 * Copyright (c) 2021 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 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H 16 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H 17 18 #include <vector> 19 20 #include "serializable/serializable.h" 21 22 namespace OHOS::DistributedData { 23 struct API_EXPORT StoreMetaData final : public Serializable { 24 // record meta version for compatible, should update when modify store meta data structure. 25 static constexpr uint32_t CURRENT_VERSION = 0x03000005; 26 // UID -> uid, deviceAccountId -> userId, userId -> user 27 static constexpr uint32_t FIELD_CHANGED_TAG = 0x03000003; 28 static constexpr uint32_t UUID_CHANGED_TAG = 0x03000004; 29 static constexpr const char *KEY_PREFIX = "KvStoreMetaData"; 30 uint32_t version = CURRENT_VERSION; 31 bool isAutoSync = false; 32 bool isBackup = false; 33 bool isDirty = false; 34 bool isEncrypt = false; 35 bool isManualClean = false; 36 bool isSearchable = false; 37 bool isNeedCompress = false; 38 int32_t storeType = -1; 39 int32_t securityLevel = 0; 40 int32_t area = 0; 41 int32_t uid = -1; 42 uint32_t tokenId = 0; 43 int32_t instanceId = 0; 44 std::string appId = ""; 45 std::string appType = ""; 46 std::string bundleName = ""; 47 std::string hapName = ""; 48 std::string dataDir = ""; 49 std::string customDir = ""; 50 std::string deviceId = ""; 51 std::string schema = ""; 52 std::string storeId = ""; 53 std::string user = ""; 54 std::string account = ""; 55 56 enum StoreType { 57 STORE_KV_BEGIN = 0, 58 STORE_KV_END = 9, 59 STORE_RELATIONAL_BEGIN = 10, 60 STORE_RELATIONAL_END = 19, 61 STORE_OBJECT_BEGIN = 20, 62 STORE_OBJECT_END = 29, 63 STORE_BUTT = 255 64 }; 65 66 API_EXPORT StoreMetaData(); 67 API_EXPORT StoreMetaData(const std::string &userId, const std::string &appId, const std::string &storeId); 68 API_EXPORT ~StoreMetaData(); 69 API_EXPORT bool operator==(const StoreMetaData &metaData) const; 70 API_EXPORT bool operator!=(const StoreMetaData &metaData) const; 71 API_EXPORT bool Marshal(json &node) const override; 72 API_EXPORT bool Unmarshal(const json &node) override; 73 API_EXPORT std::string GetKey() const; 74 API_EXPORT std::string GetKeyLocal() const; 75 API_EXPORT std::string GetSecretKey() const; 76 API_EXPORT std::string GetStrategyKey() const; 77 API_EXPORT std::string GetBackupSecretKey() const; 78 API_EXPORT std::string GetStoreAlias() const; 79 API_EXPORT static std::string GetKey(const std::initializer_list<std::string> &fields); 80 API_EXPORT static std::string GetPrefix(const std::initializer_list<std::string> &fields); 81 }; 82 } // namespace OHOS::DistributedData 83 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H