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_MANAGER_H 16 #define RELATIONAL_STORE_MANAGER_H 17 #include <string> 18 #include <functional> 19 #include <mutex> 20 21 #include "auto_launch_export.h" 22 #include "relational_store_delegate.h" 23 #include "store_types.h" 24 25 namespace DistributedDB { 26 class RelationalStoreManager final { 27 public: 28 // Only calculate the table name with device hash, no guarantee for the table exists 29 DB_API static std::string GetDistributedTableName(const std::string &device, const std::string &tableName); 30 31 DB_API RelationalStoreManager(const std::string &appId, const std::string &userId, int32_t instanceId = 0); 32 DB_API ~RelationalStoreManager() = default; 33 34 RelationalStoreManager(const RelationalStoreManager &) = delete; 35 RelationalStoreManager(RelationalStoreManager &&) = delete; 36 RelationalStoreManager &operator=(const RelationalStoreManager &) = delete; 37 RelationalStoreManager &operator=(RelationalStoreManager &&) = delete; 38 39 DB_API DBStatus OpenStore(const std::string &path, const std::string &storeId, 40 const RelationalStoreDelegate::Option &option, RelationalStoreDelegate *&delegate); 41 42 DB_API DBStatus CloseStore(RelationalStoreDelegate *store); 43 44 DB_API static void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback); 45 46 DB_API static std::string GetRelationalStoreIdentifier(const std::string &userId, const std::string &appId, 47 const std::string &storeId, bool syncDualTupleMode = false); 48 49 private: 50 std::string appId_; 51 std::string userId_; 52 int32_t instanceId_; 53 }; 54 } // namespace DistributedDB 55 #endif // RELATIONAL_STORE_MANAGER_H