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_FILEMGMT_DATA_SYNCER_RDB_STORE_H 17 #define OHOS_FILEMGMT_DATA_SYNCER_RDB_STORE_H 18 19 #include "rdb_open_callback.h" 20 #include "rdb_store.h" 21 #include "sync_state_manager.h" 22 #include "cloud_sync_constants.h" 23 24 namespace OHOS::FileManagement::CloudSync { 25 class DataSyncerRdbStore { 26 public: 27 static DataSyncerRdbStore &GetInstance(); 28 ~DataSyncerRdbStore() = default; 29 30 int32_t Insert(int32_t userId, const std::string &bundleName); 31 int32_t UpdateSyncState(int32_t userId, const std::string &bundleName, 32 CloudSyncState cloudSyncState, ErrorType errorType); 33 int32_t GetLastSyncTime(int32_t userId, const std::string &bundleName, int64_t &time); 34 int32_t QueryDataSyncer(int32_t userId, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 35 int32_t QueryCloudSync(int32_t userId, 36 const std::string &bundleName, 37 std::shared_ptr<NativeRdb::ResultSet> &resultSet); 38 int32_t GetSyncStateAndErrorType(int32_t userId, const std::string &bundleName, 39 CloudSyncState &cloudSyncState, ErrorType &errorType); 40 private: 41 int32_t Query(NativeRdb::AbsRdbPredicates predicates, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 42 int32_t RdbInit(); DataSyncerRdbStore()43 DataSyncerRdbStore() 44 { 45 RdbInit(); 46 } 47 std::shared_ptr<NativeRdb::RdbStore> rdb_; 48 std::mutex rdbMutex_; 49 }; 50 51 class DataSyncerRdbCallBack : public NativeRdb::RdbOpenCallback { 52 public: 53 int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; 54 int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; 55 }; 56 } // namespace OHOS::FileManagement::CloudSync 57 58 #endif // OHOS_FILEMGMT_DATA_SYNCER_RDB_STORE_H