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 23namespace OHOS::CalendarApi { 24class DataShareHelperManager : public OHOS::Singleton<DataShareHelperManager> { 25public: 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 /** 39 * @brief batch insert data records into the database. 40 * 41 * @param uri Indicates the path of the data to operate. 42 * @param values Indicates the data records to insert. If this parameter is null, a blank row will be inserted. 43 * 44 * @return Returns the index of the inserted data count. 45 */ 46 int BatchInsert(const Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values); 47 48 /** 49 * @brief Updates data records in the database. 50 * 51 * @param uri Indicates the path of data to update. 52 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 53 * @param value Indicates the data to update. This parameter can be null. 54 * 55 * @return Returns the number of data records updated. 56 */ 57 int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates, 58 const DataShare::DataShareValuesBucket &value); 59 60 /** 61 * @brief Deletes one or more data records from the database. 62 * 63 * @param uri Indicates the path of the data to operate. 64 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 65 * 66 * @return Returns the number of data records deleted. 67 */ 68 int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates); 69 70 /** 71 * @brief Query records from the database. 72 * 73 * @param uri Indicates the path of data to query. 74 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 75 * @param columns Indicates the columns to query. If this parameter is null, all columns are queried. 76 * @param businessError Indicates the error by query. 77 * 78 * @return Returns the query result. 79 */ 80 std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 81 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 82 DataShare::DatashareBusinessError *businessError = nullptr); 83private: 84 std::shared_ptr<DataShare::DataShareHelper> dataShareHelper; 85}; 86} // namespace OHOS::CalendarApi 87 88#endif // CALENDAR_DATA_SHARE_HELPER_MANAGER_H