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_VIRTUAL_DEVICE_H 16 #define RELATIONAL_VIRTUAL_DEVICE_H 17 #ifdef RELATIONAL_STORE 18 19 #include "data_transformer.h" 20 #include "db_common.h" 21 #include "generic_virtual_device.h" 22 #include "relational_schema_object.h" 23 #include "virtual_relational_ver_sync_db_interface.h" 24 25 namespace DistributedDB { 26 class RelationalVirtualDevice final : public GenericVirtualDevice { 27 public: 28 explicit RelationalVirtualDevice(const std::string &deviceId); 29 ~RelationalVirtualDevice() override; 30 31 int PutData(const std::string &tableName, const std::vector<VirtualRowData> &dataList); 32 int GetAllSyncData(const std::string &tableName, std::vector<VirtualRowData> &data); 33 int GetSyncData(const std::string &tableName, const std::string &hashKey, VirtualRowData &data); 34 void SetLocalFieldInfo(const std::vector<FieldInfo> &localFieldInfo); 35 void SetTableInfo(const TableInfo &tableInfo); 36 int Sync(SyncMode mode, bool wait) override; 37 void EraseSyncData(const std::string &tableName); 38 39 template<typename T> PutDeviceData(const std::string & tableName,const std::vector<T> & data)40 void PutDeviceData(const std::string &tableName, const std::vector<T> &data) 41 { 42 std::vector<VirtualRowData> dataList; 43 for (const auto &it : data) { 44 dataList.emplace_back(it()); 45 } 46 this->PutData(tableName, dataList); 47 } 48 }; 49 } 50 #endif 51 #endif // RELATIONAL_VIRTUAL_DEVICE_H 52