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 OHOS_DISTRIBUTED_DATA_NATIVE_GDB_DB_STORE_IMPL_H 17 #define OHOS_DISTRIBUTED_DATA_NATIVE_GDB_DB_STORE_IMPL_H 18 19 #include <mutex> 20 #include <variant> 21 22 #include "connection.h" 23 #include "connection_pool.h" 24 #include "gdb_store.h" 25 #include "gdb_store_config.h" 26 #include "gdb_transaction.h" 27 28 namespace OHOS::DistributedDataAip { 29 class DBStoreImpl final : public DBStore { 30 public: 31 explicit DBStoreImpl(StoreConfig config); 32 ~DBStoreImpl(); 33 std::pair<int32_t, std::shared_ptr<Result>> QueryGql(const std::string &gql) override; 34 std::pair<int32_t, std::shared_ptr<Result>> ExecuteGql(const std::string &gql) override; 35 std::pair<int32_t, std::shared_ptr<Transaction>> CreateTransaction() override; 36 int32_t Close() override; 37 int32_t InitConn(); 38 39 private: 40 std::shared_ptr<ConnectionPool> GetConnectionPool(); 41 void SetConnectionPool(std::shared_ptr<ConnectionPool> connectionPool); 42 43 std::mutex mutex_; 44 std::mutex transMutex_; 45 StoreConfig config_; 46 std::shared_ptr<ConnectionPool> connectionPool_ = nullptr; 47 std::list<std::weak_ptr<Transaction>> transactions_; 48 }; 49 } // namespace OHOS::DistributedDataAip 50 #endif 51