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