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_CONNECTION_H 17 #define OHOS_DISTRIBUTED_DATA_NATIVE_GDB_CONNECTION_H 18 19 #include "gdb_store_config.h" 20 #include "statement.h" 21 22 namespace OHOS::DistributedDataAip { 23 class StoreConfig; 24 class Statement; 25 class Connection { 26 public: 27 using SConn = std::shared_ptr<Connection>; 28 using Stmt = std::shared_ptr<Statement>; 29 using Creator = std::pair<int32_t, SConn> (*)(const StoreConfig &config, bool isWriter); 30 static std::pair<int32_t, SConn> Create(const StoreConfig &config, bool isWriter); 31 static int32_t RegisterCreator(DBType dbType, Creator creator); 32 33 int32_t SetId(int32_t id); 34 int32_t GetId() const; 35 virtual ~Connection() = default; 36 virtual std::pair<int32_t, Stmt> CreateStatement(const std::string &gql, std::shared_ptr<Connection> conn) = 0; 37 virtual DBType GetDBType() const = 0; 38 virtual bool IsWriter() const = 0; 39 40 private: 41 int32_t id_ = 0; 42 }; 43 } // namespace OHOS::DistributedDataAip 44 #endif // OHOS_DISTRIBUTED_DATA_NATIVE_GDB_CONNECTION_H