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 SecurityLevel : int32_t { 53 S1 = 1, 54 S2, 55 S3, 56 S4, 57 LAST 58 }; 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 SecurityLevel securityLevel = SecurityLevel::LAST, bool isCreateNecessary = true); 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 bool IsReadOnly() const; 77 bool IsMemoryRdb() const; 78 std::string GetDatabaseFileType() const; 79 SecurityLevel GetSecurityLevel() const; 80 void SetEncryptStatus(const bool status); 81 bool IsEncrypt() const; 82 bool IsCreateNecessary() const; 83 // set the journal mode, if not set, the default mode is WAL 84 void SetName(std::string name); 85 void SetJournalMode(JournalMode journalMode); 86 void SetPath(std::string path); 87 void SetReadOnly(bool readOnly); 88 void SetStorageMode(StorageMode storageMode); 89 void SetDatabaseFileType(DatabaseFileType type); 90 void SetSecurityLevel(SecurityLevel secLevel); 91 void SetCreateNecessary(bool isCreateNecessary); 92 93 // distributed rdb 94 int SetBundleName(const std::string &bundleName); 95 std::string GetBundleName() const; 96 int SetDistributedType(DistributedType type); 97 DistributedType GetDistributedType() const; 98 void SetModuleName(const std::string& moduleName); 99 std::string GetModuleName() const; 100 void SetServiceName(const std::string& serviceName); 101 void SetArea(int32_t area); 102 int32_t GetArea() const; 103 std::string GetUri() const; 104 void SetUri(const std::string& uri); 105 std::string GetReadPermission() const; 106 void SetReadPermission(const std::string& permission); 107 std::string GetWritePermission() const; 108 void SetWritePermission(const std::string& permission); 109 110 static std::string GetJournalModeValue(JournalMode journalMode); 111 static std::string GetSyncModeValue(SyncMode syncMode); 112 static std::string GetDatabaseFileTypeValue(DatabaseFileType databaseFileType); 113 114 private: 115 std::string name; 116 std::string path; 117 StorageMode storageMode; 118 std::string journalMode; 119 std::string syncMode; 120 bool readOnly; 121 std::string databaseFileType; 122 123 // distributed rdb 124 DistributedType distributedType_ = DistributedRdb::RdbDistributedType::RDB_DEVICE_COLLABORATION; 125 int32_t area_ = 0; 126 std::string bundleName_; 127 std::string moduleName_; 128 129 bool isEncrypt_ = false; 130 SecurityLevel securityLevel = SecurityLevel::LAST; 131 std::string uri_; 132 std::string readPermission_; 133 std::string writePermission_; 134 bool isCreateNecessary_; 135 }; 136 } // namespace OHOS::NativeRdb 137 138 #endif 139