1 /* 2 * Copyright (c) 2023 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_CLOUD_SYNC_SERVICE_ALBUM_DATA_HANDLER_H 17 #define OHOS_CLOUD_SYNC_SERVICE_ALBUM_DATA_HANDLER_H 18 19 #include "album_data_convertor.h" 20 #include "rdb_data_handler.h" 21 22 namespace OHOS { 23 namespace FileManagement { 24 namespace CloudSync { 25 class AlbumDataHandler : public RdbDataHandler { 26 public: 27 AlbumDataHandler(int32_t userId, const std::string &bundleName, std::shared_ptr<NativeRdb::RdbStore> rdb); 28 virtual ~AlbumDataHandler() = default; 29 30 /* download */ 31 virtual void GetFetchCondition(FetchCondition &cond) override; 32 virtual int32_t OnFetchRecords(std::shared_ptr<std::vector<DriveKit::DKRecord>> &records, 33 OnFetchParams ¶ms) override; 34 virtual int32_t GetRetryRecords(std::vector<DriveKit::DKRecordId> &records) override; 35 36 /* upload */ 37 virtual int32_t GetCreatedRecords(std::vector<DriveKit::DKRecord> &records) override; 38 virtual int32_t GetDeletedRecords(std::vector<DriveKit::DKRecord> &records) override; 39 virtual int32_t GetMetaModifiedRecords(std::vector<DriveKit::DKRecord> &records) override; 40 41 virtual int32_t OnCreateRecords(const std::map<DriveKit::DKRecordId, 42 DriveKit::DKRecordOperResult> &map) override; 43 virtual int32_t OnDeleteRecords(const std::map<DriveKit::DKRecordId, 44 DriveKit::DKRecordOperResult> &map) override; 45 virtual int32_t OnModifyMdirtyRecords(const std::map<DriveKit::DKRecordId, 46 DriveKit::DKRecordOperResult> &map) override; 47 48 virtual int32_t Clean(const int action) override; 49 50 virtual void SetChecking() override; 51 /* reset */ 52 void Reset(); 53 54 private: 55 std::tuple<std::shared_ptr<NativeRdb::ResultSet>, int> QueryLocalMatch(const std::string &recordId); 56 int32_t InsertCloudAlbum(DriveKit::DKRecord &record); 57 int32_t DeleteCloudAlbum(DriveKit::DKRecord &record); 58 int32_t UpdateCloudAlbum(DriveKit::DKRecord &record); 59 int32_t HandleLocalDirty(int32_t dirty, const DriveKit::DKRecord &record); 60 61 int32_t OnUploadSuccess(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 62 int32_t OnDeleteSuccess(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 63 int32_t OnCreateSuccess(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 64 int32_t OnCreateFail(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 65 int32_t OnDeleteFail(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 66 int32_t OnModifyFail(const std::pair<DriveKit::DKRecordId, DriveKit::DKRecordOperResult> &entry); 67 68 static inline const std::string TABLE_NAME = "albums"; 69 static inline const int32_t LIMIT_SIZE = 5; 70 DriveKit::DKRecordType recordType_ = "album"; 71 DriveKit::DKFieldKeyArray desiredKeys_; 72 73 /* failure records */ 74 std::vector<std::string> modifyFailSet_; 75 std::vector<std::string> createFailSet_; 76 77 /* convert */ 78 AlbumDataConvertor createConvertor_ = { AlbumDataConvertor::ALBUM_CREATE }; 79 AlbumDataConvertor deleteConvertor_ = { AlbumDataConvertor::ALBUM_DELETE }; 80 AlbumDataConvertor modifyConvertor_ = { AlbumDataConvertor::ALBUM_MODIFY }; 81 }; 82 } // namespace CloudSync 83 } // namespace FileManagement 84 } // namespace OHOS 85 #endif // OHOS_CLOUD_SYNC_SERVICE_ALBUM_DATA_HANDLER_H 86