1 /* 2 * Copyright (c) 2023 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_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H 18 #include "serializable/serializable.h" 19 namespace OHOS::DistributedData { 20 struct API_EXPORT Field final : public Serializable { 21 std::string colName; 22 std::string alias; 23 int32_t type = 0; 24 bool primary = false; 25 bool nullable = true; 26 bool Marshal(json &node) const override; 27 bool Unmarshal(const json &node) override; 28 }; 29 30 struct API_EXPORT Table final : public Serializable { 31 std::string name; 32 std::string sharedTableName; 33 std::string alias; 34 std::vector<Field> fields; 35 std::vector<std::string> deviceSyncFields = {}; 36 std::vector<std::string> cloudSyncFields = {}; 37 bool Marshal(json &node) const override; 38 bool Unmarshal(const json &node) override; 39 }; 40 41 struct API_EXPORT Database final : public Serializable { 42 std::string name = ""; 43 std::string alias; 44 std::vector<Table> tables; 45 std::vector<std::string> GetTableNames() const; 46 uint32_t autoSyncType = 0; 47 std::string user = ""; 48 std::string deviceId = ""; 49 uint32_t version = 0; 50 std::string bundleName = ""; 51 API_EXPORT std::string GetKey() const; 52 API_EXPORT static std::string GetKey(const std::initializer_list<std::string> &fields); 53 API_EXPORT static std::string GetPrefix(const std::initializer_list<std::string> &fields); 54 bool Marshal(json &node) const override; 55 bool Unmarshal(const json &node) override; 56 }; 57 58 class API_EXPORT SchemaMeta final : public Serializable { 59 public: 60 using Database = Database; 61 using Table = Table; 62 using Field = Field; 63 static constexpr const char *DELETE_FIELD = "#_deleted"; 64 static constexpr const char *GID_FIELD = "#_gid"; 65 static constexpr const char *CREATE_FIELD = "#_createTime"; 66 static constexpr const char *MODIFY_FIELD = "#_modifyTime"; 67 static constexpr const char *CURSOR_FIELD = "#_cursor"; 68 static constexpr const char *ERROR_FIELD = "#_error"; 69 static constexpr const char *VERSION_FIELD = "#_version"; 70 static constexpr const char *REFERENCE_FIELD = "#_reference"; 71 static constexpr const char *CLOUD_OWNER = "cloud_owner"; 72 static constexpr const char *CLOUD_PRIVILEGE = "cloud_privilege"; 73 static constexpr const char *SHARING_RESOURCE = "#_sharing_resource"; 74 static constexpr const char *HASH_KEY = "#_hash_key"; 75 76 static constexpr uint32_t CURRENT_VERSION = 0x10001; 77 static constexpr uint32_t CLEAN_WATER_VERSION = 0x10001; 78 static inline uint32_t GetLowVersion(uint32_t metaVersion = CURRENT_VERSION) 79 { 80 return metaVersion & 0xFFFF; 81 } 82 83 static inline uint32_t GetHighVersion(uint32_t metaVersion = CURRENT_VERSION) 84 { 85 return metaVersion & ~0xFFFF; 86 } 87 uint32_t metaVersion = CURRENT_VERSION; 88 int32_t version = 0; 89 std::string bundleName; 90 std::vector<Database> databases; 91 bool e2eeEnable = false; 92 93 bool Marshal(json &node) const override; 94 bool Unmarshal(const json &node) override; 95 bool IsValid() const; 96 Database GetDataBase(const std::string &storeId); 97 std::vector<std::string> GetStores(); 98 }; 99 100 // Table mode of device data sync time 101 enum AutoSyncType { 102 IS_NOT_AUTO_SYNC = 0, 103 SYNC_ON_CHANGE = 1, // datachange sync 104 SYNC_ON_READY, // onready sync 105 SYNC_ON_CHANGE_READY //datachange and onready sync 106 }; 107 108 } // namespace OHOS::DistributedData 109 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H