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 23 namespace OHOS::FileManagement::CloudSync { 24 class DataSyncerRdbStore { 25 public: 26 static DataSyncerRdbStore &GetInstance(); 27 ~DataSyncerRdbStore() = default; 28 29 int32_t Insert(int32_t userId, const std::string &bundleName); 30 int32_t UpdateSyncState(int32_t userId, const std::string &bundleName, SyncState syncState); 31 int32_t GetLastSyncTime(int32_t userId, const std::string &bundleName, int64_t &time); 32 int32_t QueryDataSyncer(int32_t userId, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 33 private: 34 int32_t Query(NativeRdb::AbsRdbPredicates predicates, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 35 int32_t RdbInit(); DataSyncerRdbStore()36 DataSyncerRdbStore() 37 { 38 RdbInit(); 39 } 40 std::shared_ptr<NativeRdb::RdbStore> rdb_; 41 std::mutex rdbMutex_; 42 }; 43 44 class DataSyncerRdbCallBack : public NativeRdb::RdbOpenCallback { 45 public: 46 int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; 47 int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; 48 }; 49 } // namespace OHOS::FileManagement::CloudSync 50 51 #endif // OHOS_FILEMGMT_DATA_SYNCER_RDB_STORE_H