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 const std::string KvDBProperties::LOCAL_ONLY = "localOnly";
34 
35 const std::string KvDBProperties::SHARED_MODE = "sharedMode";
36 const std::string KvDBProperties::READ_ONLY_MODE = "read_only";
37 const std::string KvDBProperties::PAGE_SIZE = "pageSize";
38 const std::string KvDBProperties::INDEX_TYPE = "indexType";
39 const std::string KvDBProperties::CACHE_SIZE = "cacheSize";
40 
KvDBProperties()41 KvDBProperties::KvDBProperties()
42     : cipherType_(CipherType::AES_256_GCM)
43 {}
44 
~KvDBProperties()45 KvDBProperties::~KvDBProperties() {}
46 
GetStoreSubDirectory(int type)47 std::string KvDBProperties::GetStoreSubDirectory(int type)
48 {
49     switch (type) {
50         case LOCAL_TYPE_SQLITE:
51             return DBConstant::LOCAL_SUB_DIR;
52         case MULTI_VER_TYPE_SQLITE:
53             return DBConstant::MULTI_SUB_DIR;
54         case SINGLE_VER_TYPE_SQLITE:
55             return DBConstant::SINGLE_SUB_DIR;
56         default:
57             return "unknown";
58     }
59 }
60 
GetPassword(CipherType & type,CipherPassword & password) const61 void KvDBProperties::GetPassword(CipherType &type, CipherPassword &password) const
62 {
63     type = cipherType_;
64     password = password_;
65 }
66 
SetPassword(CipherType type,const CipherPassword & password)67 void KvDBProperties::SetPassword(CipherType type, const CipherPassword &password)
68 {
69     cipherType_ = type;
70     password_ = password;
71 }
72 
SetSchema(const SchemaObject & schema)73 void KvDBProperties::SetSchema(const SchemaObject &schema)
74 {
75     schema_ = schema;
76 }
77 
GetSchema() const78 SchemaObject KvDBProperties::GetSchema() const
79 {
80     return schema_;
81 }
82 
GetSecLabel() const83 int KvDBProperties::GetSecLabel() const
84 {
85     return GetIntProp(KvDBProperties::SECURITY_LABEL, 0);
86 }
87 
GetSecFlag() const88 int KvDBProperties::GetSecFlag() const
89 {
90     return GetIntProp(KvDBProperties::SECURITY_FLAG, 0);
91 }
92 
GetSchemaConstRef() const93 const SchemaObject &KvDBProperties::GetSchemaConstRef() const
94 {
95     return schema_;
96 }
97 } // namespace DistributedDB
98