• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t QueryCloudSync(int32_t userId,
34                            const std::string &bundleName,
35                            std::shared_ptr<NativeRdb::ResultSet> &resultSet);
36 private:
37     int32_t Query(NativeRdb::AbsRdbPredicates predicates, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
38     int32_t RdbInit();
DataSyncerRdbStore()39     DataSyncerRdbStore()
40     {
41         RdbInit();
42     }
43     std::shared_ptr<NativeRdb::RdbStore> rdb_;
44     std::mutex rdbMutex_;
45 };
46 
47 class DataSyncerRdbCallBack : public NativeRdb::RdbOpenCallback {
48 public:
49     int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override;
50     int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
51 };
52 } // namespace OHOS::FileManagement::CloudSync
53 
54 #endif // OHOS_FILEMGMT_DATA_SYNCER_RDB_STORE_H