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