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_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_STORE_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_STORE_H 18 #include <functional> 19 #include <memory> 20 21 #include "store/cursor.h" 22 #include "store/general_value.h" 23 #include "store/general_watcher.h" 24 namespace OHOS::DistributedData { 25 class CloudDB; 26 class AssetLoader; 27 struct Database; 28 class GeneralStore { 29 public: 30 using Watcher = GeneralWatcher; 31 using DetailAsync = GenAsync; 32 using Devices = std::vector<std::string>; 33 enum SyncMode { 34 NEARBY_BEGIN, 35 NEARBY_PUSH = NEARBY_BEGIN, 36 NEARBY_PULL, 37 NEARBY_PULL_PUSH, 38 NEARBY_END, 39 CLOUD_BEGIN = 4, 40 CLOUD_TIME_FIRST = CLOUD_BEGIN, 41 CLOUD_NATIVE_FIRST, 42 CLOUD_ClOUD_FIRST, 43 CLOUD_END, 44 MODE_BUTT = CLOUD_END, 45 }; 46 enum CleanMode { 47 NEARBY_DATA = 0, 48 CLOUD_DATA, 49 CLOUD_INFO, 50 LOCAL_DATA, 51 CLEAN_MODE_BUTT 52 }; 53 54 struct BindInfo { 55 BindInfo(std::shared_ptr<CloudDB> db = nullptr, std::shared_ptr<AssetLoader> loader = nullptr) db_BindInfo56 : db_(std::move(db)), loader_(std::move(loader)) 57 { 58 } 59 std::shared_ptr<CloudDB> db_; 60 std::shared_ptr<AssetLoader> loader_; 61 }; 62 virtual ~GeneralStore() = default; 63 64 virtual int32_t Bind(const Database &database, BindInfo bindInfo) = 0; 65 66 virtual bool IsBound() = 0; 67 68 virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; 69 70 virtual int32_t SetDistributedTables(const std::vector<std::string> &tables, int type); 71 72 virtual int32_t BatchInsert(const std::string &table, VBuckets &&values) = 0; 73 74 virtual int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) = 0; 75 76 virtual int32_t Delete(const std::string &table, const std::string &sql, Values &&args) = 0; 77 78 virtual std::shared_ptr<Cursor> Query(const std::string &table, const std::string &sql, Values &&args) = 0; 79 80 virtual std::shared_ptr<Cursor> Query(const std::string &table, GenQuery &query) = 0; 81 82 virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) = 0; 83 84 virtual int32_t Clean(const std::vector<std::string> &devices, int32_t mode, const std::string &tableName) = 0; 85 86 virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; 87 88 virtual int32_t Unwatch(int32_t origin, Watcher &watcher) = 0; 89 90 virtual int32_t Close() = 0; 91 92 virtual int32_t AddRef() = 0; 93 94 virtual int32_t Release() = 0; 95 }; 96 } // namespace OHOS::DistributedData 97 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_STORE_H 98