1 /* 2 * Copyright (c) 2021-2022 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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_DATABSE_OPERATOR_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_DATABSE_OPERATOR_H 18 19 #include <memory> 20 #include "account_data_storage.h" 21 #include "ios_account_control.h" 22 23 namespace OHOS { 24 namespace AccountSA { 25 class OsAccountDatabaseOperator { 26 public: 27 OsAccountDatabaseOperator(); 28 virtual ~OsAccountDatabaseOperator(); 29 void Init(); 30 31 // update infos to database 32 void UpdateOsAccountIDListInDatabase(const Json &accountListJson); 33 void UpdateOsAccountInDatabase(const OsAccountInfo &osAccountInfo); 34 void InsertOsAccountIntoDataBase(const OsAccountInfo &osAccountInfo); 35 void DelOsAccountFromDatabase(const int id); 36 37 ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum); 38 ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber); 39 ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id); 40 ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id, OsAccountInfo &osAccountInfo); 41 ErrCode GetOsAccountListFromDatabase(const std::string& storeID, std::vector<OsAccountInfo> &osAccountList); 42 43 private: 44 ErrCode GetAccountListFromStoreID(const std::string& storeID, Json &accountListJson); 45 ErrCode SaveAccountListToDatabase(const Json &accountListJson); 46 bool InnerInit(); 47 48 private: 49 std::shared_ptr<AccountDataStorage> accountDataStorage_; 50 std::string storeID_; 51 }; 52 } // namespace AccountSA 53 } // namespace OHOS 54 55 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_CONTROL_DATABSE_MANAGER_H