• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_RDB_ADAPTER_H
17 #define OHOS_DP_RDB_ADAPTER_H
18 
19 
20 #include <set>
21 #include "irdb_adapter.h"
22 #include "rdb_open_callback.h"
23 
24 namespace OHOS {
25 namespace DistributedDeviceProfile {
26 class RdbAdapter : public IRdbAdapter {
27 public:
28     RdbAdapter();
29     ~RdbAdapter();
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 
41 private:
42     std::shared_ptr<RdbStore> store_ = nullptr;
43     std::mutex rdbAdapterMtx_;
44 };
45 
46 class OpenCallback : public NativeRdb::RdbOpenCallback {
47 public:
48     int32_t OnCreate(RdbStore& store) override;
49     int32_t OnUpgrade(RdbStore& store, int oldVersion, int newVersion) override;
50     int32_t CreateTable(RdbStore& store);
51     int32_t CreateUniqueIndex(RdbStore& store);
52     int32_t UpgradeVersionOneToTwo(RdbStore& store);
53     int32_t UpgradeVersionTwoToThree(RdbStore& store);
54     int32_t AddAcerColumnOneToTwo(RdbStore& store);
55     int32_t AddAceeColumnOneToTwo(RdbStore& store);
56     int32_t AddAclColumnTwoToThree(RdbStore& store);
57     int32_t AddAcerColumnTwoToThree(RdbStore& store);
58     int32_t AddAceeColumnTwoToThree(RdbStore& store);
59     int32_t DropAndRebuildIndex(RdbStore& store);
60 
61 private:
62     std::mutex rdbStoreMtx_;
63 };
64 } // namespace DistributedDeviceProfile
65 } // namespace OHOS
66 #endif // OHOS_DP_RDB_ADAPTER_H
67