• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 ARKDATA_INTELLIGENCE_PLATFORM_GDB_TRANSACTION_H
17 #define ARKDATA_INTELLIGENCE_PLATFORM_GDB_TRANSACTION_H
18 
19 #include <functional>
20 #include <tuple>
21 #include <utility>
22 #include <vector>
23 
24 #include "gdb_store_config.h"
25 #include "result.h"
26 
27 namespace OHOS::DistributedDataAip {
28 class Connection;
29 class Transaction {
30 public:
31     using Creator = std::function<std::pair<int32_t, std::shared_ptr<Transaction>>(std::shared_ptr<Connection> conn)>;
32 
33     static std::pair<int32_t, std::shared_ptr<Transaction>> Create(std::shared_ptr<Connection> conn);
34     static int32_t RegisterCreator(Creator creator);
35 
36     API_EXPORT virtual ~Transaction() = default;
37 
38     API_EXPORT virtual int32_t Commit() = 0;
39     API_EXPORT virtual int32_t Rollback() = 0;
40     virtual int32_t Close() = 0;
41 
42     /**
43      * @brief Queries data in the database based on GQL statement.
44      *
45      * @param gql Indicates the GQL statement to execute.
46      */
47     API_EXPORT virtual std::pair<int32_t, std::shared_ptr<Result>> Query(const std::string &gql) = 0;
48 
49     /**
50      * @brief Executes an GQL statement.
51      *
52      * @param gql Indicates the GQL statement to execute.
53      */
54     API_EXPORT virtual std::pair<int32_t, std::shared_ptr<Result>> Execute(const std::string &gql) = 0;
55 
56 private:
57     static inline Creator creator_;
58 };
59 } // namespace OHOS::DistributedDataAip
60 #endif
61