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 #include "clouddisk_rdb_transaction.h" 17 #include "utils_log.h" 18 19 namespace OHOS { 20 namespace FileManagement { 21 namespace CloudDisk { 22 using namespace std; 23 24 constexpr int32_t E_HAS_DB_ERROR = -222; 25 constexpr int32_t E_OK = 0; 26 27 constexpr int RDB_TRANSACTION_WAIT_MS = 1000; 28 constexpr int32_t MAX_TRY_TIMES = 5; 29 constexpr int32_t TRANSACTION_WAIT_INTERVAL = 50; // in milliseconds. 30 TransactionOperations(const shared_ptr<OHOS::NativeRdb::RdbStore> & rdbStore)31TransactionOperations::TransactionOperations( 32 const shared_ptr<OHOS::NativeRdb::RdbStore> &rdbStore) : rdbStore_(rdbStore) {} 33 ~TransactionOperations()34TransactionOperations::~TransactionOperations() 35 { 36 if (isStart && !isFinish) { 37 LOGI("TransactionOperations::RollBack"); 38 TransactionRollback(); 39 } 40 } 41 Start(NativeRdb::Transaction::TransactionType type)42std::pair<int32_t, std::shared_ptr<NativeRdb::Transaction>> TransactionOperations::Start( 43 NativeRdb::Transaction::TransactionType type) 44 { 45 auto [errCode, transaction] = rdbStore_->CreateTransaction(type); 46 return make_pair(errCode, transaction); 47 } 48 Finish()49void TransactionOperations::Finish() 50 { 51 } 52 BeginTransaction(NativeRdb::Transaction::TransactionType type)53int32_t TransactionOperations::BeginTransaction( 54 NativeRdb::Transaction::TransactionType type) 55 { 56 return E_OK; 57 } 58 TransactionCommit()59int32_t TransactionOperations::TransactionCommit() 60 { 61 return E_OK; 62 } 63 TransactionRollback()64int32_t TransactionOperations::TransactionRollback() 65 { 66 return E_OK; 67 } 68 } // namespace CloudDisk 69 } // namespace FileManagement 70 } // namespace OHOS