• 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 CALENDAR_DATA_SHARE_HELPER_MANAGER_H
17 #define CALENDAR_DATA_SHARE_HELPER_MANAGER_H
18 
19 #include <memory>
20 #include "singleton.h"
21 #include "datashare_helper.h"
22 
23 namespace OHOS::CalendarApi {
24 class DataShareHelperManager : public OHOS::Singleton<DataShareHelperManager> {
25 public:
26     void SetDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> helper);
27     std::shared_ptr<DataShare::DataShareHelper> GetDataShareHelper();
28     /**
29      * @brief Inserts a single data record into the database.
30      *
31      * @param uri Indicates the path of the data to operate.
32      * @param value  Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
33      *
34      * @return Returns the index of the inserted data record.
35      */
36     int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value);
37     /**
38      * @brief Updates data records in the database.
39      *
40      * @param uri Indicates the path of data to update.
41      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
42      * @param value Indicates the data to update. This parameter can be null.
43      *
44      * @return Returns the number of data records updated.
45      */
46     int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates,
47         const DataShare::DataShareValuesBucket &value);
48 
49     /**
50      * @brief Deletes one or more data records from the database.
51      *
52      * @param uri Indicates the path of the data to operate.
53      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
54      *
55      * @return Returns the number of data records deleted.
56      */
57     int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates);
58 
59     /**
60      * @brief Query records from the database.
61      *
62      * @param uri Indicates the path of data to query.
63      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
64      * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
65      * @param businessError Indicates the error by query.
66      *
67      * @return Returns the query result.
68      */
69     std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri,
70         const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
71         DataShare::DatashareBusinessError *businessError = nullptr);
72 private:
73     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper;
74 };
75 } // namespace OHOS::CalendarApi
76 
77 #endif // CALENDAR_DATA_SHARE_HELPER_MANAGER_H