1 /* 2 * Copyright (c) 2022 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 DISTRIBUTEDDATAMGR_APPDATAMGR_BASE_TRANSACTION_H 17 #define DISTRIBUTEDDATAMGR_APPDATAMGR_BASE_TRANSACTION_H 18 19 #include <iostream> 20 21 namespace OHOS::NativeRdb { 22 enum TransType { 23 ROLLBACK_SELF = 1, 24 ROLLBACK_PARENT, 25 }; 26 27 class BaseTransaction { 28 public: 29 explicit BaseTransaction(int id); 30 ~BaseTransaction(); 31 bool IsAllBeforeSuccessful() const; 32 void SetAllBeforeSuccessful(bool allBeforeSuccessful); 33 bool IsMarkedSuccessful() const; 34 void SetMarkedSuccessful(bool markedSuccessful); 35 int GetType() const; 36 bool IsChildFailure() const; 37 void SetChildFailure(bool failureFlag); 38 std::string GetTransactionStr(); 39 std::string GetCommitStr(); 40 std::string GetRollbackStr(); 41 42 private: 43 bool allBeforeSuccessful; 44 bool markedSuccessful; 45 bool childFailure; 46 int type; 47 int id; 48 49 const std::string BEGIN_IMMEDIATE = "BEGIN EXCLUSIVE"; 50 const std::string TRANS_STR = "TRANS_STR"; 51 const std::string SAVE_POINT = "SAVEPOINT"; 52 const std::string COMMIT = "COMMIT"; 53 const std::string ROLLBACK = "ROLLBACK"; 54 const std::string ROLLBACK_TO = "ROLLBACK TO"; 55 }; 56 } // namespace OHOS::NativeRdb 57 #endif 58