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 "kvdb_properties.h"
17
18 #include "db_constant.h"
19
20 namespace DistributedDB {
21 const std::string KvDBProperties::FILE_NAME = "fileName";
22 const std::string KvDBProperties::MEMORY_MODE = "memoryMode";
23 const std::string KvDBProperties::ENCRYPTED_MODE = "isEncryptedDb";
24 const std::string KvDBProperties::FIRST_OPEN_IS_READ_ONLY = "firstOpenIsReadOnly";
25 const std::string KvDBProperties::CREATE_DIR_BY_STORE_ID_ONLY = "createDirByStoreIdOnly";
26 const std::string KvDBProperties::SECURITY_LABEL = "securityLabel";
27 const std::string KvDBProperties::SECURITY_FLAG = "securityFlag";
28 const std::string KvDBProperties::CONFLICT_RESOLVE_POLICY = "conflictResolvePolicy";
29 const std::string KvDBProperties::CHECK_INTEGRITY = "checkIntegrity";
30 const std::string KvDBProperties::RM_CORRUPTED_DB = "rmCorruptedDb";
31 const std::string KvDBProperties::COMPRESS_ON_SYNC = "needCompressOnSync";
32 const std::string KvDBProperties::COMPRESSION_RATE = "compressionRate";
33
KvDBProperties()34 KvDBProperties::KvDBProperties()
35 : cipherType_(CipherType::AES_256_GCM)
36 {}
37
~KvDBProperties()38 KvDBProperties::~KvDBProperties() {}
39
GetStoreSubDirectory(int type)40 std::string KvDBProperties::GetStoreSubDirectory(int type)
41 {
42 switch (type) {
43 case LOCAL_TYPE:
44 return DBConstant::LOCAL_SUB_DIR;
45 case MULTI_VER_TYPE:
46 return DBConstant::MULTI_SUB_DIR;
47 case SINGLE_VER_TYPE:
48 return DBConstant::SINGLE_SUB_DIR;
49 default:
50 return "unknown";
51 }
52 }
53
GetPassword(CipherType & type,CipherPassword & password) const54 void KvDBProperties::GetPassword(CipherType &type, CipherPassword &password) const
55 {
56 type = cipherType_;
57 password = password_;
58 }
59
SetPassword(CipherType type,const CipherPassword & password)60 void KvDBProperties::SetPassword(CipherType type, const CipherPassword &password)
61 {
62 cipherType_ = type;
63 password_ = password;
64 }
65
IsSchemaExist() const66 bool KvDBProperties::IsSchemaExist() const
67 {
68 return schema_.IsSchemaValid();
69 }
70
SetSchema(const SchemaObject & schema)71 void KvDBProperties::SetSchema(const SchemaObject &schema)
72 {
73 schema_ = schema;
74 }
75
GetSchema() const76 SchemaObject KvDBProperties::GetSchema() const
77 {
78 return schema_;
79 }
80
GetSecLabel() const81 int KvDBProperties::GetSecLabel() const
82 {
83 return GetIntProp(KvDBProperties::SECURITY_LABEL, 0);
84 }
85
GetSecFlag() const86 int KvDBProperties::GetSecFlag() const
87 {
88 return GetIntProp(KvDBProperties::SECURITY_FLAG, 0);
89 }
90
GetSchemaConstRef() const91 const SchemaObject &KvDBProperties::GetSchemaConstRef() const
92 {
93 return schema_;
94 }
95 } // namespace DistributedDB
96