1/* 2 * Copyright (C) 2021 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 DATASHARE_HELPER_H 17#define DATASHARE_HELPER_H 18 19#include <cstdint> 20#include <string> 21 22#include "data_ability_observer_interface.h" 23#include "datashare_value_object.h" 24#include "datashare_values_bucket.h" 25#include "uri.h" 26 27namespace OHOS { 28namespace DataShare { 29constexpr int32_t E_OK = 0; 30class DataSharePredicates { 31public: 32 DataSharePredicates *EqualTo(const std::string &field, const std::string &value); 33}; 34class DatashareBusinessError {}; 35class DataShareResultSet { 36public: 37 DataShareResultSet() = default; 38 ~DataShareResultSet() = default; 39 static int32_t GetRowCount(int32_t &count); 40 static int32_t Close(); 41 static int32_t GoToFirstRow(); 42 static int32_t GetColumnIndex(const std::string &columnName, int32_t &columnIndex); 43 int32_t GetString(int columnIndex, std::string &value) const; 44 45private: 46 std::string strValue_; 47}; 48 49class DataShareHelper { 50public: 51 DataShareHelper() = default; 52 ~DataShareHelper() = default; 53 static std::shared_ptr<DataShareHelper> Creator( 54 const sptr<IRemoteObject> &token, const std::string &strUri, const std::string &extUri); 55 std::shared_ptr<DataShareResultSet> Query(Uri &uri, const DataSharePredicates &predicates, 56 std::vector<std::string> &columns, DatashareBusinessError *businessError = nullptr); 57 static void RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 58 static void UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 59 static bool Release(); 60 static int Update(Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value); 61 static int Insert(Uri &uri, const DataShareValuesBucket &value); 62 63private: 64 static std::shared_ptr<DataShareHelper> instance_; 65 std::shared_ptr<DataShareResultSet> resultSet_; 66}; 67} // namespace DataShare 68} // namespace OHOS 69#endif // DATASHARE_HELPER_H 70