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 DATASHARESERVICE_TEMPLATE_DATA_H 17 #define DATASHARESERVICE_TEMPLATE_DATA_H 18 19 #include "datashare_template.h" 20 #include "db_delegate.h" 21 #include "serializable/serializable.h" 22 23 namespace OHOS::DataShare { 24 struct PredicatesNode final: public DistributedData::Serializable { 25 PredicatesNode() = default; 26 PredicatesNode(const std::string &key, const std::string &selectSql); 27 bool Marshal(json &node) const override; 28 bool Unmarshal(const json &node) override; 29 std::string key; 30 std::string selectSql; 31 }; 32 struct TemplateNode final: public DistributedData::Serializable { 33 TemplateNode() = default; 34 explicit TemplateNode(const Template &tpl); 35 bool Marshal(json &node) const override; 36 bool Unmarshal(const json &node) override; 37 Template ToTemplate() const; 38 private: 39 std::vector<PredicatesNode> predicates; 40 std::string scheduler; 41 }; 42 43 struct TemplateRootNode final: public DistributedData::Serializable { 44 TemplateRootNode() = default; 45 TemplateRootNode(const std::string &uri, const std::string &bundleName, const int64_t subscriberId, 46 const int32_t userId, const Template &tpl); 47 bool Marshal(json &node) const override; 48 bool Unmarshal(const json &node) override; 49 Template ToTemplate() const; 50 private: 51 std::string uri; 52 std::string bundleName; 53 std::string subscriberId; 54 int32_t userId; 55 TemplateNode tpl; 56 }; 57 58 struct TemplateData final : public KvData { 59 TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, int32_t userId, 60 const Template &tpl); 61 static int32_t Query(const std::string &filter, Template &aTemplate); 62 static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId); 63 static bool Delete(const std::string &bundleName, const int32_t userId); 64 static bool Add(const std::string &uri, const int32_t userId, const std::string &bundleName, 65 const int64_t subscriberId, const Template &aTemplate); 66 static bool Delete( 67 const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subscriberId); 68 bool HasVersion() const override; 69 int GetVersion() const override; 70 std::string GetValue() const override; 71 72 private: 73 TemplateRootNode value; 74 }; 75 } // namespace OHOS::DataShare 76 #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H 77