10fbfc30aSopenharmony_ci/* 20fbfc30aSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 30fbfc30aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40fbfc30aSopenharmony_ci * you may not use this file except in compliance with the License. 50fbfc30aSopenharmony_ci * You may obtain a copy of the License at 60fbfc30aSopenharmony_ci * 70fbfc30aSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80fbfc30aSopenharmony_ci * 90fbfc30aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100fbfc30aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110fbfc30aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120fbfc30aSopenharmony_ci * See the License for the specific language governing permissions and 130fbfc30aSopenharmony_ci * limitations under the License. 140fbfc30aSopenharmony_ci */ 150fbfc30aSopenharmony_ci 160fbfc30aSopenharmony_ci#include "data_share_helper_manager.h" 170fbfc30aSopenharmony_ci#include "calendar_log.h" 180fbfc30aSopenharmony_ci 190fbfc30aSopenharmony_ciusing namespace OHOS::DataShare; 200fbfc30aSopenharmony_cinamespace OHOS::CalendarApi { 210fbfc30aSopenharmony_ci 220fbfc30aSopenharmony_civoid DataShareHelperManager::SetDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> helper) 230fbfc30aSopenharmony_ci{ 240fbfc30aSopenharmony_ci dataShareHelper = helper; 250fbfc30aSopenharmony_ci} 260fbfc30aSopenharmony_ci 270fbfc30aSopenharmony_cistd::shared_ptr<DataShare::DataShareHelper> DataShareHelperManager::GetDataShareHelper() 280fbfc30aSopenharmony_ci{ 290fbfc30aSopenharmony_ci return dataShareHelper; 300fbfc30aSopenharmony_ci} 310fbfc30aSopenharmony_ci 320fbfc30aSopenharmony_ciint DataShareHelperManager::Insert(const Uri &uri, const DataShareValuesBucket &value) 330fbfc30aSopenharmony_ci{ 340fbfc30aSopenharmony_ci if (!dataShareHelper) { 350fbfc30aSopenharmony_ci LOG_ERROR("dataShareHelper null"); 360fbfc30aSopenharmony_ci return -1; 370fbfc30aSopenharmony_ci } 380fbfc30aSopenharmony_ci return dataShareHelper->Insert(const_cast<Uri &>(uri), value); 390fbfc30aSopenharmony_ci} 400fbfc30aSopenharmony_ci 410fbfc30aSopenharmony_ciint DataShareHelperManager::BatchInsert(const Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values) 420fbfc30aSopenharmony_ci{ 430fbfc30aSopenharmony_ci if (!dataShareHelper) { 440fbfc30aSopenharmony_ci LOG_ERROR("dataShareHelper null"); 450fbfc30aSopenharmony_ci return -1; 460fbfc30aSopenharmony_ci } 470fbfc30aSopenharmony_ci return dataShareHelper->BatchInsert(const_cast<Uri &>(uri), values); 480fbfc30aSopenharmony_ci} 490fbfc30aSopenharmony_ci 500fbfc30aSopenharmony_ciint DataShareHelperManager::Update(const Uri &uri, const DataSharePredicates &predicates, 510fbfc30aSopenharmony_ci const DataShareValuesBucket &value) 520fbfc30aSopenharmony_ci{ 530fbfc30aSopenharmony_ci if (!dataShareHelper) { 540fbfc30aSopenharmony_ci LOG_ERROR("dataShareHelper null"); 550fbfc30aSopenharmony_ci return -1; 560fbfc30aSopenharmony_ci } 570fbfc30aSopenharmony_ci return dataShareHelper->Update(const_cast<Uri &>(uri), predicates, value); 580fbfc30aSopenharmony_ci} 590fbfc30aSopenharmony_ci 600fbfc30aSopenharmony_ciint DataShareHelperManager::Delete(const Uri &uri, const DataSharePredicates &predicates) 610fbfc30aSopenharmony_ci{ 620fbfc30aSopenharmony_ci if (!dataShareHelper) { 630fbfc30aSopenharmony_ci LOG_ERROR("dataShareHelper null"); 640fbfc30aSopenharmony_ci return -1; 650fbfc30aSopenharmony_ci } 660fbfc30aSopenharmony_ci return dataShareHelper->Delete(const_cast<Uri &>(uri), predicates); 670fbfc30aSopenharmony_ci} 680fbfc30aSopenharmony_ci 690fbfc30aSopenharmony_cistd::shared_ptr<DataShareResultSet> DataShareHelperManager::Query(const Uri &uri, const DataSharePredicates &predicates, 700fbfc30aSopenharmony_ci std::vector<std::string> &columns, DatashareBusinessError *businessError) 710fbfc30aSopenharmony_ci{ 720fbfc30aSopenharmony_ci if (!dataShareHelper) { 730fbfc30aSopenharmony_ci LOG_ERROR("dataShareHelper null"); 740fbfc30aSopenharmony_ci return nullptr; 750fbfc30aSopenharmony_ci } 760fbfc30aSopenharmony_ci return dataShareHelper->Query(const_cast<Uri &>(uri), predicates, columns, businessError); 770fbfc30aSopenharmony_ci} 780fbfc30aSopenharmony_ci}