• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef RELATIONAL_STORE_DELEGATE_IMPL_H
16 #define RELATIONAL_STORE_DELEGATE_IMPL_H
17 #ifdef RELATIONAL_STORE
18 
19 #include "macro_utils.h"
20 #include "relational_store_connection.h"
21 
22 namespace DistributedDB {
23 class RelationalStoreDelegateImpl final : public RelationalStoreDelegate {
24 public:
25     RelationalStoreDelegateImpl() = default;
26     ~RelationalStoreDelegateImpl() override;
27 
28     RelationalStoreDelegateImpl(RelationalStoreConnection *conn, const std::string &path);
29 
30     DISABLE_COPY_ASSIGN_MOVE(RelationalStoreDelegateImpl);
31 
32     DBStatus SetStoreConfig(const StoreConfig &config) override;
33 
34     DBStatus Sync(const std::vector<std::string> &devices, SyncMode mode,
35         const Query &query, const SyncStatusCallback &onComplete, bool wait) override;
36 
37     DBStatus RemoveDeviceDataInner(const std::string &device, ClearMode mode) override;
38 
39     DBStatus CreateDistributedTableInner(const std::string &tableName, TableSyncType type) override;
40 
41     DBStatus RemoveDeviceData(const std::string &device, const std::string &tableName) override;
42 
43     // For connection
44     DBStatus Close();
45 
46     void SetReleaseFlag(bool flag);
47 
48     DBStatus RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout,
49         std::shared_ptr<ResultSet> &result) override;
50 
51     DBStatus RemoveDeviceData() override;
52 
53     DBStatus RegisterObserver(StoreObserver *observer) override;
54 
55     DBStatus UnRegisterObserver() override;
56 
57     DBStatus UnRegisterObserver(StoreObserver *observer) override;
58 
59     DBStatus SetTrackerTable(const TrackerSchema &schema) override;
60 
61     DBStatus ExecuteSql(const SqlCondition &condition, std::vector<VBucket> &records) override;
62 
63     DBStatus SetReference(const std::vector<TableReferenceProperty> &tableReferenceProperty) override;
64 
65     DBStatus CleanTrackerData(const std::string &tableName, int64_t cursor) override;
66 
67     DBStatus Pragma(PragmaCmd cmd, PragmaData &pragmaData) override;
68 
69     DBStatus UpsertData(const std::string &tableName, const std::vector<VBucket> &records,
70         RecordStatus status) override;
71 
72     DBStatus SetDistributedSchema(const DistributedSchema &schema, bool isForceUpgrade) override;
73 
74     std::pair<DBStatus, int32_t> GetDownloadingAssetsCount() override;
75 
76 #ifdef USE_DISTRIBUTEDDB_CLOUD
77     int32_t GetCloudSyncTaskCount() override;
78 
79     DBStatus SetCloudDB(const std::shared_ptr<ICloudDb> &cloudDb) override;
80 
81     DBStatus SetCloudDbSchema(const DataBaseSchema &schema) override;
82 
83     DBStatus Sync(const std::vector<std::string> &devices, SyncMode mode, const Query &query,
84         const SyncProcessCallback &onProcess, int64_t waitTime) override;
85 
86     DBStatus Sync(const CloudSyncOption &option, const SyncProcessCallback &onProcess) override;
87 
88     DBStatus SetCloudSyncConfig(const CloudSyncConfig &config) override;
89 
90     DBStatus Sync(const CloudSyncOption &option, const SyncProcessCallback &onProcess, uint64_t taskId) override;
91 
92     SyncProcess GetCloudTaskStatus(uint64_t taskId) override;
93 
94     DBStatus SetIAssetLoader(const std::shared_ptr<IAssetLoader> &loader) override;
95 
96     DBStatus ClearMetaData(const ClearMetaDataOption &option) override;
97 #endif
98     int32_t GetDeviceSyncTaskCount() override;
99 private:
100     static void OnSyncComplete(const std::map<std::string, std::vector<TableStatus>> &devicesStatus,
101         const SyncStatusCallback &onComplete);
102 
103 #ifdef USE_DISTRIBUTEDDB_CLOUD
104     DBStatus ClearWatermark(const ClearMetaDataOption &option);
105 #endif
106     DBStatus OperateDataStatus(uint32_t dataOperator) override;
107     RelationalStoreConnection *conn_ = nullptr;
108     std::string storePath_;
109     std::atomic<bool> releaseFlag_ = false;
110 };
111 } // namespace DistributedDB
112 #endif
113 #endif // RELATIONAL_STORE_DELEGATE_IMPL_H