• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define MLOG_TAG "Media_Cloud_Dao"
17 
18 #include "cloud_media_enhance_dao.h"
19 
20 #include <string>
21 #include <utime.h>
22 #include <vector>
23 
24 #include "abs_rdb_predicates.h"
25 #include "media_column.h"
26 #include "media_log.h"
27 #include "medialibrary_rdbstore.h"
28 #include "medialibrary_unistore_manager.h"
29 #include "result_set.h"
30 #include "result_set_utils.h"
31 #include "medialibrary_rdb_utils.h"
32 
33 namespace OHOS::Media::CloudSync {
GetCloudSyncUnPreparedDataCount(int32_t & result)34 int32_t CloudMediaEnhanceDao::GetCloudSyncUnPreparedDataCount(int32_t &result)
35 {
36     MEDIA_INFO_LOG("enter GetCloudSyncUnPreparedDataCount");
37     auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStore();
38     CHECK_AND_RETURN_RET_LOG(rdbStore != nullptr, E_RDB_STORE_NULL, "Failed to get rdbStore.");
39 
40     NativeRdb::AbsRdbPredicates queryPredicates = NativeRdb::AbsRdbPredicates(PhotoColumn::PHOTOS_TABLE);
41     queryPredicates.EqualTo(PhotoColumn::PHOTO_QUALITY,
42         std::to_string(static_cast<int32_t>(MultiStagesPhotoQuality::LOW)));
43     queryPredicates.EqualTo(MediaColumn::MEDIA_TYPE,
44         std::to_string(static_cast<int32_t>(MediaType::MEDIA_TYPE_IMAGE)));
45     queryPredicates.And()->IsNotNull(PhotoColumn::PHOTO_ID);
46     vector<string> queryColums = {"COUNT(1) AS count"};
47     auto resultSet = rdbStore->Query(queryPredicates, queryColums);
48     if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
49         MEDIA_ERR_LOG("resultSet is null or failed to get row");
50         return E_RDB;
51     }
52     result = GetInt32Val("count", resultSet);
53     resultSet->Close();
54     MEDIA_INFO_LOG("GetCloudSyncUnPreparedDataCount end %{public}d", result);
55     return E_OK;
56 }
57 
GetNextUnPreparedData()58 std::tuple<std::string, std::string> CloudMediaEnhanceDao::GetNextUnPreparedData()
59 {
60     MEDIA_INFO_LOG("enter GetNextUnPreparedData");
61     auto ret = std::make_tuple<std::string, std::string>("", "");
62     auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStore();
63     CHECK_AND_RETURN_RET_LOG(rdbStore != nullptr, ret, "Failed to get rdbStore.");
64 
65     NativeRdb::AbsRdbPredicates queryPredicates = NativeRdb::AbsRdbPredicates(PhotoColumn::PHOTOS_TABLE);
66     queryPredicates.EqualTo(PhotoColumn::PHOTO_QUALITY,
67         std::to_string(static_cast<int32_t>(MultiStagesPhotoQuality::LOW)));
68     queryPredicates.EqualTo(MediaColumn::MEDIA_TYPE,
69         std::to_string(static_cast<int32_t>(MediaType::MEDIA_TYPE_IMAGE)));
70     queryPredicates.And()->IsNotNull(PhotoColumn::PHOTO_ID);
71     queryPredicates.Limit(1);
72     vector<string> queryColums = { MediaColumn::MEDIA_ID, PhotoColumn::PHOTO_ID };
73     auto resultSet = rdbStore->Query(queryPredicates, queryColums);
74     CHECK_AND_RETURN_RET_LOG(resultSet != nullptr, ret, "Failed to query.");
75 
76     int32_t rowCount = 0;
77     int32_t retRow = resultSet->GetRowCount(rowCount);
78     CHECK_AND_RETURN_RET_LOG((retRow == 0 && rowCount >= 0), ret, "Failed to Get Count.");
79 
80     if (resultSet->GoToNextRow() == NativeRdb::E_OK) {
81         std::get<0>(ret) = GetStringVal(MediaColumn::MEDIA_ID, resultSet);
82         std::get<1>(ret) = GetStringVal(PhotoColumn::PHOTO_ID, resultSet);
83     }
84     resultSet->Close();
85 
86     return ret;
87 }
88 }  // namespace OHOS::Media::CloudSync