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 #include <rdb_types.h> 22 23 namespace OHOS::NativeRdb { 24 // indicates the type of the storage 25 enum class StorageMode { 26 MODE_MEMORY = 101, 27 MODE_DISK, 28 }; 29 30 enum class JournalMode { 31 MODE_DELETE, 32 MODE_TRUNCATE, 33 MODE_PERSIST, 34 MODE_MEMORY, 35 MODE_WAL, 36 MODE_OFF, 37 }; 38 39 enum class SyncMode { 40 MODE_OFF, 41 MODE_NORMAL, 42 MODE_FULL, 43 MODE_EXTRA, 44 }; 45 46 enum class DatabaseFileType { 47 NORMAL, 48 BACKUP, 49 CORRUPT, 50 }; 51 52 enum class DatabaseFileSecurityLevel { 53 S4, 54 S3, 55 S2, 56 S1, 57 S0, 58 NO_LEVEL, 59 }; 60 61 using DistributedType = OHOS::DistributedRdb::RdbDistributedType; 62 63 class RdbStoreConfig { 64 public: 65 RdbStoreConfig(const RdbStoreConfig &config); 66 RdbStoreConfig(const std::string &path, StorageMode storageMode = StorageMode::MODE_DISK, bool readOnly = false, 67 const std::vector<uint8_t> &encryptKey = std::vector<uint8_t>(), const std::string &journalMode = "", 68 const std::string &syncMode = "", const std::string &databaseFileType = "", 69 const std::string &databaseFileSecurityLevel = ""); 70 ~RdbStoreConfig(); 71 std::string GetName() const; 72 std::string GetPath() const; 73 StorageMode GetStorageMode() const; 74 std::string GetJournalMode() const; 75 std::string GetSyncMode() const; 76 std::vector<uint8_t> GetEncryptKey() const; 77 bool IsReadOnly() const; 78 bool IsMemoryRdb() const; 79 std::string GetDatabaseFileType() const; 80 std::string GetDatabaseFileSecurityLevel() const; 81 82 // set the journal mode, if not set, the default mode is WAL 83 void SetName(const std::string &name); 84 void SetJournalMode(JournalMode journalMode); 85 void SetPath(std::string path); 86 void SetReadOnly(bool readOnly); 87 void SetStorageMode(StorageMode storageMode); 88 void SetDatabaseFileType(DatabaseFileType type); 89 void SetEncryptKey(const std::vector<uint8_t> &encryptKey); 90 void ClearEncryptKey(); 91 92 // distributed rdb 93 int SetBundleName(const std::string &bundleName); 94 std::string GetBundleName() const; 95 int SetDistributedType(DistributedType type); 96 DistributedType GetDistributedType() const; 97 void SetAppModuleName(const std::string& moduleName); 98 std::string GetAppModuleName() const; 99 void SetRelativePath(const std::string& relativePath); 100 std::string GetRelativePath() const; 101 void SetServiceName(const std::string& serviceName); 102 void SetEncryptLevel(const std::string& secLevel); 103 std::string GetEncryptLevel() const; 104 105 static std::string GetJournalModeValue(JournalMode journalMode); 106 static std::string GetSyncModeValue(SyncMode syncMode); 107 static std::string GetDatabaseFileTypeValue(DatabaseFileType databaseFileType); 108 static std::string GetDatabaseFileSecurityLevelValue(DatabaseFileSecurityLevel databaseFileSecurityLevel); 109 110 private: 111 std::string name; 112 std::string path; 113 StorageMode storageMode; 114 std::string journalMode; 115 std::string syncMode; 116 std::vector<uint8_t> encryptKey; 117 bool readOnly; 118 std::string databaseFileType; 119 std::string databaseFileSecurityLevel; 120 121 // distributed rdb 122 DistributedType distributedType_ = DistributedRdb::RdbDistributedType::RDB_DEVICE_COLLABORATION; 123 std::string bundleName_; 124 std::string moduleName_; 125 std::string relativePath_; 126 std::string encryptLevel_; 127 }; 128 } 129 130 #endif 131