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_DEVICE_PROFILE_DAO_H 17 #define OHOS_DP_DEVICE_PROFILE_DAO_H 18 19 20 #include <map> 21 #include <string> 22 #include <memory> 23 #include <mutex> 24 #include <vector> 25 26 #include "device_profile.h" 27 #include "device_profile_filter_options.h" 28 #include "profile_data_rdb_adapter.h" 29 #include "single_instance.h" 30 #include "values_bucket.h" 31 32 33 namespace OHOS { 34 namespace DistributedDeviceProfile { 35 using namespace OHOS::NativeRdb; 36 37 class DeviceProfileDao { 38 DECLARE_SINGLE_INSTANCE(DeviceProfileDao); 39 40 public: 41 int32_t Init(); 42 int32_t UnInit(); 43 int32_t PutDeviceProfile(const DeviceProfile& deviceProfile); 44 int32_t GetDeviceProfiles(const DeviceProfileFilterOptions& filterOptions, 45 std::vector<DeviceProfile>& deviceProfiles); 46 int32_t DeleteDeviceProfile(const DeviceProfile& deviceProfile); 47 int32_t UpdateDeviceProfile(const DeviceProfile& newProfile); 48 int32_t CreateTable(); 49 int32_t CreateIndex(); 50 void CreateQuerySqlAndCondition(const DeviceProfileFilterOptions& filterOptions, 51 std::string& sql, std::vector<ValueObject>& condition); 52 int32_t DeviceProfileToEntries(const DeviceProfile& deviceProfile, ValuesBucket& values); 53 int32_t ConvertToDeviceProfile(std::shared_ptr<ResultSet> resultSet, DeviceProfile& deviceProfile); 54 void GenerateSqlAndCondition(const std::vector<int32_t>& params, 55 std::string& sql, std::vector<ValueObject>& condition); 56 void GenerateSqlAndCondition(const std::vector<std::string>& params, 57 std::string& sql, std::vector<ValueObject>& condition); 58 private: 59 std::mutex rdbMutex_; 60 }; 61 } 62 } 63 #endif // OHOS_DP_DEVICE_PROFILE_DAO_H 64