• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_DP_PROFILE_DATA_RDB_ADAPTER_H
17 #define OHOS_DP_PROFILE_DATA_RDB_ADAPTER_H
18 
19 
20 #include <set>
21 #include "irdb_adapter.h"
22 #include "rdb_open_callback.h"
23 #include "single_instance.h"
24 
25 namespace OHOS {
26 namespace DistributedDeviceProfile {
27 class ProfileDataRdbAdapter : public IRdbAdapter {
28     DECLARE_SINGLE_INSTANCE(ProfileDataRdbAdapter);
29 public:
30     int32_t Init() override;
31     int32_t UnInit() override;
32     int32_t Put(int64_t& outRowId, const std::string& table, const ValuesBucket& Values) override;
33     int32_t Delete(int32_t& deleteRows, const std::string& table, const std::string& whereClause,
34         const std::vector<ValueObject>& bindArgs = {}) override;
35     int32_t Update(int32_t& changedRows, const std::string& table, const ValuesBucket& values,
36         const std::string& whereClause, const std::vector<ValueObject>& bindArgs = {}) override;
37     int32_t CreateTable(const std::string& sql) override;
38     std::shared_ptr <ResultSet> Get(const std::string& sql, const std::vector<ValueObject>& args = {}) override;
39     int32_t GetRDBPtr();
40     bool IsInit();
41 
42 private:
43     std::shared_ptr<RdbStore> store_ = nullptr;
44     std::mutex ProfileDataRdbAdapterMtx_;
45 };
46 
47 class ProfileDataOpenCallback : public NativeRdb::RdbOpenCallback {
48 public:
49     int32_t OnCreate(RdbStore& store) override;
50     int32_t OnUpgrade(RdbStore& store, int oldVersion, int newVersion) override;
51 private:
52     int32_t UpdateFromVer1To2(RdbStore& store);
53 };
54 } // namespace DistributedDeviceProfile
55 } // namespace OHOS
56 #endif // OHOS_DP_PROFILE_DATA_RDB_ADAPTER_H
57