153c3577eSopenharmony_ci/* 253c3577eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 353c3577eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 453c3577eSopenharmony_ci * you may not use this file except in compliance with the License. 553c3577eSopenharmony_ci * You may obtain a copy of the License at 653c3577eSopenharmony_ci * 753c3577eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 853c3577eSopenharmony_ci * 953c3577eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1053c3577eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1153c3577eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1253c3577eSopenharmony_ci * See the License for the specific language governing permissions and 1353c3577eSopenharmony_ci * limitations under the License. 1453c3577eSopenharmony_ci */ 1553c3577eSopenharmony_ci 1653c3577eSopenharmony_ci#define LOG_TAG "RdbCloud" 1753c3577eSopenharmony_ci#include "rdb_cloud.h" 1853c3577eSopenharmony_ci 1953c3577eSopenharmony_ci#include "cloud/schema_meta.h" 2053c3577eSopenharmony_ci#include "log_print.h" 2153c3577eSopenharmony_ci#include "rdb_query.h" 2253c3577eSopenharmony_ci#include "relational_store_manager.h" 2353c3577eSopenharmony_ci#include "utils/anonymous.h" 2453c3577eSopenharmony_ci#include "value_proxy.h" 2553c3577eSopenharmony_ci 2653c3577eSopenharmony_cinamespace OHOS::DistributedRdb { 2753c3577eSopenharmony_ciusing namespace DistributedDB; 2853c3577eSopenharmony_ciusing namespace DistributedData; 2953c3577eSopenharmony_ciRdbCloud::RdbCloud(std::shared_ptr<DistributedData::CloudDB> cloudDB, BindAssets* bindAssets) 3053c3577eSopenharmony_ci : cloudDB_(std::move(cloudDB)), snapshots_(bindAssets) 3153c3577eSopenharmony_ci{ 3253c3577eSopenharmony_ci} 3353c3577eSopenharmony_ci 3453c3577eSopenharmony_ciDBStatus RdbCloud::BatchInsert( 3553c3577eSopenharmony_ci const std::string &tableName, std::vector<DBVBucket> &&record, std::vector<DBVBucket> &extend) 3653c3577eSopenharmony_ci{ 3753c3577eSopenharmony_ci extend.resize(record.size()); 3853c3577eSopenharmony_ci VBuckets extends = ValueProxy::Convert(std::move(extend)); 3953c3577eSopenharmony_ci VBuckets records = ValueProxy::Convert(std::move(record)); 4053c3577eSopenharmony_ci std::set<std::string> skipAssets; 4153c3577eSopenharmony_ci PostEvent(records, skipAssets, extends, DistributedData::AssetEvent::UPLOAD); 4253c3577eSopenharmony_ci VBuckets temp = records; 4353c3577eSopenharmony_ci auto error = cloudDB_->BatchInsert(tableName, std::move(records), extends); 4453c3577eSopenharmony_ci PostEvent(temp, skipAssets, extends, DistributedData::AssetEvent::UPLOAD_FINISHED); 4553c3577eSopenharmony_ci ConvertErrorField(extends); 4653c3577eSopenharmony_ci extend = ValueProxy::Convert(std::move(extends)); 4753c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(error)); 4853c3577eSopenharmony_ci} 4953c3577eSopenharmony_ci 5053c3577eSopenharmony_ciDBStatus RdbCloud::BatchUpdate( 5153c3577eSopenharmony_ci const std::string &tableName, std::vector<DBVBucket> &&record, std::vector<DBVBucket> &extend) 5253c3577eSopenharmony_ci{ 5353c3577eSopenharmony_ci extend.resize(record.size()); 5453c3577eSopenharmony_ci VBuckets extends = ValueProxy::Convert(std::move(extend)); 5553c3577eSopenharmony_ci VBuckets records = ValueProxy::Convert(std::move(record)); 5653c3577eSopenharmony_ci std::set<std::string> skipAssets; 5753c3577eSopenharmony_ci PostEvent(records, skipAssets, extends, DistributedData::AssetEvent::UPLOAD); 5853c3577eSopenharmony_ci VBuckets temp = records; 5953c3577eSopenharmony_ci auto error = cloudDB_->BatchUpdate(tableName, std::move(records), extends); 6053c3577eSopenharmony_ci PostEvent(temp, skipAssets, extends, DistributedData::AssetEvent::UPLOAD_FINISHED); 6153c3577eSopenharmony_ci ConvertErrorField(extends); 6253c3577eSopenharmony_ci extend = ValueProxy::Convert(std::move(extends)); 6353c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(error)); 6453c3577eSopenharmony_ci} 6553c3577eSopenharmony_ci 6653c3577eSopenharmony_ciDBStatus RdbCloud::BatchDelete(const std::string &tableName, std::vector<DBVBucket> &extend) 6753c3577eSopenharmony_ci{ 6853c3577eSopenharmony_ci VBuckets extends = ValueProxy::Convert(std::move(extend)); 6953c3577eSopenharmony_ci auto error = cloudDB_->BatchDelete(tableName, extends); 7053c3577eSopenharmony_ci ConvertErrorField(extends); 7153c3577eSopenharmony_ci extend = ValueProxy::Convert(std::move(extends)); 7253c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(error)); 7353c3577eSopenharmony_ci} 7453c3577eSopenharmony_ci 7553c3577eSopenharmony_ciDBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::vector<DBVBucket> &data) 7653c3577eSopenharmony_ci{ 7753c3577eSopenharmony_ci auto [nodes, status] = ConvertQuery(extend); 7853c3577eSopenharmony_ci std::shared_ptr<Cursor> cursor = nullptr; 7953c3577eSopenharmony_ci if (status == GeneralError::E_OK && !nodes.empty()) { 8053c3577eSopenharmony_ci RdbQuery query; 8153c3577eSopenharmony_ci query.SetQueryNodes(tableName, std::move(nodes)); 8253c3577eSopenharmony_ci cursor = cloudDB_->Query(query, ValueProxy::Convert(std::move(extend))); 8353c3577eSopenharmony_ci } else { 8453c3577eSopenharmony_ci cursor = cloudDB_->Query(tableName, ValueProxy::Convert(std::move(extend))); 8553c3577eSopenharmony_ci } 8653c3577eSopenharmony_ci if (cursor == nullptr) { 8753c3577eSopenharmony_ci ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", 8853c3577eSopenharmony_ci Anonymous::Change(tableName).c_str(), extend.size()); 8953c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(E_ERROR)); 9053c3577eSopenharmony_ci } 9153c3577eSopenharmony_ci int32_t count = cursor->GetCount(); 9253c3577eSopenharmony_ci data.reserve(count); 9353c3577eSopenharmony_ci auto err = cursor->MoveToFirst(); 9453c3577eSopenharmony_ci while (err == E_OK && count > 0) { 9553c3577eSopenharmony_ci DistributedData::VBucket entry; 9653c3577eSopenharmony_ci err = cursor->GetEntry(entry); 9753c3577eSopenharmony_ci if (err != E_OK) { 9853c3577eSopenharmony_ci break; 9953c3577eSopenharmony_ci } 10053c3577eSopenharmony_ci data.emplace_back(ValueProxy::Convert(std::move(entry))); 10153c3577eSopenharmony_ci err = cursor->MoveToNext(); 10253c3577eSopenharmony_ci count--; 10353c3577eSopenharmony_ci } 10453c3577eSopenharmony_ci DistributedData::Value cursorFlag; 10553c3577eSopenharmony_ci cursor->Get(SchemaMeta::CURSOR_FIELD, cursorFlag); 10653c3577eSopenharmony_ci extend[SchemaMeta::CURSOR_FIELD] = ValueProxy::Convert(std::move(cursorFlag)); 10753c3577eSopenharmony_ci if (cursor->IsEnd()) { 10853c3577eSopenharmony_ci ZLOGD("query end, table:%{public}s", Anonymous::Change(tableName).c_str()); 10953c3577eSopenharmony_ci return DBStatus::QUERY_END; 11053c3577eSopenharmony_ci } 11153c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(err)); 11253c3577eSopenharmony_ci} 11353c3577eSopenharmony_ci 11453c3577eSopenharmony_ciDistributedData::GeneralError RdbCloud::PreSharing(const std::string& tableName, VBuckets& extend) 11553c3577eSopenharmony_ci{ 11653c3577eSopenharmony_ci return static_cast<GeneralError>(cloudDB_->PreSharing(tableName, extend)); 11753c3577eSopenharmony_ci} 11853c3577eSopenharmony_ci 11953c3577eSopenharmony_cistd::pair<DBStatus, uint32_t> RdbCloud::Lock() 12053c3577eSopenharmony_ci{ 12153c3577eSopenharmony_ci auto result = InnerLock(FLAG::SYSTEM_ABILITY); 12253c3577eSopenharmony_ci return { ConvertStatus(result.first), result.second }; 12353c3577eSopenharmony_ci} 12453c3577eSopenharmony_ci 12553c3577eSopenharmony_ciDBStatus RdbCloud::UnLock() 12653c3577eSopenharmony_ci{ 12753c3577eSopenharmony_ci return ConvertStatus(InnerUnLock(FLAG::SYSTEM_ABILITY)); 12853c3577eSopenharmony_ci} 12953c3577eSopenharmony_ci 13053c3577eSopenharmony_ciDBStatus RdbCloud::HeartBeat() 13153c3577eSopenharmony_ci{ 13253c3577eSopenharmony_ci auto error = cloudDB_->Heartbeat(); 13353c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(error)); 13453c3577eSopenharmony_ci} 13553c3577eSopenharmony_ci 13653c3577eSopenharmony_ciDBStatus RdbCloud::Close() 13753c3577eSopenharmony_ci{ 13853c3577eSopenharmony_ci auto error = cloudDB_->Close(); 13953c3577eSopenharmony_ci return ConvertStatus(static_cast<GeneralError>(error)); 14053c3577eSopenharmony_ci} 14153c3577eSopenharmony_ci 14253c3577eSopenharmony_cistd::pair<GeneralError, uint32_t> RdbCloud::InnerLock(FLAG flag) 14353c3577eSopenharmony_ci{ 14453c3577eSopenharmony_ci std::lock_guard<decltype(mutex_)> lock(mutex_); 14553c3577eSopenharmony_ci flag_ |= flag; 14653c3577eSopenharmony_ci // int64_t <-> uint32_t, s <-> ms 14753c3577eSopenharmony_ci return std::make_pair(static_cast<GeneralError>(cloudDB_->Lock()), cloudDB_->AliveTime() * TO_MS); 14853c3577eSopenharmony_ci} 14953c3577eSopenharmony_ci 15053c3577eSopenharmony_ciGeneralError RdbCloud::InnerUnLock(FLAG flag) 15153c3577eSopenharmony_ci{ 15253c3577eSopenharmony_ci std::lock_guard<decltype(mutex_)> lock(mutex_); 15353c3577eSopenharmony_ci flag_ &= ~flag; 15453c3577eSopenharmony_ci if (flag_ == 0) { 15553c3577eSopenharmony_ci return static_cast<GeneralError>(cloudDB_->Unlock()); 15653c3577eSopenharmony_ci } 15753c3577eSopenharmony_ci return GeneralError::E_OK; 15853c3577eSopenharmony_ci} 15953c3577eSopenharmony_ci 16053c3577eSopenharmony_cistd::pair<GeneralError, uint32_t> RdbCloud::LockCloudDB(FLAG flag) 16153c3577eSopenharmony_ci{ 16253c3577eSopenharmony_ci return InnerLock(flag); 16353c3577eSopenharmony_ci} 16453c3577eSopenharmony_ci 16553c3577eSopenharmony_ciGeneralError RdbCloud::UnLockCloudDB(FLAG flag) 16653c3577eSopenharmony_ci{ 16753c3577eSopenharmony_ci return InnerUnLock(flag); 16853c3577eSopenharmony_ci} 16953c3577eSopenharmony_ci 17053c3577eSopenharmony_cistd::pair<DBStatus, std::string> RdbCloud::GetEmptyCursor(const std::string &tableName) 17153c3577eSopenharmony_ci{ 17253c3577eSopenharmony_ci auto [error, cursor] = cloudDB_->GetEmptyCursor(tableName); 17353c3577eSopenharmony_ci return { ConvertStatus(static_cast<GeneralError>(error)), cursor }; 17453c3577eSopenharmony_ci} 17553c3577eSopenharmony_ci 17653c3577eSopenharmony_ciDBStatus RdbCloud::ConvertStatus(DistributedData::GeneralError error) 17753c3577eSopenharmony_ci{ 17853c3577eSopenharmony_ci switch (error) { 17953c3577eSopenharmony_ci case GeneralError::E_OK: 18053c3577eSopenharmony_ci return DBStatus::OK; 18153c3577eSopenharmony_ci case GeneralError::E_NETWORK_ERROR: 18253c3577eSopenharmony_ci return DBStatus::CLOUD_NETWORK_ERROR; 18353c3577eSopenharmony_ci case GeneralError::E_LOCKED_BY_OTHERS: 18453c3577eSopenharmony_ci return DBStatus::CLOUD_LOCK_ERROR; 18553c3577eSopenharmony_ci case GeneralError::E_RECODE_LIMIT_EXCEEDED: 18653c3577eSopenharmony_ci return DBStatus::CLOUD_FULL_RECORDS; 18753c3577eSopenharmony_ci case GeneralError::E_NO_SPACE_FOR_ASSET: 18853c3577eSopenharmony_ci return DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT; 18953c3577eSopenharmony_ci case GeneralError::E_VERSION_CONFLICT: 19053c3577eSopenharmony_ci return DBStatus::CLOUD_VERSION_CONFLICT; 19153c3577eSopenharmony_ci case GeneralError::E_RECORD_EXIST_CONFLICT: 19253c3577eSopenharmony_ci return DBStatus::CLOUD_RECORD_EXIST_CONFLICT; 19353c3577eSopenharmony_ci case GeneralError::E_RECORD_NOT_FOUND: 19453c3577eSopenharmony_ci return DBStatus::CLOUD_RECORD_NOT_FOUND; 19553c3577eSopenharmony_ci case GeneralError::E_RECORD_ALREADY_EXISTED: 19653c3577eSopenharmony_ci return DBStatus::CLOUD_RECORD_ALREADY_EXISTED; 19753c3577eSopenharmony_ci case GeneralError::E_FILE_NOT_EXIST: 19853c3577eSopenharmony_ci return DBStatus::LOCAL_ASSET_NOT_FOUND; 19953c3577eSopenharmony_ci case GeneralError::E_TIME_OUT: 20053c3577eSopenharmony_ci return DBStatus::TIME_OUT; 20153c3577eSopenharmony_ci default: 20253c3577eSopenharmony_ci ZLOGI("error:0x%{public}x", error); 20353c3577eSopenharmony_ci break; 20453c3577eSopenharmony_ci } 20553c3577eSopenharmony_ci return DBStatus::CLOUD_ERROR; 20653c3577eSopenharmony_ci} 20753c3577eSopenharmony_ci 20853c3577eSopenharmony_cistd::pair<RdbCloud::QueryNodes, DistributedData::GeneralError> RdbCloud::ConvertQuery(RdbCloud::DBVBucket& extend) 20953c3577eSopenharmony_ci{ 21053c3577eSopenharmony_ci auto it = extend.find(TYPE_FIELD); 21153c3577eSopenharmony_ci if (it == extend.end() || std::get<int64_t>(it->second) != static_cast<int64_t>(CloudQueryType::QUERY_FIELD)) { 21253c3577eSopenharmony_ci return { {}, GeneralError::E_ERROR }; 21353c3577eSopenharmony_ci } 21453c3577eSopenharmony_ci it = extend.find(QUERY_FIELD); 21553c3577eSopenharmony_ci if (it == extend.end()) { 21653c3577eSopenharmony_ci ZLOGE("error, no QUERY_FIELD!"); 21753c3577eSopenharmony_ci return { {}, GeneralError::E_ERROR }; 21853c3577eSopenharmony_ci } 21953c3577eSopenharmony_ci 22053c3577eSopenharmony_ci auto bytes = std::get_if<DistributedDB::Bytes>(&it->second); 22153c3577eSopenharmony_ci std::vector<DistributedDB::QueryNode> nodes; 22253c3577eSopenharmony_ci DBStatus status = DB_ERROR; 22353c3577eSopenharmony_ci if (bytes != nullptr) { 22453c3577eSopenharmony_ci nodes = DistributedDB::RelationalStoreManager::ParserQueryNodes(*bytes, status); 22553c3577eSopenharmony_ci } 22653c3577eSopenharmony_ci if (status != OK) { 22753c3577eSopenharmony_ci ZLOGE("error, ParserQueryNodes failed, status:%{public}d", status); 22853c3577eSopenharmony_ci return { {}, GeneralError::E_ERROR }; 22953c3577eSopenharmony_ci } 23053c3577eSopenharmony_ci return { ConvertQuery(std::move(nodes)), GeneralError::E_OK }; 23153c3577eSopenharmony_ci} 23253c3577eSopenharmony_ci 23353c3577eSopenharmony_ciRdbCloud::QueryNodes RdbCloud::ConvertQuery(RdbCloud::DBQueryNodes&& nodes) 23453c3577eSopenharmony_ci{ 23553c3577eSopenharmony_ci QueryNodes queryNodes; 23653c3577eSopenharmony_ci queryNodes.reserve(nodes.size()); 23753c3577eSopenharmony_ci for (auto& node : nodes) { 23853c3577eSopenharmony_ci QueryNode queryNode; 23953c3577eSopenharmony_ci queryNode.fieldName = std::move(node.fieldName); 24053c3577eSopenharmony_ci queryNode.fieldValue = ValueProxy::Convert(std::move(node.fieldValue)); 24153c3577eSopenharmony_ci switch (node.type) { 24253c3577eSopenharmony_ci case QueryNodeType::IN: 24353c3577eSopenharmony_ci queryNode.op = QueryOperation::IN; 24453c3577eSopenharmony_ci break; 24553c3577eSopenharmony_ci case QueryNodeType::OR: 24653c3577eSopenharmony_ci queryNode.op = QueryOperation::OR; 24753c3577eSopenharmony_ci break; 24853c3577eSopenharmony_ci case QueryNodeType::AND: 24953c3577eSopenharmony_ci queryNode.op = QueryOperation::AND; 25053c3577eSopenharmony_ci break; 25153c3577eSopenharmony_ci case QueryNodeType::EQUAL_TO: 25253c3577eSopenharmony_ci queryNode.op = QueryOperation::EQUAL_TO; 25353c3577eSopenharmony_ci break; 25453c3577eSopenharmony_ci case QueryNodeType::BEGIN_GROUP: 25553c3577eSopenharmony_ci queryNode.op = QueryOperation::BEGIN_GROUP; 25653c3577eSopenharmony_ci break; 25753c3577eSopenharmony_ci case QueryNodeType::END_GROUP: 25853c3577eSopenharmony_ci queryNode.op = QueryOperation::END_GROUP; 25953c3577eSopenharmony_ci break; 26053c3577eSopenharmony_ci default: 26153c3577eSopenharmony_ci ZLOGE("invalid operation:0x%{public}d", node.type); 26253c3577eSopenharmony_ci return {}; 26353c3577eSopenharmony_ci } 26453c3577eSopenharmony_ci queryNodes.emplace_back(std::move(queryNode)); 26553c3577eSopenharmony_ci } 26653c3577eSopenharmony_ci return queryNodes; 26753c3577eSopenharmony_ci} 26853c3577eSopenharmony_ci 26953c3577eSopenharmony_civoid RdbCloud::PostEvent(VBuckets& records, std::set<std::string>& skipAssets, VBuckets& extend, 27053c3577eSopenharmony_ci DistributedData::AssetEvent eventId) 27153c3577eSopenharmony_ci{ 27253c3577eSopenharmony_ci int32_t index = 0; 27353c3577eSopenharmony_ci for (auto& record : records) { 27453c3577eSopenharmony_ci DataBucket& ext = extend[index++]; 27553c3577eSopenharmony_ci for (auto& [key, value] : record) { 27653c3577eSopenharmony_ci PostEvent(value, ext, skipAssets, eventId); 27753c3577eSopenharmony_ci } 27853c3577eSopenharmony_ci } 27953c3577eSopenharmony_ci} 28053c3577eSopenharmony_ci 28153c3577eSopenharmony_civoid RdbCloud::PostEvent(DistributedData::Value& value, DataBucket& extend, std::set<std::string>& skipAssets, 28253c3577eSopenharmony_ci DistributedData::AssetEvent eventId) 28353c3577eSopenharmony_ci{ 28453c3577eSopenharmony_ci if (value.index() != TYPE_INDEX<DistributedData::Asset> && value.index() != TYPE_INDEX<DistributedData::Assets>) { 28553c3577eSopenharmony_ci return; 28653c3577eSopenharmony_ci } 28753c3577eSopenharmony_ci 28853c3577eSopenharmony_ci if (value.index() == TYPE_INDEX<DistributedData::Asset>) { 28953c3577eSopenharmony_ci auto* asset = Traits::get_if<DistributedData::Asset>(&value); 29053c3577eSopenharmony_ci PostEventAsset(*asset, extend, skipAssets, eventId); 29153c3577eSopenharmony_ci } 29253c3577eSopenharmony_ci 29353c3577eSopenharmony_ci if (value.index() == TYPE_INDEX<DistributedData::Assets>) { 29453c3577eSopenharmony_ci auto* assets = Traits::get_if<DistributedData::Assets>(&value); 29553c3577eSopenharmony_ci for (auto& asset : *assets) { 29653c3577eSopenharmony_ci PostEventAsset(asset, extend, skipAssets, eventId); 29753c3577eSopenharmony_ci } 29853c3577eSopenharmony_ci } 29953c3577eSopenharmony_ci} 30053c3577eSopenharmony_ci 30153c3577eSopenharmony_civoid RdbCloud::PostEventAsset(DistributedData::Asset& asset, DataBucket& extend, std::set<std::string>& skipAssets, 30253c3577eSopenharmony_ci DistributedData::AssetEvent eventId) 30353c3577eSopenharmony_ci{ 30453c3577eSopenharmony_ci if (snapshots_->bindAssets == nullptr) { 30553c3577eSopenharmony_ci return; 30653c3577eSopenharmony_ci } 30753c3577eSopenharmony_ci auto it = snapshots_->bindAssets->find(asset.uri); 30853c3577eSopenharmony_ci if (it == snapshots_->bindAssets->end() || it->second == nullptr) { 30953c3577eSopenharmony_ci return; 31053c3577eSopenharmony_ci } 31153c3577eSopenharmony_ci 31253c3577eSopenharmony_ci if (eventId == DistributedData::UPLOAD) { 31353c3577eSopenharmony_ci it->second->Upload(asset); 31453c3577eSopenharmony_ci if (it->second->GetAssetStatus(asset) == TransferStatus::STATUS_WAIT_UPLOAD) { 31553c3577eSopenharmony_ci skipAssets.insert(asset.uri); 31653c3577eSopenharmony_ci extend[SchemaMeta::ERROR_FIELD] = DBStatus::CLOUD_RECORD_EXIST_CONFLICT; 31753c3577eSopenharmony_ci } 31853c3577eSopenharmony_ci } 31953c3577eSopenharmony_ci 32053c3577eSopenharmony_ci if (eventId == DistributedData::UPLOAD_FINISHED) { 32153c3577eSopenharmony_ci auto skip = skipAssets.find(asset.uri); 32253c3577eSopenharmony_ci if (skip != skipAssets.end()) { 32353c3577eSopenharmony_ci return; 32453c3577eSopenharmony_ci } 32553c3577eSopenharmony_ci it->second->Uploaded(asset); 32653c3577eSopenharmony_ci } 32753c3577eSopenharmony_ci} 32853c3577eSopenharmony_ci 32953c3577eSopenharmony_ciuint8_t RdbCloud::GetLockFlag() const 33053c3577eSopenharmony_ci{ 33153c3577eSopenharmony_ci return flag_; 33253c3577eSopenharmony_ci} 33353c3577eSopenharmony_ci 33453c3577eSopenharmony_civoid RdbCloud::ConvertErrorField(DistributedData::VBuckets& extends) 33553c3577eSopenharmony_ci{ 33653c3577eSopenharmony_ci for (auto& extend : extends) { 33753c3577eSopenharmony_ci auto errorField = extend.find(SchemaMeta::ERROR_FIELD); 33853c3577eSopenharmony_ci if (errorField == extend.end()) { 33953c3577eSopenharmony_ci continue; 34053c3577eSopenharmony_ci } 34153c3577eSopenharmony_ci auto errCode = Traits::get_if<int64_t>(&(errorField->second)); 34253c3577eSopenharmony_ci if (errCode == nullptr) { 34353c3577eSopenharmony_ci continue; 34453c3577eSopenharmony_ci } 34553c3577eSopenharmony_ci errorField->second = ConvertStatus(static_cast<GeneralError>(*errCode)); 34653c3577eSopenharmony_ci } 34753c3577eSopenharmony_ci} 34853c3577eSopenharmony_ci 34953c3577eSopenharmony_civoid RdbCloud::SetPrepareTraceId(const std::string &traceId) 35053c3577eSopenharmony_ci{ 35153c3577eSopenharmony_ci if (cloudDB_ == nullptr) { 35253c3577eSopenharmony_ci return; 35353c3577eSopenharmony_ci } 35453c3577eSopenharmony_ci cloudDB_->SetPrepareTraceId(traceId); 35553c3577eSopenharmony_ci} 35653c3577eSopenharmony_ci} // namespace OHOS::DistributedRdb