1 /*
2  * Copyright (c) 2021 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 #include "base_transaction.h"
17 
18 namespace OHOS ::NativeRdb {
BaseTransaction(int id)19 BaseTransaction::BaseTransaction(int id)
20     : allBeforeSuccessful(true), markedSuccessful(false), childFailure(false), type(ROLLBACK_SELF), id(id)
21 {
22 }
23 
~BaseTransaction()24 BaseTransaction::~BaseTransaction()
25 {
26 }
27 
IsAllBeforeSuccessful() const28 bool BaseTransaction::IsAllBeforeSuccessful() const
29 {
30     return allBeforeSuccessful;
31 }
32 
SetAllBeforeSuccessful(bool allBeforeSuccessful)33 void BaseTransaction::SetAllBeforeSuccessful(bool allBeforeSuccessful)
34 {
35     this->allBeforeSuccessful = allBeforeSuccessful;
36 }
37 
IsMarkedSuccessful() const38 bool BaseTransaction::IsMarkedSuccessful() const
39 {
40     return markedSuccessful;
41 }
42 
SetMarkedSuccessful(bool markedSuccessful)43 void BaseTransaction::SetMarkedSuccessful(bool markedSuccessful)
44 {
45     this->markedSuccessful = markedSuccessful;
46 }
47 
GetType() const48 int BaseTransaction::GetType() const
49 {
50     return type;
51 }
52 
IsChildFailure() const53 bool BaseTransaction::IsChildFailure() const
54 {
55     return childFailure;
56 }
57 
SetChildFailure(bool failureFlag)58 void BaseTransaction::SetChildFailure(bool failureFlag)
59 {
60     this->childFailure = failureFlag;
61 }
62 
GetTransactionStr()63 std::string BaseTransaction::GetTransactionStr()
64 {
65     std::string retStr = this->id == 0 ? BEGIN_IMMEDIATE : SAVE_POINT + " " + TRANS_STR + std::to_string(this->id);
66     return retStr + ";";
67 }
68 
GetCommitStr()69 std::string BaseTransaction::GetCommitStr()
70 {
71     std::string retStr = this->id == 0 ? COMMIT : "";
72     return retStr + ";";
73 }
74 
GetRollbackStr()75 std::string BaseTransaction::GetRollbackStr()
76 {
77     std::string retStr = this->id == 0 ? ROLLBACK : ROLLBACK_TO + " " + TRANS_STR + std::to_string(this->id);
78     return retStr + ";";
79 }
80 } // namespace OHOS::NativeRdb
81