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 16 #include "kv_store_nb_conflict_data_impl.h" 17 18 namespace DistributedDB { KvStoreNbConflictDataImpl()19KvStoreNbConflictDataImpl::KvStoreNbConflictDataImpl() {} 20 ~KvStoreNbConflictDataImpl()21KvStoreNbConflictDataImpl::~KvStoreNbConflictDataImpl() {} 22 GetType() const23KvStoreNbConflictType KvStoreNbConflictDataImpl::GetType() const 24 { 25 return static_cast<KvStoreNbConflictType>(data_.type); 26 } 27 GetKey(Key & key) const28void KvStoreNbConflictDataImpl::GetKey(Key &key) const 29 { 30 key = data_.key; 31 } 32 GetValue(ValueType type,Value & value) const33DBStatus KvStoreNbConflictDataImpl::GetValue(ValueType type, Value &value) const 34 { 35 if (IsDeleted(type)) { 36 return DB_ERROR; 37 } 38 39 if (type == ValueType::OLD_VALUE) { 40 value = data_.oldData.value; 41 } else { 42 value = data_.newData.value; 43 } 44 45 return OK; 46 } 47 IsDeleted(ValueType type) const48bool KvStoreNbConflictDataImpl::IsDeleted(ValueType type) const 49 { 50 if (type == ValueType::OLD_VALUE) { 51 return data_.oldData.isDeleted; 52 } 53 return data_.newData.isDeleted; 54 } 55 IsNative(ValueType type) const56bool KvStoreNbConflictDataImpl::IsNative(ValueType type) const 57 { 58 if (type == ValueType::OLD_VALUE) { 59 return data_.oldData.isLocal; 60 } 61 return data_.newData.isLocal; 62 } 63 SetConflictData(const KvDBConflictEntry & conflictData)64void KvStoreNbConflictDataImpl::SetConflictData(const KvDBConflictEntry &conflictData) 65 { 66 data_ = conflictData; 67 } 68 } 69