diff --git a/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h b/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h index b7a3775bfc647a9fcf2cd7361739a7202e48a246..fc52bd8d7cc4b17bec94b6f86ee610e59d78d9e1 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h +++ b/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h @@ -35,7 +35,7 @@ public: NEARBY_PUSH = NEARBY_BEGIN, NEARBY_PULL, NEARBY_PULL_PUSH, - NEARBY_END, + NEARBY_END = 4, CLOUD_BEGIN = NEARBY_END, CLOUD_TIME_FIRST = CLOUD_BEGIN, CLOUD_NATIVE_FIRST, diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 897647861290c0cbcd1027f50c30a0fc2f58e202..1724e1ba4ccf67eb51028bea2e50b106105fe471 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -16,7 +16,6 @@ #define LOG_TAG "RdbCloud" #include "rdb_cloud.h" #include "log_print.h" -#include "rdb_util.h" #include "value_proxy.h" namespace OHOS::DistributedRdb { @@ -35,7 +34,7 @@ DBStatus RdbCloud::BatchInsert( if (error == GeneralError::E_OK) { extend = ValueProxy::Convert(std::move(extends)); } - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); } DBStatus RdbCloud::BatchUpdate( @@ -43,13 +42,13 @@ DBStatus RdbCloud::BatchUpdate( { auto error = cloudDB_->BatchUpdate( tableName, ValueProxy::Convert(std::move(record)), ValueProxy::Convert(std::move(extend))); - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); } DBStatus RdbCloud::BatchDelete(const std::string &tableName, std::vector &extend) { auto error = cloudDB_->BatchDelete(tableName, ValueProxy::Convert(std::move(extend))); - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); } DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::vector &data) @@ -57,7 +56,7 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v auto cursor = cloudDB_->Query(tableName, ValueProxy::Convert(std::move(extend))); if (cursor == nullptr) { ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", tableName.c_str(), extend.size()); - return RdbUtil::ConvertStatus(static_cast(E_ERROR)); + return ConvertStatus(static_cast(E_ERROR)); } int32_t count = cursor->GetCount(); data.reserve(count); @@ -76,30 +75,53 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v ZLOGD("query end, table:%{public}s", tableName.c_str()); return DBStatus::QUERY_END; } - return RdbUtil::ConvertStatus(static_cast(err)); + return ConvertStatus(static_cast(err)); } std::pair RdbCloud::Lock() { auto error = cloudDB_->Lock(); - return std::make_pair(RdbUtil::ConvertStatus(static_cast(error)), cloudDB_->AliveTime() * 1000); // int64_t <-> uint32_t, s <-> ms + return std::make_pair(ConvertStatus(static_cast(error)), cloudDB_->AliveTime() * 1000); // int64_t <-> uint32_t, s <-> ms } DBStatus RdbCloud::UnLock() { auto error = cloudDB_->Unlock(); - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); } DBStatus RdbCloud::HeartBeat() { auto error = cloudDB_->Heartbeat(); - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); } DBStatus RdbCloud::Close() { auto error = cloudDB_->Close(); - return RdbUtil::ConvertStatus(static_cast(error)); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::ConvertStatus(DistributedData::GeneralError error) +{ + switch (error) { + case GeneralError::E_OK: + return DBStatus::OK; + case GeneralError::E_BUSY: + return DBStatus::BUSY; + case GeneralError::E_INVALID_ARGS: + return DBStatus::INVALID_ARGS; + case GeneralError::E_NOT_SUPPORT: + return DBStatus::NOT_SUPPORT; + case GeneralError::E_ERROR: // fallthrough + case GeneralError::E_NOT_INIT: + case GeneralError::E_ALREADY_CONSUMED: + case GeneralError::E_ALREADY_CLOSED: + return DBStatus::CLOUD_ERROR; + default: + ZLOGE("unknown error:0x%{public}x", error); + break; + } + return DBStatus::CLOUD_ERROR; } } // namespace OHOS::DistributedRdb diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.h index df4df17f6508a5ab7b4d2828c63a9f99ab62dd28..30e4ee59245234a35ae56a97c3fd444cd210849c 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_cloud.h @@ -18,6 +18,7 @@ #include "cloud/cloud_db.h" #include "cloud/cloud_store_types.h" #include "cloud/icloud_db.h" +#include "error/general_error.h" namespace OHOS::DistributedRdb { class RdbCloud : public DistributedDB::ICloudDb { @@ -37,6 +38,7 @@ public: DBStatus UnLock() override; DBStatus HeartBeat() override; DBStatus Close() override; + DBStatus ConvertStatus(DistributedData::GeneralError error); private: std::shared_ptr cloudDB_; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp index d057a60eece4acade55e217eb4d1bd1ba890f5fc..87049d11679196bd3dcebae0ca346c0fed1c2a8b 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -26,7 +26,6 @@ #include "rdb_helper.h" #include "rdb_query.h" #include "rdb_syncer.h" -#include "rdb_util.h" #include "relational_store_manager.h" #include "value_proxy.h" namespace OHOS::DistributedRdb { @@ -199,7 +198,7 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu } else { dbQuery = rdbQuery->query_; } - auto dbMode = RdbUtil::ConvertMode(static_cast(mode)); + auto dbMode = DistributedDB::SyncMode(mode); auto status = (mode < CLOUD_BEGIN) ? delegate_->Sync(devices, dbMode, dbQuery, GetDBBriefCB(std::move(async)), wait) : delegate_->Sync(devices, dbMode, dbQuery, GetDBProcessCB(std::move(async)), wait); diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp index a9e83914e01cfc6bac393e922ef839db98b29893..cfbf3da3a39444aeff1f70854252b49f9de5773b 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -368,7 +368,7 @@ int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, [async](const std::map> &syncStatus) { async(HandleSyncStatus(syncStatus)); }, - option.isAsync); + !option.isAsync); } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { CloudEvent::StoreInfo storeInfo; storeInfo.bundleName = GetBundleName(); diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.cpp deleted file mode 100644 index 02eabaeec13ed6e82b7049ff6d7944c03e34f455..0000000000000000000000000000000000000000 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "RdbUtil" -#include "rdb_util.h" -#include "log_print.h" - -namespace OHOS::DistributedRdb { -using namespace DistributedDB; -using namespace DistributedData; -RdbUtil::DBStatus RdbUtil::ConvertStatus(DistributedData::GeneralError error) -{ - switch (error) { - case GeneralError::E_OK: - return DBStatus::OK; - case GeneralError::E_BUSY: - return DBStatus::BUSY; - case GeneralError::E_INVALID_ARGS: - return DBStatus::INVALID_ARGS; - case GeneralError::E_NOT_SUPPORT: - return DBStatus::NOT_SUPPORT; - case GeneralError::E_ERROR: // fallthrough - case GeneralError::E_NOT_INIT: - case GeneralError::E_ALREADY_CONSUMED: - case GeneralError::E_ALREADY_CLOSED: - return DBStatus::CLOUD_ERROR; - default: - ZLOGE("unknown error:0x%{public}x", error); - break; - } - return DBStatus::CLOUD_ERROR; -} - -RdbUtil::DBSyncMode RdbUtil::ConvertMode(SyncMode mode) -{ - switch (mode) { - case SyncMode::CLOUD_TIME_FIRST: - return DBSyncMode::SYNC_MODE_CLOUD_MERGE; - case SyncMode::CLOUD_NATIVE_FIRST: - return DBSyncMode::SYNC_MODE_CLOUD_FORCE_PUSH; - case SyncMode::CLOUD_ClOUD_FIRST: - return DBSyncMode::SYNC_MODE_CLOUD_FORCE_PULL; - default: - ZLOGE("unknown mode:0x%{public}x", mode); - break; - } - return DBSyncMode::SYNC_MODE_CLOUD_MERGE; -} -} // OHOS::DistributedRdb \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.h deleted file mode 100644 index 60e84c1961dd1d4722098a99cd593b725d0bc34b..0000000000000000000000000000000000000000 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_util.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_UTIL_H -#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_UTIL_H -#include -#include "error/general_error.h" -#include "store/general_store.h" -#include "store_types.h" - -namespace OHOS::DistributedRdb { -class RdbUtil final { -public: - using DBStatus = DistributedDB::DBStatus; - using DBSyncMode = DistributedDB::SyncMode; - using SyncMode = DistributedData::GeneralStore::SyncMode; - - static DBStatus ConvertStatus(DistributedData::GeneralError error); - static DBSyncMode ConvertMode(SyncMode mode); -}; -} // OHOS::DistributedRdb -#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_UTIL_H diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h index 569b11e08633efe3a167a18748800eff7300b83d..0038d310a1ab9751a77be1447fd91629c672e2a1 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h @@ -53,7 +53,7 @@ enum SyncMode { PUSH, PULL, PULL_PUSH, - TIME_FIRST, + TIME_FIRST = 4, NATIVE_FIRST, CLOUD_FIRST, };