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 #ifndef KV_DB_PROPERTIES_H
17 #define KV_DB_PROPERTIES_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "db_properties.h"
24 #include "schema_object.h"
25 
26 namespace DistributedDB {
27 class KvDBProperties final : public DBProperties {
28 public:
29     KvDBProperties();
30     ~KvDBProperties() override;
31 
32     // Get the sub directory for different type database.
33     static std::string GetStoreSubDirectory(int type);
34 
35     // Get the password
36     void GetPassword(CipherType &type, CipherPassword &password) const;
37 
38     // Set the password
39     void SetPassword(CipherType type, const CipherPassword &password);
40 
41     // set schema
42     void SetSchema(const SchemaObject &schema);
43 
44     // get schema
45     SchemaObject GetSchema() const;
46 
47     // If it does not exist, use the int map default value 0
48     int GetSecLabel() const;
49 
50     int GetSecFlag() const;
51 
52     // Get schema const reference if you can guarantee the lifecycle of this KvDBProperties
53     // The upper code will not change the schema if it is already set
54     const SchemaObject &GetSchemaConstRef() const;
55 
56     static const std::string FILE_NAME;
57     static const std::string SYNC_MODE;
58     static const std::string MEMORY_MODE;
59     static const std::string ENCRYPTED_MODE;
60     static const std::string FIRST_OPEN_IS_READ_ONLY;
61     static const std::string CREATE_DIR_BY_STORE_ID_ONLY;
62     static const std::string SECURITY_LABEL;
63     static const std::string SECURITY_FLAG;
64     static const std::string CONFLICT_RESOLVE_POLICY;
65     static const std::string CHECK_INTEGRITY;
66     static const std::string RM_CORRUPTED_DB;
67     static const std::string COMPRESS_ON_SYNC;
68     static const std::string COMPRESSION_RATE;
69     static const std::string LOCAL_ONLY;
70 
71     static const std::string SHARED_MODE;
72     static const std::string READ_ONLY_MODE;
73     static const std::string PAGE_SIZE;
74     static const std::string INDEX_TYPE;
75     static const std::string CACHE_SIZE;
76 
77     static const int LOCAL_TYPE_SQLITE = 1;
78     static const int MULTI_VER_TYPE_SQLITE = 2;
79     static const int SINGLE_VER_TYPE_SQLITE = 3;
80     static const int SINGLE_VER_TYPE_RD_KERNAL = 4;
81 
82 private:
83     CipherType cipherType_;
84     CipherPassword password_;
85     SchemaObject schema_;
86 };
87 } // namespace DistributedDB
88 
89 #endif // KV_DB_PROPERTIES_H
90