• 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 "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::LOCAL_ONLY = "localOnly";
32 
33 const std::string KvDBProperties::SHARED_MODE = "sharedMode";
34 const std::string KvDBProperties::READ_ONLY_MODE = "read_only";
35 const std::string KvDBProperties::PAGE_SIZE = "pageSize";
36 const std::string KvDBProperties::INDEX_TYPE = "indexType";
37 const std::string KvDBProperties::CACHE_SIZE = "cacheSize";
38 
KvDBProperties()39 KvDBProperties::KvDBProperties()
40     : cipherType_(CipherType::AES_256_GCM)
41 {}
42 
~KvDBProperties()43 KvDBProperties::~KvDBProperties() {}
44 
GetStoreSubDirectory(int type)45 std::string KvDBProperties::GetStoreSubDirectory(int type)
46 {
47     switch (type) {
48         case LOCAL_TYPE_SQLITE:
49             return DBConstant::LOCAL_SUB_DIR;
50         case MULTI_VER_TYPE_SQLITE:
51             return DBConstant::MULTI_SUB_DIR;
52         case SINGLE_VER_TYPE_SQLITE:
53             return DBConstant::SINGLE_SUB_DIR;
54         default:
55             return "unknown";
56     }
57 }
58 
GetPassword(CipherType & type,CipherPassword & password) const59 void KvDBProperties::GetPassword(CipherType &type, CipherPassword &password) const
60 {
61     type = cipherType_;
62     password = password_;
63 }
64 
SetPassword(CipherType type,const CipherPassword & password)65 void KvDBProperties::SetPassword(CipherType type, const CipherPassword &password)
66 {
67     cipherType_ = type;
68     password_ = password;
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