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 #ifndef DB_PROPERTIES_H 16 #define DB_PROPERTIES_H 17 18 #include <map> 19 #include <string> 20 21 namespace DistributedDB { 22 class DBProperties { 23 public: 24 DBProperties() = default; 25 virtual ~DBProperties() = default; 26 27 // Get the string property according the name 28 std::string GetStringProp(const std::string &name, const std::string &defaultValue) const; 29 30 // Set the string property for the name 31 void SetStringProp(const std::string &name, const std::string &value); 32 33 // Get the bool property according the name 34 bool GetBoolProp(const std::string &name, bool defaultValue) const; 35 36 // Set the bool property for the name 37 void SetBoolProp(const std::string &name, bool value); 38 39 // Get the integer property according the name 40 int GetIntProp(const std::string &name, int defaultValue) const; 41 42 // Set the integer property for the name 43 void SetIntProp(const std::string &name, int value); 44 45 // Get the unsigned integer property according the name 46 uint32_t GetUIntProp(const std::string &name, uint32_t defaultValue) const; 47 48 // Set the unsigned integer property for the name 49 void SetUIntProp(const std::string &name, uint32_t value); 50 51 // Set all indentifers 52 void SetIdentifier(const std::string &userId, const std::string &appId, const std::string &storeId, 53 const std::string &subUser = "", int32_t instanceId = 0); 54 55 static constexpr const char *CREATE_IF_NECESSARY = "createIfNecessary"; 56 static constexpr const char *DATA_DIR = "dataDir"; 57 static constexpr const char *USER_ID = "userId"; 58 static constexpr const char *APP_ID = "appId"; 59 static constexpr const char *STORE_ID = "storeId"; 60 static constexpr const char *INSTANCE_ID = "instanceId"; 61 static constexpr const char *SUB_USER = "subUser"; 62 static constexpr const char *IDENTIFIER_DATA = "identifier"; 63 static constexpr const char *IDENTIFIER_DIR = "identifierDir"; 64 static constexpr const char *DUAL_TUPLE_IDENTIFIER_DATA = "dualTupleIdentifier"; 65 static constexpr const char *SYNC_DUAL_TUPLE_MODE = "syncDualTuple"; 66 static constexpr const char *AUTO_LAUNCH_ID = "autoLaunchID"; 67 68 static constexpr const char *DATABASE_TYPE = "databaseType"; 69 70 protected: 71 72 std::map<std::string, std::string> stringProperties_; 73 std::map<std::string, bool> boolProperties_; 74 std::map<std::string, int> intProperties_; 75 std::map<std::string, uint32_t> uintProperties_; 76 }; 77 } 78 #endif