1 /* 2 * Copyright (c) 2022 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 #include "single_ver_relational_sync_task_context.h" 17 #include "db_common.h" 18 19 #ifdef RELATIONAL_STORE 20 namespace DistributedDB { SingleVerRelationalSyncTaskContext()21SingleVerRelationalSyncTaskContext::SingleVerRelationalSyncTaskContext() 22 : SingleVerSyncTaskContext() 23 {} 24 ~SingleVerRelationalSyncTaskContext()25SingleVerRelationalSyncTaskContext::~SingleVerRelationalSyncTaskContext() 26 { 27 } 28 GetQuerySyncId() const29std::string SingleVerRelationalSyncTaskContext::GetQuerySyncId() const 30 { 31 return querySyncId_; 32 } 33 GetDeleteSyncId() const34std::string SingleVerRelationalSyncTaskContext::GetDeleteSyncId() const 35 { 36 return deleteSyncId_; 37 } 38 Clear()39void SingleVerRelationalSyncTaskContext::Clear() 40 { 41 querySyncId_.clear(); 42 deleteSyncId_.clear(); 43 SingleVerSyncTaskContext::Clear(); 44 } 45 CopyTargetData(const ISyncTarget * target,const TaskParam & TaskParam)46void SingleVerRelationalSyncTaskContext::CopyTargetData(const ISyncTarget *target, const TaskParam &TaskParam) 47 { 48 SingleVerSyncTaskContext::CopyTargetData(target, TaskParam); 49 std::string hashTableName = DBCommon::TransferHashString(query_.GetRelationTableName()); 50 std::string hexTableName = DBCommon::TransferStringToHex(hashTableName); 51 querySyncId_ = hexTableName + query_.GetIdentify(); // save as deviceId + hexTableName + queryId 52 deleteSyncId_ = GetDeviceId() + hexTableName; // save as deviceId + hexTableName 53 } 54 SetRelationalSyncStrategy(RelationalSyncStrategy strategy)55void SingleVerRelationalSyncTaskContext::SetRelationalSyncStrategy(RelationalSyncStrategy strategy) 56 { 57 std::lock_guard<std::mutex> autoLock(syncStrategyMutex_); 58 relationalSyncStrategy_ = strategy; 59 } 60 GetSyncStrategy(QuerySyncObject & querySyncObject) const61SyncStrategy SingleVerRelationalSyncTaskContext::GetSyncStrategy(QuerySyncObject &querySyncObject) const 62 { 63 std::lock_guard<std::mutex> autoLock(syncStrategyMutex_); 64 auto it = relationalSyncStrategy_.find(querySyncObject.GetRelationTableName()); 65 if (it == relationalSyncStrategy_.end()) { 66 return {}; 67 } 68 return it->second; 69 } 70 SetIsNeedResetAbilitySync(bool isNeedReset)71void SingleVerRelationalSyncTaskContext::SetIsNeedResetAbilitySync(bool isNeedReset) 72 { 73 isNeedResetAbilitySync_ = isNeedReset; 74 if (isNeedResetAbilitySync_) { 75 SetIsSchemaSync(false); 76 } 77 } 78 SchemaChange()79void SingleVerRelationalSyncTaskContext::SchemaChange() 80 { 81 SetIsNeedResetAbilitySync(true); 82 std::lock_guard<std::mutex> autoLock(syncStrategyMutex_); 83 relationalSyncStrategy_ = {}; 84 } 85 } 86 #endif