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 CLONE_RESTORE_ANALYSIS_DATA_H 17 #define CLONE_RESTORE_ANALYSIS_DATA_H 18 19 #include <string> 20 21 #include "backup_const.h" 22 #include "clone_restore_analysis_total.h" 23 #include "media_backup_report_data_type.h" 24 #include "rdb_store.h" 25 26 namespace OHOS::Media { 27 class CloneRestoreAnalysisData { 28 public: 29 struct AnalysisDataInfo { 30 int32_t fileId; 31 std::unordered_map<std::string, std::variant<int32_t, int64_t, double, 32 std::string, std::vector<uint8_t>>> columnValMap; 33 }; 34 35 void Init(int32_t sceneCode, const std::string &taskId, std::shared_ptr<NativeRdb::RdbStore> mediaRdb, 36 std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb); 37 std::unordered_map<std::string, std::string> GetTableCommonColumns( 38 const std::unordered_set<std::string> &excludedColumns); 39 void GetValFromResultSet(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, AnalysisDataInfo &info, 40 const std::string &columnName, const std::string &columnType); 41 void PrepareCommonColumnVal(NativeRdb::ValuesBucket &value, const std::string &columnName, 42 const std::string &columnType, 43 const std::variant<int32_t, int64_t, double, std::string, std::vector<uint8_t>> &columnVal); 44 void GetAnalysisDataRowInfo(AnalysisDataInfo &info, const std::shared_ptr<NativeRdb::ResultSet> &resultSet); 45 void GetAnalysisDataInfo(); 46 void GetAnalysisDataInsertValue(NativeRdb::ValuesBucket &value, const AnalysisDataInfo &info); 47 int32_t BatchInsertWithRetry(const std::string &tableName, std::vector<NativeRdb::ValuesBucket> &values, 48 int64_t &rowNum); 49 void RemoveDuplicateInfos(const std::unordered_set<int32_t> &existingFileIds); 50 std::unordered_set<int32_t> GetExistingFileIds(); 51 void DeleteDuplicateInfos(); 52 void InsertIntoAnalysisTable(); 53 void RestoreAnalysisDataMaps(); 54 void AnalysisDataRestoreBatch(); 55 void ReportRestoreTaskOfTotal(); 56 void ReportRestoreTaskofData(); 57 void ReportAnalysisTableRestoreTask(); 58 void GetMaxIds(); 59 void CloneAnalysisData(const std::string &table, const std::string &type, 60 const std::unordered_map<int32_t, PhotoInfo> &photoInfoMap, 61 const std::unordered_set<std::string> &excludedColumns); 62 63 private: ToUpper(const std::string & str)64 std::string ToUpper(const std::string &str) 65 { 66 std::string upperStr; 67 std::transform( 68 str.begin(), str.end(), std::back_inserter(upperStr), [](unsigned char c) { return std::toupper(c); }); 69 return upperStr; 70 } 71 72 private: 73 std::string table_; 74 std::string analysisType_; 75 int32_t sceneCode_{-1}; 76 std::string taskId_; 77 int32_t maxId_{0}; 78 std::unordered_map<std::string, std::string> tableCommonColumns_; 79 std::vector<AnalysisDataInfo> analysisDataInfos_; 80 CloneRestoreAnalysisTotal cloneRestoreAnalysisTotal_; 81 std::unordered_map<int32_t, PhotoInfo> photoInfoMap_; 82 std::atomic<int64_t> restoreTimeCost_{0}; 83 int32_t totalCnt_{0}; 84 int32_t successCnt_{0}; 85 int32_t failCnt_{0}; 86 int32_t duplicateCnt_{0}; 87 std::shared_ptr<NativeRdb::RdbStore> mediaRdb_; 88 std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb_; 89 }; 90 } // namespace OHOS::Media 91 #endif // CLONE_RESTORE_ANALYSIS_DATA_H