• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::string update;
40     std::vector<PredicatesNode> predicates;
41     std::string scheduler;
42 };
43 
44 struct TemplateRootNode final: public DistributedData::Serializable {
45     TemplateRootNode() = default;
46     TemplateRootNode(const std::string &uri, const std::string &bundleName, const int64_t subscriberId,
47         const int32_t userId, const Template &tpl);
48     bool Marshal(json &node) const override;
49     bool Unmarshal(const json &node) override;
50     Template ToTemplate() const;
51 private:
52     std::string uri;
53     std::string bundleName;
54     std::string subscriberId;
55     int32_t userId;
56     TemplateNode tpl;
57 };
58 
59 struct TemplateData final : public KvData {
60     TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, int32_t userId,
61         const Template &tpl);
62     static int32_t Query(const std::string &filter, Template &aTemplate);
63     static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId);
64     static bool Delete(const std::string &bundleName, const int32_t userId);
65     static bool Add(const std::string &uri, const int32_t userId, const std::string &bundleName,
66         const int64_t subscriberId, const Template &aTemplate);
67     static bool Delete(
68         const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subscriberId);
69     bool HasVersion() const override;
70     int GetVersion() const override;
71     std::string GetValue() const override;
72 
73 private:
74     TemplateRootNode value;
75 };
76 } // namespace OHOS::DataShare
77 #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H
78