1 /* 2 * Copyright (c) 2024 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 APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_DATA_MANAGER_H 17 #define APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_DATA_MANAGER_H 18 19 #include <mutex> 20 #include "cpp/mutex.h" 21 #include "event_handler.h" 22 #include "rdb_store.h" 23 #include "values_bucket.h" 24 #include "app_details_rdb_data_define.h" 25 #include "ffrt.h" 26 27 namespace OHOS { 28 namespace AppDomainVerify { 29 using RdbForEachRetCb = std::function<bool(std::shared_ptr<AbsSharedResultSet> retSet)>; 30 class AppDetailsRdbDataMgr : public std::enable_shared_from_this<AppDetailsRdbDataMgr> { 31 public: 32 AppDetailsRdbDataMgr(bool createFile); 33 AppDetailsRdbDataMgr(const RdbConfigInfo& info); 34 virtual ~AppDetailsRdbDataMgr(); 35 bool ExecWithTrans(TransCallback cb); 36 bool InsertDataBatch(const std::string& tableName, std::vector<AppDetailsRdbItem>& itemVec); 37 bool QueryDataByDomain(const std::string& tableName, 38 const std::string& domain, std::vector<AppDetailsRdbItem>& itemVec); 39 bool UpdateMetaData(std::vector<MetaItem>& item); 40 bool QueryMetaData(const std::string& tableName, MetaItem& info); 41 bool CreateMetaData(); 42 bool CreateTable(const std::string& tableName); 43 bool CreateRegularIndex(const std::string& tableName, const std::string& colName); 44 bool DeleteTable(const std::string& tableName); 45 bool RenameTable(const std::string& oldName, const std::string& newName); 46 std::string GetDbVersion(); 47 private: 48 void PostDelayCloseTask(int32_t delayTime); 49 bool Query(const NativeRdb::AbsRdbPredicates& predicates, 50 const std::vector<std::string>& columns, RdbForEachRetCb cb); 51 bool CheckRdbReturnIfOk(int errcode); 52 std::shared_ptr<NativeRdb::RdbStore> GetRdbStore(); 53 private: 54 ffrt::mutex mtx_; 55 std::shared_ptr<NativeRdb::RdbStore> rdbStore_; 56 RdbConfigInfo conf_; 57 std::shared_ptr<AppExecFwk::EventHandler> closeHandler_; 58 std::shared_ptr<AppExecFwk::EventRunner> runner_; 59 }; 60 61 } // namespace AppDomainVerify 62 } // namespace OHOS 63 #endif 64