/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_RDB_RDB_DATA_MANAGER_H #define OHOS_ABILITY_RUNTIME_RDB_RDB_DATA_MANAGER_H #include #include #include #include "rdb_helper.h" #include "rdb_open_callback.h" namespace OHOS { namespace AbilityRuntime { namespace { constexpr static const char *ABILITY_RDB_NAME = "/ability_manager_service.db"; constexpr static const char *ABILITY_RDB_PATH = "/data/service/el1/public/database/ability_manager_service"; constexpr static int32_t ABILITY_RDB_VERSION = 1; } // namespace struct AmsRdbConfig { std::string dbPath{ ABILITY_RDB_PATH }; std::string dbName{ ABILITY_RDB_NAME }; std::string tableName; std::string journalMode; std::string syncMode; int32_t version{ ABILITY_RDB_VERSION }; }; class RdbDataManager final { public: RdbDataManager(const AmsRdbConfig &rdbConfig) : amsRdbConfig_(rdbConfig) {} ~RdbDataManager() {} int32_t Init(NativeRdb::RdbOpenCallback &rdbCallback); int32_t InsertData(const NativeRdb::ValuesBucket &valuesBucket); int32_t BatchInsert(int64_t &outInsertNum, const std::vector &valuesBuckets); int32_t UpdateData( const NativeRdb::ValuesBucket &valuesBucket, const NativeRdb::AbsRdbPredicates &absRdbPredicates); int32_t DeleteData(const NativeRdb::AbsRdbPredicates &absRdbPredicates); std::shared_ptr QueryData(const NativeRdb::AbsRdbPredicates &absRdbPredicates); void ClearCache(); private: std::mutex rdbMutex_; std::shared_ptr rdbStore_; AmsRdbConfig amsRdbConfig_; }; } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_RDB_RDB_DATA_MANAGER_H