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 Sync(const std::vector<std::string> &devices, SyncMode mode, 33 const Query &query, const SyncStatusCallback &onComplete, bool wait) override; 34 35 int32_t GetCloudSyncTaskCount() override; 36 37 DBStatus RemoveDeviceDataInner(const std::string &device, ClearMode mode) override; 38 39 DBStatus DoClean(ClearMode mode); 40 41 DBStatus CreateDistributedTableInner(const std::string &tableName, TableSyncType type) override; 42 43 DBStatus RemoveDeviceData(const std::string &device, const std::string &tableName) override; 44 45 // For connection 46 DBStatus Close(); 47 48 void SetReleaseFlag(bool flag); 49 50 DBStatus RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, 51 std::shared_ptr<ResultSet> &result) override; 52 53 DBStatus RemoveDeviceData() override; 54 55 DBStatus Sync(const std::vector<std::string> &devices, SyncMode mode, const Query &query, 56 const SyncProcessCallback &onProcess, int64_t waitTime) override; 57 58 DBStatus SetCloudDB(const std::shared_ptr<ICloudDb> &cloudDb) override; 59 60 DBStatus SetCloudDbSchema(const DataBaseSchema &schema) override; 61 62 DBStatus RegisterObserver(StoreObserver *observer) override; 63 64 DBStatus UnRegisterObserver() override; 65 66 DBStatus SetIAssetLoader(const std::shared_ptr<IAssetLoader> &loader) override; 67 private: 68 static void OnSyncComplete(const std::map<std::string, std::vector<TableStatus>> &devicesStatus, 69 const SyncStatusCallback &onComplete); 70 71 RelationalStoreConnection *conn_ = nullptr; 72 std::string storePath_; 73 std::atomic<bool> releaseFlag_ = false; 74 }; 75 } // namespace DistributedDB 76 #endif 77 #endif // RELATIONAL_STORE_DELEGATE_IMPL_H