• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()19 KvStoreNbConflictDataImpl::KvStoreNbConflictDataImpl() {}
20 
~KvStoreNbConflictDataImpl()21 KvStoreNbConflictDataImpl::~KvStoreNbConflictDataImpl() {}
22 
GetType() const23 KvStoreNbConflictType KvStoreNbConflictDataImpl::GetType() const
24 {
25     return static_cast<KvStoreNbConflictType>(data_.type);
26 }
27 
GetKey(Key & key) const28 void KvStoreNbConflictDataImpl::GetKey(Key &key) const
29 {
30     key = data_.key;
31 }
32 
GetValue(ValueType type,Value & value) const33 DBStatus 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) const48 bool KvStoreNbConflictDataImpl::IsDeleted(ValueType type) const
49 {
50     if (type == ValueType::OLD_VALUE) {
51         return data_.oldData.isDeleted;
52     } else {
53         return data_.newData.isDeleted;
54     }
55 }
56 
IsNative(ValueType type) const57 bool KvStoreNbConflictDataImpl::IsNative(ValueType type) const
58 {
59     if (type == ValueType::OLD_VALUE) {
60         return data_.oldData.isLocal;
61     } else {
62         return data_.newData.isLocal;
63     }
64 }
65 
SetConflictData(const KvDBConflictEntry & conflictData)66 void KvStoreNbConflictDataImpl::SetConflictData(const KvDBConflictEntry &conflictData)
67 {
68     data_ = conflictData;
69 }
70 }
71