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 NATIVE_RDB_RDB_STORE_CONFIG_H 17 #define NATIVE_RDB_RDB_STORE_CONFIG_H 18 19 #include <string> 20 #include <vector> 21 22 namespace OHOS { 23 namespace NativeRdb { 24 25 // indicates the type of the storage 26 enum class StorageMode { 27 MODE_MEMORY = 101, 28 MODE_DISK, 29 }; 30 31 enum class JournalMode { 32 MODE_DELETE, 33 MODE_TRUNCATE, 34 MODE_PERSIST, 35 MODE_MEMORY, 36 MODE_WAL, 37 MODE_OFF, 38 }; 39 40 enum class SyncMode { 41 MODE_OFF, 42 MODE_NORMAL, 43 MODE_FULL, 44 MODE_EXTRA, 45 }; 46 47 enum class DatabaseFileType { 48 NORMAL, 49 BACKUP, 50 CORRUPT, 51 }; 52 53 enum class DatabaseFileSecurityLevel { 54 S4, 55 S3, 56 S2, 57 S1, 58 S0, 59 NO_LEVEL, 60 }; 61 62 class RdbStoreConfig { 63 public: 64 RdbStoreConfig(const RdbStoreConfig &config); 65 RdbStoreConfig(const std::string &path, StorageMode storageMode = StorageMode::MODE_DISK, bool readOnly = false, 66 const std::vector<uint8_t> &encryptKey = std::vector<uint8_t>(), const std::string &journalMode = "", 67 const std::string &syncMode = "", const std::string &databaseFileType = "", 68 const std::string &databaseFileSecurityLevel = ""); 69 ~RdbStoreConfig(); 70 std::string GetName() const; 71 std::string GetPath() const; 72 StorageMode GetStorageMode() const; 73 std::string GetJournalMode() const; 74 std::string GetSyncMode() const; 75 std::vector<uint8_t> GetEncryptKey() const; 76 bool IsReadOnly() const; 77 bool IsMemoryRdb() const; 78 std::string GetDatabaseFileType() const; 79 std::string GetDatabaseFileSecurityLevel() const; 80 81 // set the journal mode, if not set, the default mode is WAL 82 void SetName(const std::string &name); 83 void SetJournalMode(JournalMode journalMode); 84 void SetPath(std::string path); 85 void SetReadOnly(bool readOnly); 86 void SetStorageMode(StorageMode storageMode); 87 void SetDatabaseFileType(DatabaseFileType type); 88 void SetEncryptKey(const std::vector<uint8_t> &encryptKey); 89 void ClearEncryptKey(); 90 91 static std::string GetJournalModeValue(JournalMode journalMode); 92 static std::string GetSyncModeValue(SyncMode syncMode); 93 static std::string GetDatabaseFileTypeValue(DatabaseFileType databaseFileType); 94 static std::string GetDatabaseFileSecurityLevelValue(DatabaseFileSecurityLevel databaseFileSecurityLevel); 95 96 private: 97 std::string name; 98 std::string path; 99 StorageMode storageMode; 100 std::string journalMode; 101 std::string syncMode; 102 std::vector<uint8_t> encryptKey; 103 bool readOnly; 104 std::string databaseFileType; 105 std::string databaseFileSecurityLevel; 106 }; 107 108 } // namespace NativeRdb 109 } // namespace OHOS 110 111 #endif