• 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 #ifndef ARKDATA_INTELLIGENCE_PLATFORM_TRANSACTION_IMPL_H
16 #define ARKDATA_INTELLIGENCE_PLATFORM_TRANSACTION_IMPL_H
17 
18 #include <memory>
19 #include <mutex>
20 #include <vector>
21 
22 #include "connection.h"
23 #include "gdb_store_config.h"
24 #include "gdb_transaction.h"
25 #include "result.h"
26 
27 namespace OHOS::DistributedDataAip {
28 class DBStore;
29 class TransactionImpl : public Transaction {
30 public:
31     TransactionImpl(std::shared_ptr<Connection> connection);
32     ~TransactionImpl() override;
33 
34     int32_t Commit() override;
35     int32_t Rollback() override;
36     int32_t Close() override;
37 
38     std::pair<int32_t, std::shared_ptr<Result>> Query(const std::string &gql) override;
39     std::pair<int32_t, std::shared_ptr<Result>> Execute(const std::string &gql) override;
40 
41     static std::pair<int32_t, std::shared_ptr<Transaction>> Create(std::shared_ptr<Connection> conn);
42 
43 private:
44     int32_t Start();
45     int32_t CloseInner();
46     std::shared_ptr<DBStore> GetStore();
47 
48     std::recursive_mutex mutex_;
49     std::shared_ptr<DBStore> store_;
50     std::shared_ptr<Connection> connection_;
51 
52     static const int32_t regCreator_;
53 };
54 } // namespace OHOS::DistributedDataAip
55 #endif
56