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 GENERAL_CONTROLLER_PORVIDER_IMPL_H
17 #define GENERAL_CONTROLLER_PORVIDER_IMPL_H
18 
19 #include "datashare_connection.h"
20 #include "general_controller.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 class IDataAbilityObserver;
25 }
26 
27 namespace DataShare {
28 class GeneralControllerProviderImpl : public GeneralController {
29 public:
30     GeneralControllerProviderImpl(std::shared_ptr<DataShareConnection> connection,
31         const Uri &uri, const sptr<IRemoteObject> &token);
32 
33     virtual ~GeneralControllerProviderImpl() = default;
34 
35     int Insert(const Uri &uri, const DataShareValuesBucket &value) override;
36 
37     int Update(const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override;
38 
39     int Delete(const Uri &uri, const DataSharePredicates &predicates) override;
40 
41     std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
42         std::vector<std::string> &columns, DatashareBusinessError &businessError) override;
43 
44     int RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
45 
46     int UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
47 
48     void NotifyChange(const Uri &uri) override;
49 
50     std::pair<int32_t, int32_t> InsertEx(const Uri &uri, const DataShareValuesBucket &value) override;
51 
52     std::pair<int32_t, int32_t> UpdateEx(
53         const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override;
54 
55     std::pair<int32_t, int32_t> DeleteEx(const Uri &uri, const DataSharePredicates &predicates) override;
56 
57 private:
58     std::shared_ptr<DataShareConnection> connection_ = nullptr;
59     sptr<IRemoteObject> token_ = {};
60     Uri uri_ = Uri("");
61 };
62 } // namespace DataShare
63 } // namespace OHOS
64 #endif // GENERAL_CONTROLLER_PORVIDER_IMPL_H
65