!951 add querySharingResource interface

Merge pull request !951 from ht/master
This commit is contained in:
openharmony_ci 2023-11-26 17:49:34 +00:00 committed by Gitee
commit 060d07a4e9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 2041 additions and 267 deletions

View File

@ -31,6 +31,8 @@ ohos_shared_library("clouddata") {
sources = [
"${cloud_data_napi_path}/src/entry_point.cpp",
"${cloud_data_napi_path}/src/js_cloud_share.cpp",
"${cloud_data_napi_path}/src/js_cloud_utils.cpp",
"${cloud_data_napi_path}/src/js_config.cpp",
"${cloud_data_napi_path}/src/js_config_util.cpp",
"${cloud_data_napi_path}/src/js_const_properties.cpp",
@ -38,6 +40,7 @@ ohos_shared_library("clouddata") {
"${cloud_data_napi_path}/src/napi_queue.cpp",
"${cloud_data_native_path}/src/cloud_manager.cpp",
"${cloud_data_native_path}/src/cloud_service_proxy.cpp",
"${cloud_data_native_path}/src/cloud_types_util.cpp",
"${relational_store_napi_path}/common/src/js_utils.cpp",
]
@ -45,6 +48,7 @@ ohos_shared_library("clouddata") {
"include",
"${relational_store_js_common_path}/include",
"${cloud_data_native_path}/include",
"${datashare_path}/provider/include",
"${kvstore_path}/common",
"${relational_store_common_path}/include",
"${relational_store_innerapi_path}/rdb/include",
@ -53,6 +57,8 @@ ohos_shared_library("clouddata") {
"${relational_store_napi_path}/common/include",
]
deps = [ "${relational_store_innerapi_path}/rdb:native_rdb" ]
external_deps = [
"ability_runtime:abilitykit_native",
"ability_runtime:napi_base_context",

View File

@ -0,0 +1,26 @@
/*
* 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 CLOUD_DATA_JS_CLOUD_SHARE_H
#define CLOUD_DATA_JS_CLOUD_SHARE_H
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
namespace OHOS::CloudData {
napi_value InitCloudSharing(napi_env env, napi_value exports);
} // namespace OHOS::CloudData
#endif // CLOUD_DATA_JS_CLOUD_SHARE_H

View File

@ -0,0 +1,49 @@
/*
* 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 CLOUD_DATA_JS_CLOUD_SHARE_H
#define CLOUD_DATA_JS_CLOUD_SHARE_H
#include "js_utils.h"
#include "cloud_types.h"
#include "rdb_predicates.h"
#include "result_set.h"
namespace OHOS::AppDataMgrJsKit {
namespace JSUtils {
using Participant = OHOS::CloudData::Participant;
using Privilege = OHOS::CloudData::Privilege;
using RdbPredicates = OHOS::NativeRdb::RdbPredicates;
using ResultSet = OHOS::NativeRdb::ResultSet;
template<>
int32_t Convert2Value(napi_env env, napi_value input, Participant &output);
template<>
int32_t Convert2Value(napi_env env, napi_value input, Privilege &output);
template<>
int32_t Convert2Value(napi_env env, napi_value input, std::shared_ptr<RdbPredicates> &output);
template<>
napi_value Convert2JSValue(napi_env env, const Participant &value);
template<>
napi_value Convert2JSValue(napi_env env, const Privilege &value);
template<>
napi_value Convert2JSValue(napi_env env, const std::shared_ptr<ResultSet> &value);
}; // namespace JSUtils
} // namespace OHOS::AppDataMgrJsKit
#endif // CLOUD_DATA_JS_CLOUD_SHARE_H

View File

@ -21,5 +21,6 @@
namespace OHOS::CloudData {
napi_status InitConstProperties(napi_env env, napi_value exports);
napi_status InitSharingConstProperties(napi_env env, napi_value exports);
} // namespace OHOS::CloudData
#endif //LDBPROJ_JS_CONST_PROPERTIES_H

View File

@ -61,16 +61,19 @@ private:
};
/* check condition related to argc/argv, return and logging. */
#define ASSERT_ARGS(ctxt, condition, message) \
#define ASSERT_VALUE(ctxt, condition, errCode, message) \
do { \
if (!(condition)) { \
(ctxt)->status = napi_invalid_arg; \
(ctxt)->status = errCode; \
(ctxt)->error = std::string(message); \
LOG_ERROR("test (" #condition ") failed: " message); \
return; \
} \
} while (0)
#define ASSERT_ARGS(ctxt, condition, message) \
ASSERT_VALUE(ctxt, condition, napi_invalid_arg, message)
#define ASSERT_STATUS(ctxt, message) \
do { \
if ((ctxt)->status != napi_ok) { \

View File

@ -16,14 +16,18 @@
#include "js_config.h"
#include "js_const_properties.h"
#include "logger.h"
#include "js_cloud_share.h"
using namespace OHOS::CloudData;
using namespace OHOS::Rdb;
static napi_value Init(napi_env env, napi_value exports)
{
auto sharingExport = InitCloudSharing(env, exports);
napi_status status = InitSharingConstProperties(env, sharingExport);
LOG_INFO("init Enumerate Constants %{public}d", status);
exports = JsConfig::InitConfig(env, exports);
napi_status status = InitConstProperties(env, exports);
status = InitConstProperties(env, exports);
LOG_INFO("init Enumerate Constants %{public}d", status);
return exports;
}

View File

@ -0,0 +1,114 @@
/*
* 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.
*/
#include "js_cloud_share.h"
#include "cache_result_set.h"
#include "cloud_manager.h"
#include "cloud_service.h"
#include "cloud_types.h"
#include "js_utils.h"
#include "js_cloud_utils.h"
#include "js_error_utils.h"
#include "logger.h"
#include "napi_queue.h"
#include "rdb_predicates.h"
#include "result_set.h"
namespace OHOS::CloudData {
using namespace OHOS::NativeRdb;
using namespace OHOS::AppDataMgrJsKit;
/*
* [JS API Prototype]
* [AsyncCallback]
* allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates,
* participants: Array<Participant>, callback: AsyncCallback<relationalStore.ResultSet>): void;
* allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates,
* participants: Array<Participant>, columns: Array<string>,
* callback: AsyncCallback<relationalStore.ResultSet> ): void;
*
* [Promise]
* allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates,
* participants: Array<Participant>, columns?: Array<string>): Promise<relationalStore.ResultSet>;
*/
napi_value AllocResourceAndShare(napi_env env, napi_callback_info info)
{
struct AllocResAndShareContext : public ContextBase {
std::string storeId;
std::vector<Participant> participants;
std::vector<std::string> columns;
std::shared_ptr<RdbPredicates> predicates = nullptr;
std::shared_ptr<ResultSet> resultSet;
};
auto ctxt = std::make_shared<AllocResAndShareContext>();
ctxt->GetCbInfo(env, info, [env, ctxt](size_t argc, napi_value *argv) {
ASSERT_BUSINESS_ERR(ctxt, argc >= 3, Status::INVALID_ARGUMENT, "The number of parameters is incorrect.");
int status = JSUtils::Convert2Value(env, argv[0], ctxt->storeId);
ASSERT_BUSINESS_ERR(ctxt, status == JSUtils::OK,
Status::INVALID_ARGUMENT, "The type of storeId must be string.");
status = JSUtils::Convert2Value(env, argv[1], ctxt->predicates);
ASSERT_BUSINESS_ERR(ctxt, status == JSUtils::OK, Status::INVALID_ARGUMENT,
"The type of predicates must be relationalStore.RdbPredicates");
status = JSUtils::Convert2Value(env, argv[2], ctxt->participants);
ASSERT_BUSINESS_ERR(ctxt, status == JSUtils::OK,
Status::INVALID_ARGUMENT, "The type of participants must be Array<Participant>.");
if (argc > 3) {
status = JSUtils::Convert2Value(env, argv[3], ctxt->columns);
ASSERT_BUSINESS_ERR(ctxt, status == JSUtils::OK,
Status::INVALID_ARGUMENT, "The type of columns must be Array<string>.");
}
});
ASSERT_NULL(!ctxt->isThrowError, "AllocResourceAndShare exit");
auto execute = [env, ctxt]() {
auto [status, proxy] = CloudManager::GetInstance().GetCloudService();
if (proxy == nullptr) {
if (status != CloudService::SERVER_UNAVAILABLE) {
status = CloudService::NOT_SUPPORT;
}
ctxt->status = (GenerateNapiError(status, ctxt->jsCode, ctxt->error) == Status::SUCCESS)
? napi_ok
: napi_generic_failure;
return;
}
auto [result, valueBuckets] = proxy->AllocResourceAndShare(
ctxt->storeId, ctxt->predicates->GetDistributedPredicates(), ctxt->columns, ctxt->participants);
ctxt->resultSet = std::make_shared<CacheResultSet>(std::move(valueBuckets));
LOG_DEBUG("AllocResourceAndShare result: %{public}d, size:%{public}zu", result, valueBuckets.size());
ctxt->status =
(GenerateNapiError(result, ctxt->jsCode, ctxt->error) == Status::SUCCESS) ? napi_ok : napi_generic_failure;
};
auto output = [env, ctxt](napi_value& result) {
result = JSUtils::Convert2JSValue(env, ctxt->resultSet);
ASSERT_VALUE(ctxt, result != nullptr, napi_generic_failure, "output failed");
};
return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
}
napi_value InitCloudSharing(napi_env env, napi_value exports)
{
napi_value sharing = nullptr;
napi_status status = napi_create_object(env, &sharing);
if (status != napi_ok || sharing == nullptr) {
return nullptr;
}
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("allocResourceAndShare", AllocResourceAndShare),
};
NAPI_CALL(env, napi_define_properties(env, sharing, sizeof(properties) / sizeof(*properties), properties));
NAPI_CALL(env, napi_set_named_property(env, exports, "sharing", sharing));
return sharing;
}
} // namespace OHOS::CloudData

View File

@ -0,0 +1,157 @@
/*
* 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.
*/
#include "js_cloud_utils.h"
#include "js_proxy.h"
#include "result_set.h"
#include "result_set_bridge.h"
#include "logger.h"
#define NAPI_CALL_RETURN_ERR(call, ret) \
ASSERT_RETURN((call) != napi_ok, ret)
#define ASSERT_RETURN(call, ret) \
do { \
if (!(call)) { \
return ret; \
} \
} while (0)
namespace OHOS::AppDataMgrJsKit {
namespace JSUtils {
using namespace OHOS::Rdb;
template<>
int32_t Convert2Value(napi_env env, napi_value input, Participant &output)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, input, &type);
if (status != napi_ok || type != napi_object) {
LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type);
return napi_invalid_arg;
}
NAPI_CALL_RETURN_ERR(GET_PROPERTY(env, input, output, identity), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "role", output.role), napi_invalid_arg);
if (output.role < CloudData::Role::ROLE_INVITER || output.role > CloudData::Role::ROLE_INVITEE) {
return napi_invalid_arg;
}
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "status", output.status), napi_invalid_arg);
if (output.status < CloudData::Confirmation::CFM_UNKNOWN ||
output.status > CloudData::Confirmation::CFM_SUSPENDED) {
return napi_invalid_arg;
}
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "privilege", output.privilege), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "attachInfo", output.attachInfo), napi_invalid_arg);
return napi_ok;
}
template<>
int32_t Convert2Value(napi_env env, napi_value input, Privilege &output)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, input, &type);
if (status != napi_ok || type != napi_object) {
LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type);
return napi_invalid_arg;
}
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "writable", output.writable), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "readable", output.readable), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "creatable", output.creatable), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "deletable", output.deletable), napi_invalid_arg);
NAPI_CALL_RETURN_ERR(GetOptionalValue(env, input, "shareable", output.shareable), napi_invalid_arg);
return napi_ok;
}
template<>
int32_t Convert2Value(napi_env env, napi_value input, std::shared_ptr<RdbPredicates> &output)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, input, &type);
if (status != napi_ok || type != napi_object) {
LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type);
return napi_invalid_arg;
}
JSProxy::JSProxy<NativeRdb::RdbPredicates> *jsProxy = nullptr;
status = napi_unwrap(env, input, reinterpret_cast<void **>(&jsProxy));
ASSERT_RETURN(status == napi_ok && jsProxy != nullptr && jsProxy->GetInstance() != nullptr, napi_invalid_arg);
output = jsProxy->GetInstance();
return napi_ok;
}
template<>
napi_value Convert2JSValue(napi_env env, const Participant &value)
{
napi_value jsValue = nullptr;
napi_status status = napi_create_object(env, &jsValue);
if (status != napi_ok) {
return nullptr;
}
napi_value identity = Convert2JSValue(env, value.identity);
napi_value role = Convert2JSValue(env, value.role);
napi_value sharingStatus = Convert2JSValue(env, value.status);
napi_value privilege = Convert2JSValue(env, value.privilege);
if (privilege == nullptr) {
return nullptr;
}
napi_value attachInfo = Convert2JSValue(env, value.attachInfo);
napi_set_named_property(env, jsValue, "identity", identity);
napi_set_named_property(env, jsValue, "role", role);
napi_set_named_property(env, jsValue, "status", sharingStatus);
napi_set_named_property(env, jsValue, "privilege", privilege);
napi_set_named_property(env, jsValue, "attachInfo", attachInfo);
return jsValue;
}
template<>
napi_value Convert2JSValue(napi_env env, const Privilege &value)
{
napi_value jsValue = nullptr;
napi_status status = napi_create_object(env, &jsValue);
if (status != napi_ok) {
return nullptr;
}
napi_set_named_property(env, jsValue, "writable", Convert2JSValue(env, value.writable));
napi_set_named_property(env, jsValue, "readable", Convert2JSValue(env, value.readable));
napi_set_named_property(env, jsValue, "creatable", Convert2JSValue(env, value.creatable));
napi_set_named_property(env, jsValue, "deletable", Convert2JSValue(env, value.deletable));
napi_set_named_property(env, jsValue, "shareable", Convert2JSValue(env, value.shareable));
return jsValue;
}
template<>
napi_value Convert2JSValue(napi_env env, const std::shared_ptr<ResultSet> &value)
{
auto constructor = JSUtils::GetClass(env, "ohos.data.relationalStore", "ResultSet");
if (constructor == nullptr) {
LOG_ERROR("Constructor of ResultSet is nullptr!");
return nullptr;
}
napi_value instance = nullptr;
napi_status status = napi_new_instance(env, constructor, 0, nullptr, &instance);
if (status != napi_ok) {
LOG_ERROR("NewInstance ResultSet failed! status:%{public}d!", status);
return nullptr;
}
JSProxy::JSEntity<NativeRdb::ResultSet, DataShare::ResultSetBridge> *proxy = nullptr;
status = napi_unwrap(env, instance, reinterpret_cast<void **>(&proxy));
if (status != napi_ok || proxy == nullptr) {
LOG_ERROR("napi_unwrap failed! status:%{public}d!", status);
return nullptr;
}
proxy->SetInstance(value);
return instance;
}
}; // namespace JSUtils
} // namespace OHOS::AppDataMgrJsKit

View File

@ -16,6 +16,7 @@
#include "js_const_properties.h"
#include "cloud_service.h"
#include "cloud_types.h"
#include "napi_queue.h"
using namespace OHOS::Rdb;
@ -42,6 +43,50 @@ static napi_value ExportAction(napi_env env)
return action;
}
static napi_value ExportRole(napi_env env)
{
napi_value role = nullptr;
napi_create_object(env, &role);
SetNamedProperty(env, role, "ROLE_INVITER", Role::ROLE_INVITER);
SetNamedProperty(env, role, "ROLE_INVITEE", Role::ROLE_INVITEE);
napi_object_freeze(env, role);
return role;
}
static napi_value ExportShareStatus(napi_env env)
{
napi_value status = nullptr;
napi_create_object(env, &status);
SetNamedProperty(env, status, "STATUS_UNKNOWN", Confirmation::CFM_UNKNOWN);
SetNamedProperty(env, status, "STATUS_ACCEPTED", Confirmation::CFM_ACCEPTED);
SetNamedProperty(env, status, "STATUS_REJECTED", Confirmation::CFM_REJECTED);
SetNamedProperty(env, status, "STATUS_SUSPENDED", Confirmation::CFM_SUSPENDED);
napi_object_freeze(env, status);
return status;
}
static napi_value ExportShareCode(napi_env env)
{
napi_value code = nullptr;
napi_create_object(env, &code);
SetNamedProperty(env, code, "SUCCESS", SharingCode::SUCCESS);
SetNamedProperty(env, code, "REPEATED_REQUEST", SharingCode::REPEATED_REQUEST);
SetNamedProperty(env, code, "NOT_INVITER", SharingCode::NOT_INVITER);
SetNamedProperty(env, code, "NOT_INVITER_OR_INVITEE", SharingCode::NOT_INVITER_OR_INVITEE);
SetNamedProperty(env, code, "OVER_QUOTA", SharingCode::OVER_QUOTA);
SetNamedProperty(env, code, "TOO_MANY_PARTICIPANTS", SharingCode::TOO_MANY_PARTICIPANTS);
SetNamedProperty(env, code, "INVALID_ARGS", SharingCode::INVALID_ARGS);
SetNamedProperty(env, code, "NETWORK_ERROR", SharingCode::NETWORK_ERROR);
SetNamedProperty(env, code, "CLOUD_DISABLED", SharingCode::CLOUD_DISABLED);
SetNamedProperty(env, code, "SERVER_ERROR", SharingCode::SERVER_ERROR);
SetNamedProperty(env, code, "INNER_ERROR", SharingCode::INNER_ERROR);
SetNamedProperty(env, code, "INVALID_INVITATION", SharingCode::INVALID_INVITATION);
SetNamedProperty(env, code, "RATE_LIMIT", SharingCode::RATE_LIMIT);
SetNamedProperty(env, code, "CUSTOM_ERROR", SharingCode::CUSTOM_ERROR);
napi_object_freeze(env, code);
return code;
}
napi_status InitConstProperties(napi_env env, napi_value exports)
{
const napi_property_descriptor properties[] = {
@ -52,4 +97,19 @@ napi_status InitConstProperties(napi_env env, napi_value exports)
return napi_define_properties(env, exports, count, properties);
}
napi_status InitSharingConstProperties(napi_env env, napi_value exports)
{
if (exports == nullptr) {
return napi_generic_failure;
}
const napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("Role", ExportRole(env)),
DECLARE_NAPI_PROPERTY("Status", ExportShareStatus(env)),
DECLARE_NAPI_PROPERTY("SharingCode", ExportShareCode(env)),
};
size_t count = sizeof(properties) / sizeof(properties[0]);
return napi_define_properties(env, exports, count, properties);
}
} // namespace OHOS::CloudData

View File

@ -0,0 +1,56 @@
/*
* 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_RELATIONAL_STORE_JS_NAPI_COMMON_JS_PROXY_H
#define OHOS_RELATIONAL_STORE_JS_NAPI_COMMON_JS_PROXY_H
#include <memory>
namespace OHOS::JSProxy {
template<typename T>
class JSCreator {
public:
virtual std::shared_ptr<T> Create() = 0;
protected:
JSCreator() = default;
~JSCreator() = default;
};
template<typename T>
class JSProxy {
public:
void SetInstance(std::shared_ptr<T> instance)
{
instance_ = std::move(instance);
}
std::shared_ptr<T> GetInstance() const
{
return instance_;
}
protected:
JSProxy() = default;
~JSProxy() = default;
private:
std::shared_ptr<T> instance_;
};
template<typename T, typename U = T>
class JSEntity : public JSCreator<U>, public JSProxy<T> {
protected:
JSEntity() = default;
~JSEntity() = default;
};
} // namespace OHOS::Proxy
#endif // OHOS_RELATIONAL_STORE_JS_NAPI_COMMON_JS_PROXY_H

View File

@ -54,6 +54,7 @@ struct JsFeatureSpace {
#endif
napi_value GetNamedProperty(napi_env env, napi_value object, const char *name);
std::pair<int32_t, napi_value> GetOptionalNamedProperty(napi_env env, napi_value input, const char *name);
int32_t Convert2ValueExt(napi_env env, napi_value jsValue, uint32_t &output);
int32_t Convert2ValueExt(napi_env env, napi_value jsValue, int32_t &output);
@ -75,6 +76,9 @@ bool Equal(napi_env env, napi_ref ref, napi_value value);
template<typename T>
int32_t Convert2Value(napi_env env, napi_value jsValue, T &output);
template<typename T>
int32_t Convert2ValueExt(napi_env env, napi_value jsValue, T &output);
template<typename T>
int32_t Convert2Value(napi_env env, napi_value jsValue, std::vector<T> &value);
@ -122,6 +126,22 @@ napi_value Convert2JSValue(napi_env env, const std::variant<Types...> &value);
template<typename T>
std::string ToString(const T &key);
template <typename T>
int32_t GetOptionalValue(napi_env env, napi_value in, const char *name, T& out)
{
auto [status, value] = GetOptionalNamedProperty(env, in, name);
if (status != napi_ok) {
return status;
}
if (value == nullptr) {
return napi_ok;
}
if (std::is_same_v<T, int32_t>) {
return JSUtils::Convert2ValueExt(env, value, out);
}
return JSUtils::Convert2Value(env, value, out);
}
template<typename K>
std::enable_if_t<!std::is_same_v<K, std::string>, std::string> ConvertMapKey(const K &key)
{

View File

@ -60,6 +60,27 @@ napi_value JSUtils::GetNamedProperty(napi_env env, napi_value object, const char
return jsItem;
}
std::pair<int32_t , napi_value> JSUtils::GetOptionalNamedProperty(napi_env env, napi_value input, const char *name)
{
bool hasProp = false;
napi_status status = napi_has_named_property(env, input, name, &hasProp);
if (status != napi_ok) {
return std::make_pair(napi_generic_failure, nullptr);
}
if (!hasProp) {
return std::make_pair(napi_ok, nullptr);
}
napi_value inner = nullptr;
status = napi_get_named_property(env, input, name, &inner);
if (status != napi_ok || inner == nullptr) {
return std::make_pair(napi_generic_failure, nullptr);
}
if (JSUtils::IsNull(env, inner)) {
return std::make_pair(napi_ok, nullptr);
}
return std::make_pair(napi_ok, inner);
}
std::string JSUtils::Convert2String(napi_env env, napi_value jsStr)
{
std::string value = ""; // TD: need to check everywhere in use whether empty is work well.
@ -452,8 +473,9 @@ napi_value JSUtils::DefineClass(napi_env env, const std::string &spaceName, cons
if (!featureSpace.has_value() || !featureSpace->isComponent) {
return nullptr;
}
if (GetClass(env, spaceName, className)) {
return GetClass(env, spaceName, className);
auto constructor = GetClass(env, spaceName, className);
if (constructor != nullptr) {
return constructor;
}
auto rootPropName = std::string(featureSpace->nameBase64);
napi_value root = nullptr;
@ -469,13 +491,12 @@ napi_value JSUtils::DefineClass(napi_env env, const std::string &spaceName, cons
}
std::string propName = "constructor_of_" + className;
napi_value constructor = nullptr;
bool hasProp = false;
napi_has_named_property(env, root, propName.c_str(), &hasProp);
if (hasProp) {
napi_get_named_property(env, root, propName.c_str(), &constructor);
if (constructor != nullptr) {
LOG_DEBUG("got data.cloudData.%{public}s as constructor", propName.c_str());
LOG_DEBUG("got %{public}s from %{public}s", propName.c_str(), featureSpace->spaceName);
return constructor;
}
hasProp = false; // no constructor.
@ -487,7 +508,7 @@ napi_value JSUtils::DefineClass(napi_env env, const std::string &spaceName, cons
if (!hasProp) {
napi_set_named_property(env, root, propName.c_str(), constructor);
LOG_DEBUG("save constructor to data.cloudData.%{public}s", propName.c_str());
LOG_DEBUG("save %{public}s to %{public}s", propName.c_str(), featureSpace->spaceName);
}
return constructor;
}
@ -517,7 +538,7 @@ napi_value JSUtils::GetClass(napi_env env, const std::string &spaceName, const s
}
napi_get_named_property(env, root, propName.c_str(), &constructor);
if (constructor != nullptr) {
LOG_DEBUG("got data.cloudData.%{public}s as constructor", propName.c_str());
LOG_DEBUG("got %{public}s from %{public}s", propName.c_str(), featureSpace->spaceName);
return constructor;
}
hasProp = false; // no constructor.

View File

@ -18,6 +18,7 @@
#include <memory>
#include "js_proxy.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
@ -26,7 +27,7 @@
namespace OHOS {
namespace RelationalStoreJsKit {
class RdbPredicatesProxy {
class RdbPredicatesProxy : public JSProxy::JSProxy<NativeRdb::RdbPredicates> {
public:
static void Init(napi_env env, napi_value exports);
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value);
@ -102,8 +103,6 @@ private:
static napi_value GetBindArgs(napi_env env, napi_callback_info info);
static napi_value InDevices(napi_env env, napi_callback_info info);
static napi_value InAllDevices(napi_env env, napi_callback_info info);
std::shared_ptr<NativeRdb::RdbPredicates> predicates_;
};
} // namespace RelationalStoreJsKit
} // namespace OHOS

View File

@ -76,6 +76,7 @@ private:
static napi_value OnEvent(napi_env env, napi_callback_info info);
static napi_value OffEvent(napi_env env, napi_callback_info info);
static napi_value Notify(napi_env env, napi_callback_info info);
static napi_value QuerySharingResource(napi_env env, napi_callback_info info);
static constexpr int EVENT_HANDLE_NUM = 2;

View File

@ -19,6 +19,7 @@
#include <memory>
#include "asset_value.h"
#include "js_proxy.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
@ -28,14 +29,14 @@
namespace OHOS {
namespace RelationalStoreJsKit {
class ResultSetProxy final : public DataShare::ResultSetBridge::Creator {
class ResultSetProxy final : public JSProxy::JSEntity<NativeRdb::ResultSet, DataShare::ResultSetBridge> {
public:
ResultSetProxy() = default;
~ResultSetProxy();
ResultSetProxy(std::shared_ptr<NativeRdb::ResultSet> resultSet);
ResultSetProxy &operator=(std::shared_ptr<NativeRdb::ResultSet> resultSet);
static void Init(napi_env env, napi_value exports);
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet);
static napi_value GetConstructor(napi_env env);
std::shared_ptr<DataShare::ResultSetBridge> Create() override;
private:
@ -74,8 +75,6 @@ private:
static napi_value IsColumnNull(napi_env env, napi_callback_info info);
static napi_value GetRow(napi_env env, napi_callback_info info);
static napi_value IsClosed(napi_env env, napi_callback_info info);
std::shared_ptr<NativeRdb::ResultSet> resultSet_;
};
} // namespace RelationalStoreJsKit
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include "napi_rdb_store.h"
#include "napi_rdb_store_helper.h"
#include "napi_rdb_const_properties.h"
#include "napi_result_set.h"
#include "napi/native_api.h"
using namespace OHOS::RelationalStoreJsKit;
@ -30,6 +31,7 @@ static napi_value Init(napi_env env, napi_value exports)
InitRdbHelper(env, exports);
RdbStoreProxy::Init(env, exports);
RdbPredicatesProxy::Init(env, exports);
ResultSetProxy::Init(env, exports);
InitConstProperties(env, exports);
return exports;
}

View File

@ -153,7 +153,7 @@ napi_value RdbPredicatesProxy::NewInstance(napi_env env, std::shared_ptr<NativeR
LOG_ERROR("RdbPredicatesProxy::NewInstance native instance is nullptr! napi_status:%{public}d!", status);
return instance;
}
proxy->predicates_ = std::move(value);
proxy->GetInstance() = std::move(value);
LOG_DEBUG("RdbPredicatesProxy::NewInstance end");
return instance;
}
@ -170,8 +170,8 @@ RdbPredicatesProxy::~RdbPredicatesProxy()
}
RdbPredicatesProxy::RdbPredicatesProxy(std::string &tableName)
: predicates_(std::make_shared<NativeRdb::RdbPredicates>(tableName))
{
SetInstance(std::make_shared<NativeRdb::RdbPredicates>(tableName));
}
RdbPredicatesProxy *RdbPredicatesProxy::GetNativePredicates(napi_env env, napi_callback_info info)
@ -182,7 +182,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::GetNativePredicates(napi_env env, napi_c
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -205,7 +205,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldArrayByName(napi_env env, napi
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -222,7 +222,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldByName(
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -239,7 +239,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseInt32FieldByName(
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -259,7 +259,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValueArray(napi_env env, na
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -280,7 +280,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValue(napi_env env, napi_ca
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -301,7 +301,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndStringValue(napi_env env, n
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -324,7 +324,7 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldLowAndHigh(
RdbPredicatesProxy *proxy = nullptr;
napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->predicates_, std::make_shared<ParamError>("predicates", "null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("predicates", "null"));
return proxy;
}
@ -336,8 +336,8 @@ napi_value RdbPredicatesProxy::EqualTo(napi_env env, napi_callback_info info)
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->EqualTo(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->EqualTo(field, value);
return thiz;
}
@ -348,8 +348,8 @@ napi_value RdbPredicatesProxy::NotEqualTo(napi_env env, napi_callback_info info)
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->NotEqualTo(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->NotEqualTo(field, value);
return thiz;
}
@ -359,8 +359,8 @@ napi_value RdbPredicatesProxy::BeginWrap(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->BeginWrap();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->BeginWrap();
return thiz;
}
@ -370,8 +370,8 @@ napi_value RdbPredicatesProxy::EndWrap(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->EndWrap();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->EndWrap();
return thiz;
}
@ -381,8 +381,8 @@ napi_value RdbPredicatesProxy::Or(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Or();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Or();
return thiz;
}
@ -392,8 +392,8 @@ napi_value RdbPredicatesProxy::And(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->And();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->And();
return thiz;
}
@ -404,8 +404,8 @@ napi_value RdbPredicatesProxy::Contains(napi_env env, napi_callback_info info)
std::string field = "";
std::string value = "";
auto predicatesProxy = ParseFieldAndStringValue(env, info, thiz, field, value, "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Contains(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Contains(field, value);
return thiz;
}
@ -416,8 +416,8 @@ napi_value RdbPredicatesProxy::BeginsWith(napi_env env, napi_callback_info info)
std::string field = "";
std::string value = "";
auto predicatesProxy = ParseFieldAndStringValue(env, info, thiz, field, value, "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->BeginsWith(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->BeginsWith(field, value);
return thiz;
}
@ -428,8 +428,8 @@ napi_value RdbPredicatesProxy::EndsWith(napi_env env, napi_callback_info info)
std::string field = "";
std::string value = "";
auto predicatesProxy = ParseFieldAndStringValue(env, info, thiz, field, value, "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->EndsWith(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->EndsWith(field, value);
return thiz;
}
@ -439,8 +439,8 @@ napi_value RdbPredicatesProxy::IsNull(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string field = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->IsNull(field);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->IsNull(field);
return thiz;
}
@ -450,8 +450,8 @@ napi_value RdbPredicatesProxy::IsNotNull(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string field = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->IsNotNull(field);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->IsNotNull(field);
return thiz;
}
@ -462,8 +462,8 @@ napi_value RdbPredicatesProxy::Like(napi_env env, napi_callback_info info)
std::string field = "";
std::string value = "";
auto predicatesProxy = ParseFieldAndStringValue(env, info, thiz, field, value, "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Like(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Like(field, value);
return thiz;
}
@ -474,8 +474,8 @@ napi_value RdbPredicatesProxy::Glob(napi_env env, napi_callback_info info)
std::string field = "";
std::string value = "";
auto predicatesProxy = ParseFieldAndStringValue(env, info, thiz, field, value, "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Glob(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Glob(field, value);
return thiz;
}
@ -487,8 +487,8 @@ napi_value RdbPredicatesProxy::Between(napi_env env, napi_callback_info info)
ValueObject low;
ValueObject high;
auto predicatesProxy = ParseFieldLowAndHigh(env, info, thiz, field, low, high);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Between(field, low, high);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Between(field, low, high);
return thiz;
}
@ -500,8 +500,8 @@ napi_value RdbPredicatesProxy::NotBetween(napi_env env, napi_callback_info info)
ValueObject low;
ValueObject high;
auto predicatesProxy = ParseFieldLowAndHigh(env, info, thiz, field, low, high);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->NotBetween(field, low, high);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->NotBetween(field, low, high);
return thiz;
}
@ -512,8 +512,8 @@ napi_value RdbPredicatesProxy::GreaterThan(napi_env env, napi_callback_info info
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->GreaterThan(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->GreaterThan(field, value);
return thiz;
}
@ -524,8 +524,8 @@ napi_value RdbPredicatesProxy::LessThan(napi_env env, napi_callback_info info)
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->LessThan(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->LessThan(field, value);
return thiz;
}
@ -536,8 +536,8 @@ napi_value RdbPredicatesProxy::GreaterThanOrEqualTo(napi_env env, napi_callback_
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->GreaterThanOrEqualTo(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->GreaterThanOrEqualTo(field, value);
return thiz;
}
@ -548,8 +548,8 @@ napi_value RdbPredicatesProxy::LessThanOrEqualTo(napi_env env, napi_callback_inf
std::string field = "";
ValueObject value;
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->LessThanOrEqualTo(field, value);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->LessThanOrEqualTo(field, value);
return thiz;
}
@ -559,8 +559,8 @@ napi_value RdbPredicatesProxy::OrderByAsc(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string field = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->OrderByAsc(field);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->OrderByAsc(field);
return thiz;
}
@ -570,8 +570,8 @@ napi_value RdbPredicatesProxy::OrderByDesc(napi_env env, napi_callback_info info
napi_value thiz = nullptr;
std::string field = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->OrderByDesc(field);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->OrderByDesc(field);
return thiz;
}
@ -581,8 +581,8 @@ napi_value RdbPredicatesProxy::Distinct(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Distinct();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Distinct();
return thiz;
}
@ -594,7 +594,7 @@ napi_value RdbPredicatesProxy::Limit(napi_env env, napi_callback_info info)
napi_value args[2] = { 0 };
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
//Ensure that the number of parameters is 1 or 2
RDB_NAPI_ASSERT(env, argc == 1 || argc == 2, std::make_shared<ParamNumError>("1 or 2"));
@ -603,14 +603,14 @@ napi_value RdbPredicatesProxy::Limit(napi_env env, napi_callback_info info)
if (argc == 1) {
napi_status status = napi_get_value_int32(env, args[0], &limit);
RDB_NAPI_ASSERT(env, status == napi_ok, std::make_shared<ParamError>("limit", "a number."));
predicatesProxy->predicates_->Limit(limit);
predicatesProxy->GetInstance()->Limit(limit);
} else {
napi_status status = napi_get_value_int32(env, args[0], &offset);
RDB_NAPI_ASSERT(env, status == napi_ok, std::make_shared<ParamError>("offset", "a number."));
status = napi_get_value_int32(env, args[1], &limit);
RDB_NAPI_ASSERT(env, status == napi_ok, std::make_shared<ParamError>("limit", "a number."));
predicatesProxy->predicates_->Limit(offset, limit);
predicatesProxy->GetInstance()->Limit(offset, limit);
}
return thiz;
@ -622,8 +622,8 @@ napi_value RdbPredicatesProxy::Offset(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
int32_t offset = AbsPredicates::INIT_OFFSET_VALUE;
auto predicatesProxy = ParseInt32FieldByName(env, info, thiz, offset, "rowOffset");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Offset(offset);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Offset(offset);
return thiz;
}
@ -633,8 +633,8 @@ napi_value RdbPredicatesProxy::GroupBy(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::vector<std::string> fields;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, fields, "fields", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->GroupBy(fields);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->GroupBy(fields);
return thiz;
}
@ -644,8 +644,8 @@ napi_value RdbPredicatesProxy::IndexedBy(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string indexName = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, indexName, "fields");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->IndexedBy(indexName);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->IndexedBy(indexName);
return thiz;
}
@ -656,8 +656,8 @@ napi_value RdbPredicatesProxy::In(napi_env env, napi_callback_info info)
std::string field = "";
std::vector<ValueObject> values;
auto predicatesProxy = ParseFieldAndValueArray(env, info, thiz, field, values, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->In(field, values);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->In(field, values);
return thiz;
}
@ -668,8 +668,8 @@ napi_value RdbPredicatesProxy::NotIn(napi_env env, napi_callback_info info)
std::string field = "";
std::vector<ValueObject> values;
auto predicatesProxy = ParseFieldAndValueArray(env, info, thiz, field, values, "ValueType");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->NotIn(field, values);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->NotIn(field, values);
return thiz;
}
@ -679,8 +679,8 @@ napi_value RdbPredicatesProxy::Using(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::vector<std::string> fields;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, fields, "fields", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Using(fields);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Using(fields);
return thiz;
}
@ -690,8 +690,8 @@ napi_value RdbPredicatesProxy::LeftOuterJoin(napi_env env, napi_callback_info in
napi_value thiz = nullptr;
std::string tablename = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->LeftOuterJoin(tablename);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->LeftOuterJoin(tablename);
return thiz;
}
@ -701,8 +701,8 @@ napi_value RdbPredicatesProxy::InnerJoin(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string tablename = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->InnerJoin(tablename);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->InnerJoin(tablename);
return thiz;
}
@ -712,8 +712,8 @@ napi_value RdbPredicatesProxy::On(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::vector<std::string> clauses;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, clauses, "clauses", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->On(clauses);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->On(clauses);
return thiz;
}
@ -722,9 +722,9 @@ napi_value RdbPredicatesProxy::GetStatement(napi_env env, napi_callback_info inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
std::string statement = predicatesProxy->predicates_->GetStatement();
std::string statement = predicatesProxy->GetInstance()->GetStatement();
return JSUtils::Convert2JSValue(env, statement);
}
@ -733,9 +733,9 @@ napi_value RdbPredicatesProxy::GetBindArgs(napi_env env, napi_callback_info info
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
std::vector<ValueObject> bindArgs = predicatesProxy->predicates_->GetBindArgs();
std::vector<ValueObject> bindArgs = predicatesProxy->GetInstance()->GetBindArgs();
return JSUtils::Convert2JSValue(env, bindArgs);
}
@ -745,8 +745,8 @@ napi_value RdbPredicatesProxy::Clear(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->Clear();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->Clear();
return thiz;
}
@ -756,8 +756,8 @@ napi_value RdbPredicatesProxy::CrossJoin(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::string tablename = "";
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->CrossJoin(tablename);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->CrossJoin(tablename);
return thiz;
}
@ -767,8 +767,8 @@ napi_value RdbPredicatesProxy::GetJoinCount(napi_env env, napi_callback_info inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
int errCode = predicatesProxy->predicates_->GetJoinCount();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
int errCode = predicatesProxy->GetInstance()->GetJoinCount();
return JSUtils::Convert2JSValue(env, errCode);
}
@ -778,8 +778,8 @@ napi_value RdbPredicatesProxy::SetJoinCount(napi_env env, napi_callback_info inf
napi_value thiz;
int32_t joinCount = 0;
auto predicatesProxy = ParseInt32FieldByName(env, info, thiz, joinCount, "joinCount");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->SetJoinCount(joinCount);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->SetJoinCount(joinCount);
return thiz;
}
@ -789,8 +789,8 @@ napi_value RdbPredicatesProxy::GetJoinTypes(napi_env env, napi_callback_info inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
auto joinTypes = predicatesProxy->predicates_->GetJoinTypes();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
auto joinTypes = predicatesProxy->GetInstance()->GetJoinTypes();
return JSUtils::Convert2JSValue(env, joinTypes);
}
@ -800,8 +800,8 @@ napi_value RdbPredicatesProxy::GetJoinTableNames(napi_env env, napi_callback_inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
auto joinTableNames = predicatesProxy->predicates_->GetJoinTableNames();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
auto joinTableNames = predicatesProxy->GetInstance()->GetJoinTableNames();
return JSUtils::Convert2JSValue(env, joinTableNames);
}
@ -811,8 +811,8 @@ napi_value RdbPredicatesProxy::GetJoinConditions(napi_env env, napi_callback_inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
RdbPredicatesProxy *predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
auto joinConditions = predicatesProxy->predicates_->GetJoinConditions();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
auto joinConditions = predicatesProxy->GetInstance()->GetJoinConditions();
return JSUtils::Convert2JSValue(env, joinConditions);
}
@ -822,8 +822,8 @@ napi_value RdbPredicatesProxy::SetJoinConditions(napi_env env, napi_callback_inf
napi_value thiz = nullptr;
std::vector<std::string> joinConditions;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, joinConditions, "joinConditions", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->SetJoinConditions(joinConditions);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->SetJoinConditions(joinConditions);
return thiz;
}
@ -833,8 +833,8 @@ napi_value RdbPredicatesProxy::SetJoinTableNames(napi_env env, napi_callback_inf
napi_value thiz = nullptr;
std::vector<std::string> joinNames;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, joinNames, "joinNames", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->SetJoinTableNames(joinNames);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->SetJoinTableNames(joinNames);
return thiz;
}
@ -844,14 +844,14 @@ napi_value RdbPredicatesProxy::SetJoinTypes(napi_env env, napi_callback_info inf
napi_value thiz = nullptr;
std::vector<std::string> joinTypes;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, joinTypes, "joinTypes", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->SetJoinTypes(joinTypes);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->SetJoinTypes(joinTypes);
return thiz;
}
std::shared_ptr<NativeRdb::RdbPredicates> RdbPredicatesProxy::GetPredicates() const
{
return this->predicates_;
return GetInstance();
}
napi_value RdbPredicatesProxy::InDevices(napi_env env, napi_callback_info info)
@ -860,8 +860,8 @@ napi_value RdbPredicatesProxy::InDevices(napi_env env, napi_callback_info info)
napi_value thiz = nullptr;
std::vector<std::string> devices;
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, devices, "devices", "string");
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->InDevices(devices);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->InDevices(devices);
return thiz;
}
@ -871,8 +871,8 @@ napi_value RdbPredicatesProxy::InAllDevices(napi_env env, napi_callback_info inf
napi_value thiz = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
auto predicatesProxy = GetNativePredicates(env, info);
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->predicates_);
predicatesProxy->predicates_->InAllDevices();
CHECK_RETURN_NULL(predicatesProxy && predicatesProxy->GetInstance());
predicatesProxy->GetInstance()->InAllDevices();
return thiz;
}
} // namespace RelationalStoreJsKit

View File

@ -71,8 +71,7 @@ struct RdbStoreContext : public Context {
int64_t int64Output;
int intOutput;
std::vector<uint8_t> newKey;
std::shared_ptr<ResultSet> newResultSet;
std::shared_ptr<ResultSet> resultSet_value;
std::shared_ptr<ResultSet> resultSet;
std::string aliasName;
std::string pathName;
std::string srcName;
@ -202,6 +201,7 @@ void RdbStoreProxy::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", OnEvent),
DECLARE_NAPI_FUNCTION("off", OffEvent),
DECLARE_NAPI_FUNCTION("emit", Notify),
DECLARE_NAPI_FUNCTION("querySharingResource", QuerySharingResource),
#endif
};
napi_value cons = nullptr;
@ -389,8 +389,8 @@ int ParseCloudSyncCallback(const napi_env env, const napi_value arg, std::shared
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, arg, &valueType);
CHECK_RETURN_SET(valueType == napi_function, std::make_shared<ParamNumError>("a callback type"));
napi_create_reference(env, arg, 1, &context->asyncHolder);
CHECK_RETURN_SET(valueType == napi_function, std::make_shared<ParamError>("progress", "a callback type"));
NAPI_CALL_BASE(env, napi_create_reference(env, arg, 1, &context->asyncHolder), ERR);
return OK;
}
@ -694,11 +694,11 @@ napi_value RdbStoreProxy::Query(napi_env env, napi_callback_info info)
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
CHECK_RETURN_ERR(obj != nullptr && obj->rdbStore_ != nullptr);
CHECK_RETURN_ERR(context->rdbPredicates != nullptr);
context->resultSet_value = obj->rdbStore_->Query(*(context->rdbPredicates), context->columns);
return (context->resultSet_value != nullptr) ? E_OK : E_ERROR;
context->resultSet = obj->rdbStore_->Query(*(context->rdbPredicates), context->columns);
return (context->resultSet != nullptr) ? E_OK : E_ERROR;
};
auto output = [context](napi_env env, napi_value &result) {
result = ResultSetProxy::NewInstance(env, context->resultSet_value);
result = ResultSetProxy::NewInstance(env, context->resultSet);
CHECK_RETURN_SET_E(result != nullptr, std::make_shared<InnerError>(E_ERROR));
};
context->SetAction(env, info, input, exec, output);
@ -726,12 +726,12 @@ napi_value RdbStoreProxy::RemoteQuery(napi_env env, napi_callback_info info)
int errCode = E_ERROR;
CHECK_RETURN_ERR(obj != nullptr && obj->rdbStore_ != nullptr);
CHECK_RETURN_ERR(context->rdbPredicates != nullptr);
context->newResultSet =
context->resultSet =
obj->rdbStore_->RemoteQuery(context->device, *(context->rdbPredicates), context->columns, errCode);
return errCode;
};
auto output = [context](napi_env env, napi_value &result) {
result = ResultSetProxy::NewInstance(env, context->newResultSet);
result = ResultSetProxy::NewInstance(env, context->resultSet);
CHECK_RETURN_SET_E(result != nullptr, std::make_shared<InnerError>(E_ERROR));
};
context->SetAction(env, info, input, exec, output);
@ -756,14 +756,14 @@ napi_value RdbStoreProxy::QuerySql(napi_env env, napi_callback_info info)
auto exec = [context]() -> int {
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) || defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
context->resultSet_value = obj->rdbStore_->QueryByStep(context->sql, context->bindArgs);
context->resultSet = obj->rdbStore_->QueryByStep(context->sql, context->bindArgs);
#else
context->resultSet_value = obj->rdbStore_->QuerySql(context->sql, context->bindArgs);
context->resultSet = obj->rdbStore_->QuerySql(context->sql, context->bindArgs);
#endif
return (context->resultSet_value != nullptr) ? E_OK : E_ERROR;
return (context->resultSet != nullptr) ? E_OK : E_ERROR;
};
auto output = [context](napi_env env, napi_value &result) {
result = ResultSetProxy::NewInstance(env, context->resultSet_value);
result = ResultSetProxy::NewInstance(env, context->resultSet);
CHECK_RETURN_SET_E(result != nullptr, std::make_shared<InnerError>(E_ERROR));
};
context->SetAction(env, info, input, exec, output);
@ -979,12 +979,12 @@ napi_value RdbStoreProxy::QueryByStep(napi_env env, napi_callback_info info)
LOG_DEBUG("RdbStoreProxy::QueryByStep Async");
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
CHECK_RETURN_ERR(obj != nullptr && obj->rdbStore_ != nullptr);
context->resultSet_value = obj->rdbStore_->QueryByStep(context->sql, context->columns);
LOG_ERROR("RdbStoreProxy::QueryByStep is nullptr ? %{public}d ", context->resultSet_value == nullptr);
return (context->resultSet_value != nullptr) ? E_OK : E_ERROR;
context->resultSet = obj->rdbStore_->QueryByStep(context->sql, context->columns);
LOG_ERROR("RdbStoreProxy::QueryByStep is nullptr ? %{public}d ", context->resultSet == nullptr);
return (context->resultSet != nullptr) ? E_OK : E_ERROR;
};
auto output = [context](napi_env env, napi_value &result) {
result = ResultSetProxy::NewInstance(env, context->resultSet_value);
result = ResultSetProxy::NewInstance(env, context->resultSet);
CHECK_RETURN_SET_E(result != nullptr, std::make_shared<InnerError>(E_ERROR));
LOG_DEBUG("RdbStoreProxy::QueryByStep end");
};
@ -1380,10 +1380,8 @@ napi_value RdbStoreProxy::OffRemote(napi_env env, size_t argc, napi_value *argv)
int errCode = rdbStore_->UnSubscribe(option, it->get());
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
it = observers_[mode].erase(it);
LOG_INFO("observer unsubscribe success");
return nullptr;
LOG_DEBUG("observer unsubscribe success");
}
LOG_INFO("observer not found");
return nullptr;
}
@ -1518,6 +1516,44 @@ napi_value RdbStoreProxy::Notify(napi_env env, napi_callback_info info)
return nullptr;
}
napi_value RdbStoreProxy::QuerySharingResource(napi_env env, napi_callback_info info)
{
LOG_DEBUG("RdbStoreProxy::QuerySharingResource start");
auto context = std::make_shared<RdbStoreContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) {
CHECK_RETURN_SET_E(argc > 0 && argc < 4, std::make_shared<ParamNumError>("1 to 3"));
CHECK_RETURN(OK == ParserThis(env, self, context));
CHECK_RETURN(OK == ParsePredicates(env, argv[0], context));
if (argc >= 2) {
bool isArray = false;
napi_is_array(env, argv[1], &isArray);
if (isArray) {
CHECK_RETURN(OK == ParseColumns(env, argv[1], context));
}
}
};
auto exec = [context]() -> int {
LOG_DEBUG("RdbStoreProxy::QuerySharingResource Async");
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
CHECK_RETURN_ERR(obj != nullptr && obj->rdbStore_ != nullptr);
auto status = E_ERROR;
std::tie(status, context->resultSet) =
obj->rdbStore_->QuerySharingResource(*(context->rdbPredicates), context->columns);
LOG_DEBUG("RdbStoreProxy::QuerySharingResource resultSet is nullptr:%{public}d, status:%{public}d",
context->resultSet == nullptr, status);
return (context->resultSet != nullptr) ? E_OK : E_ERROR;
};
auto output = [context](napi_env env, napi_value &result) {
result = ResultSetProxy::NewInstance(env, context->resultSet);
CHECK_RETURN_SET_E(result != nullptr, std::make_shared<InnerError>(E_ERROR));
LOG_DEBUG("RdbStoreProxy::QuerySharingResource end");
};
context->SetAction(env, info, input, exec, output);
CHECK_RETURN_NULL(context->error == nullptr || context->error->GetCode() == OK);
return AsyncCall::Call(env, context);
}
napi_value RdbStoreProxy::RegisterSyncCallback(napi_env env, size_t argc, napi_value *argv)
{
napi_valuetype type = napi_undefined;
@ -1527,7 +1563,7 @@ napi_value RdbStoreProxy::RegisterSyncCallback(napi_env env, size_t argc, napi_v
return *observer == argv[1];
});
if (result) {
LOG_INFO("duplicate subscribe");
LOG_DEBUG("duplicate subscribe");
return nullptr;
}
auto observer = std::make_shared<SyncObserver>(env, argv[0], queue_);
@ -1560,10 +1596,8 @@ napi_value RdbStoreProxy::UnregisterSyncCallback(napi_env env, size_t argc, napi
int errCode = rdbStore_->UnregisterAutoSyncCallback(*it);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
it = syncObservers_.erase(it);
LOG_INFO("progress unsubscribe success");
return nullptr;
LOG_DEBUG("observer unsubscribe success");
}
LOG_INFO("observer not found");
return nullptr;
}

View File

@ -35,18 +35,17 @@ namespace OHOS {
namespace RelationalStoreJsKit {
using Asset = AssetValue;
using Assets = std::vector<Asset>;
static napi_ref __thread ctorRef_ = nullptr;
static const int E_OK = 0;
napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet)
{
napi_value cons = GetConstructor(env);
napi_value cons = JSUtils::GetClass(env, "ohos.data.relationalStore", "ResultSet");
if (cons == nullptr) {
LOG_ERROR("NewInstance GetConstructor is nullptr!");
LOG_ERROR("Constructor of ResultSet is nullptr!");
return nullptr;
}
napi_value instance = nullptr;
napi_status status = napi_new_instance(env, cons, 0, nullptr, &instance);
auto status = napi_new_instance(env, cons, 0, nullptr, &instance);
if (status != napi_ok) {
LOG_ERROR("NewInstance napi_new_instance failed! code:%{public}d!", status);
return nullptr;
@ -58,68 +57,20 @@ napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::
LOG_ERROR("NewInstance native instance is nullptr! code:%{public}d!", status);
return instance;
}
*proxy = std::move(resultSet);
proxy->SetInstance(std::move(resultSet));
return instance;
}
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
std::shared_ptr<DataShare::ResultSetBridge> ResultSetProxy::Create()
{
if (resultSet_ == nullptr) {
if (GetInstance() == nullptr) {
LOG_ERROR("resultSet is null");
return nullptr;
}
return std::make_shared<RdbDataShareAdapter::RdbResultSetBridge>(std::move(resultSet_));
return std::make_shared<RdbDataShareAdapter::RdbResultSetBridge>(GetInstance());
}
#endif
napi_value ResultSetProxy::GetConstructor(napi_env env)
{
napi_value cons = nullptr;
if (ctorRef_ != nullptr) {
NAPI_CALL(env, napi_get_reference_value(env, ctorRef_, &cons));
return cons;
}
LOG_INFO("GetConstructor result set constructor");
napi_property_descriptor clzDes[] = {
DECLARE_NAPI_FUNCTION("goToRow", GoToRow),
DECLARE_NAPI_FUNCTION("getLong", GetLong),
DECLARE_NAPI_FUNCTION("getColumnType", GetColumnType),
DECLARE_NAPI_FUNCTION("goTo", GoTo),
DECLARE_NAPI_FUNCTION("getColumnIndex", GetColumnIndex),
DECLARE_NAPI_FUNCTION("getColumnName", GetColumnName),
DECLARE_NAPI_FUNCTION("close", Close),
DECLARE_NAPI_FUNCTION("goToFirstRow", GoToFirstRow),
DECLARE_NAPI_FUNCTION("goToLastRow", GoToLastRow),
DECLARE_NAPI_FUNCTION("goToNextRow", GoToNextRow),
DECLARE_NAPI_FUNCTION("goToPreviousRow", GoToPreviousRow),
DECLARE_NAPI_FUNCTION("getInt", GetInt),
DECLARE_NAPI_FUNCTION("getBlob", GetBlob),
DECLARE_NAPI_FUNCTION("getAsset", GetAsset),
DECLARE_NAPI_FUNCTION("getAssets", GetAssets),
DECLARE_NAPI_FUNCTION("getString", GetString),
DECLARE_NAPI_FUNCTION("getDouble", GetDouble),
DECLARE_NAPI_FUNCTION("isColumnNull", IsColumnNull),
DECLARE_NAPI_FUNCTION("getRow", GetRow),
DECLARE_NAPI_GETTER("columnNames", GetAllColumnNames),
DECLARE_NAPI_GETTER("columnCount", GetColumnCount),
DECLARE_NAPI_GETTER("isEnded", IsEnded),
DECLARE_NAPI_GETTER("isStarted", IsBegin),
DECLARE_NAPI_GETTER("isClosed", IsClosed),
DECLARE_NAPI_GETTER("rowCount", GetRowCount),
DECLARE_NAPI_GETTER("rowIndex", GetRowIndex),
DECLARE_NAPI_GETTER("isAtFirstRow", IsAtFirstRow),
DECLARE_NAPI_GETTER("isAtLastRow", IsAtLastRow),
};
NAPI_CALL(env, napi_define_class(env, "ResultSet", NAPI_AUTO_LENGTH, Initialize, nullptr,
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRef_));
return cons;
}
napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info)
{
napi_value self = nullptr;
@ -149,18 +100,18 @@ ResultSetProxy::~ResultSetProxy()
ResultSetProxy::ResultSetProxy(std::shared_ptr<ResultSet> resultSet)
{
if (resultSet_ == resultSet) {
if (GetInstance() == resultSet) {
return;
}
resultSet_ = std::move(resultSet);
SetInstance(std::move(resultSet));
}
ResultSetProxy &ResultSetProxy::operator=(std::shared_ptr<ResultSet> resultSet)
{
if (resultSet_ == resultSet) {
if (GetInstance() == resultSet) {
return *this;
}
resultSet_ = std::move(resultSet);
SetInstance(std::move(resultSet));
return *this;
}
@ -171,7 +122,7 @@ ResultSetProxy *ResultSetProxy::GetInnerResultSet(napi_env env, napi_callback_in
ResultSetProxy *proxy = nullptr;
napi_unwrap(env, self, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->resultSet_, std::make_shared<InnerError>(E_RESULT_GOTO_ERROR));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<InnerError>(E_RESULT_GOTO_ERROR));
return proxy;
}
@ -190,7 +141,7 @@ ResultSetProxy *ResultSetProxy::ParseInt32FieldByName(
ResultSetProxy *proxy = nullptr;
napi_unwrap(env, self, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->resultSet_, std::make_shared<ParamError>("resultSet", "not null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("resultSet", "not null"));
return proxy;
}
@ -208,17 +159,17 @@ ResultSetProxy *ResultSetProxy::ParseFieldByName(
ResultSetProxy *proxy = nullptr;
napi_unwrap(env, self, reinterpret_cast<void **>(&proxy));
RDB_NAPI_ASSERT(env, proxy && proxy->resultSet_, std::make_shared<ParamError>("resultSet", "not null"));
RDB_NAPI_ASSERT(env, proxy && proxy->GetInstance(), std::make_shared<ParamError>("resultSet", "not null"));
return proxy;
}
napi_value ResultSetProxy::GetAllColumnNames(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
std::vector<std::string> colNames;
int errCode = resultSetProxy->resultSet_->GetAllColumnNames(colNames);
int errCode = resultSetProxy->GetInstance()->GetAllColumnNames(colNames);
if (errCode != E_OK) {
LOG_ERROR("GetAllColumnNames failed code:%{public}d", errCode);
}
@ -229,10 +180,10 @@ napi_value ResultSetProxy::GetAllColumnNames(napi_env env, napi_callback_info in
napi_value ResultSetProxy::GetColumnCount(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int32_t count = 0;
int errCode = resultSetProxy->resultSet_->GetColumnCount(count);
int errCode = resultSetProxy->GetInstance()->GetColumnCount(count);
if (errCode != E_OK) {
LOG_ERROR("GetColumnCount failed code:%{public}d", errCode);
}
@ -244,10 +195,10 @@ napi_value ResultSetProxy::GetColumnType(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
ColumnType columnType;
int errCode = resultSetProxy->resultSet_->GetColumnType(columnIndex, columnType);
int errCode = resultSetProxy->GetInstance()->GetColumnType(columnIndex, columnType);
if (errCode != E_OK) {
LOG_ERROR("GetColumnType failed code:%{public}d", errCode);
}
@ -258,10 +209,10 @@ napi_value ResultSetProxy::GetColumnType(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::GetRowCount(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int32_t result;
int errCode = resultSetProxy->resultSet_->GetRowCount(result);
int errCode = resultSetProxy->GetInstance()->GetRowCount(result);
if (errCode != E_OK) {
LOG_ERROR("GetRowCount failed code:%{public}d", errCode);
}
@ -272,10 +223,10 @@ napi_value ResultSetProxy::GetRowCount(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::GetRowIndex(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int32_t result;
int errCode = resultSetProxy->resultSet_->GetRowIndex(result);
int errCode = resultSetProxy->GetInstance()->GetRowIndex(result);
if (errCode != E_OK) {
LOG_ERROR("GetRowIndex failed code:%{public}d", errCode);
}
@ -286,10 +237,10 @@ napi_value ResultSetProxy::GetRowIndex(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::IsEnded(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = false;
int errCode = resultSetProxy->resultSet_->IsEnded(result);
int errCode = resultSetProxy->GetInstance()->IsEnded(result);
if (errCode != E_OK) {
LOG_ERROR("IsEnded failed code:%{public}d", errCode);
}
@ -300,10 +251,10 @@ napi_value ResultSetProxy::IsEnded(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::IsBegin(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = false;
int errCode = resultSetProxy->resultSet_->IsStarted(result);
int errCode = resultSetProxy->GetInstance()->IsStarted(result);
if (errCode != E_OK) {
LOG_ERROR("IsBegin failed code:%{public}d", errCode);
}
@ -314,10 +265,10 @@ napi_value ResultSetProxy::IsBegin(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::IsAtFirstRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = false;
int errCode = resultSetProxy->resultSet_->IsAtFirstRow(result);
int errCode = resultSetProxy->GetInstance()->IsAtFirstRow(result);
if (errCode != E_OK) {
LOG_ERROR("IsAtFirstRow failed code:%{public}d", errCode);
}
@ -328,10 +279,10 @@ napi_value ResultSetProxy::IsAtFirstRow(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::IsAtLastRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = false;
int errCode = resultSetProxy->resultSet_->IsAtLastRow(result);
int errCode = resultSetProxy->GetInstance()->IsAtLastRow(result);
if (errCode != E_OK) {
LOG_ERROR("IsAtLastRow failed code:%{public}d", errCode);
}
@ -342,9 +293,9 @@ napi_value ResultSetProxy::IsAtLastRow(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::Close(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->Close();
int errCode = resultSetProxy->GetInstance()->Close();
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
napi_value result = nullptr;
@ -356,9 +307,9 @@ napi_value ResultSetProxy::GoToRow(napi_env env, napi_callback_info info)
{
int32_t position;
auto resultSetProxy = ParseInt32FieldByName(env, info, position, "position");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoToRow(position);
int errCode = resultSetProxy->GetInstance()->GoToRow(position);
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
@ -366,45 +317,45 @@ napi_value ResultSetProxy::GoTo(napi_env env, napi_callback_info info)
{
int32_t offset;
auto resultSetProxy = ParseInt32FieldByName(env, info, offset, "offset");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoTo(offset);
int errCode = resultSetProxy->GetInstance()->GoTo(offset);
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
napi_value ResultSetProxy::GoToFirstRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoToFirstRow();
int errCode = resultSetProxy->GetInstance()->GoToFirstRow();
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
napi_value ResultSetProxy::GoToLastRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoToLastRow();
int errCode = resultSetProxy->GetInstance()->GoToLastRow();
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
napi_value ResultSetProxy::GoToNextRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoToNextRow();
int errCode = resultSetProxy->GetInstance()->GoToNextRow();
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
napi_value ResultSetProxy::GoToPreviousRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int errCode = resultSetProxy->resultSet_->GoToPreviousRow();
int errCode = resultSetProxy->GetInstance()->GoToPreviousRow();
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
}
@ -412,10 +363,10 @@ napi_value ResultSetProxy::GetInt(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int32_t result;
int errCode = resultSetProxy->resultSet_->GetInt(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetInt(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -425,10 +376,10 @@ napi_value ResultSetProxy::GetLong(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int64_t result;
int errCode = resultSetProxy->resultSet_->GetLong(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetLong(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -439,10 +390,10 @@ napi_value ResultSetProxy::GetBlob(napi_env env, napi_callback_info info)
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
std::vector<uint8_t> result;
int errCode = resultSetProxy->resultSet_->GetBlob(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetBlob(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -453,10 +404,10 @@ napi_value ResultSetProxy::GetAsset(napi_env env, napi_callback_info info)
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
Asset result;
int errCode = resultSetProxy->resultSet_->GetAsset(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetAsset(columnIndex, result);
if (errCode == E_NULL_OBJECT) {
LOG_DEBUG("getAsset col %{public}d is null ", columnIndex);
return JSUtils::Convert2JSValue(env, std::monostate());
@ -471,10 +422,10 @@ napi_value ResultSetProxy::GetAssets(napi_env env, napi_callback_info info)
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
Assets result;
int errCode = resultSetProxy->resultSet_->GetAssets(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetAssets(columnIndex, result);
if (errCode == E_NULL_OBJECT) {
LOG_DEBUG("getAssets col %{public}d is null ", columnIndex);
return JSUtils::Convert2JSValue(env, std::monostate());
@ -489,10 +440,10 @@ napi_value ResultSetProxy::GetString(napi_env env, napi_callback_info info)
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
std::string result;
int errCode = resultSetProxy->resultSet_->GetString(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetString(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -502,10 +453,10 @@ napi_value ResultSetProxy::GetDouble(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
double result = 0.0;
int errCode = resultSetProxy->resultSet_->GetDouble(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetDouble(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -515,10 +466,10 @@ napi_value ResultSetProxy::GetColumnIndex(napi_env env, napi_callback_info info)
{
std::string input;
auto resultSetProxy = ParseFieldByName(env, info, input, "columnName");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
int32_t result = -1;
int errCode = resultSetProxy->resultSet_->GetColumnIndex(input, result);
int errCode = resultSetProxy->GetInstance()->GetColumnIndex(input, result);
if (errCode != E_OK) {
LOG_ERROR("IsAtLastRow failed code:%{public}d", errCode);
}
@ -530,10 +481,10 @@ napi_value ResultSetProxy::GetColumnName(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
std::string result;
int errCode = resultSetProxy->resultSet_->GetColumnName(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->GetColumnName(columnIndex, result);
if (errCode != E_OK) {
LOG_ERROR("IsAtLastRow failed code:%{public}d", errCode);
}
@ -545,10 +496,10 @@ napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info)
{
int32_t columnIndex;
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = false;
int errCode = resultSetProxy->resultSet_->IsColumnNull(columnIndex, result);
int errCode = resultSetProxy->GetInstance()->IsColumnNull(columnIndex, result);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, result);
@ -557,10 +508,10 @@ napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::GetRow(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
RowEntity rowEntity;
int errCode = resultSetProxy->resultSet_->GetRow(rowEntity);
int errCode = resultSetProxy->GetInstance()->GetRow(rowEntity);
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<InnerError>(errCode));
return JSUtils::Convert2JSValue(env, rowEntity);
}
@ -568,10 +519,54 @@ napi_value ResultSetProxy::GetRow(napi_env env, napi_callback_info info)
napi_value ResultSetProxy::IsClosed(napi_env env, napi_callback_info info)
{
ResultSetProxy *resultSetProxy = GetInnerResultSet(env, info);
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->resultSet_);
bool result = resultSetProxy->resultSet_->IsClosed();
CHECK_RETURN_NULL(resultSetProxy && resultSetProxy->GetInstance());
bool result = resultSetProxy->GetInstance()->IsClosed();
return JSUtils::Convert2JSValue(env, result);
}
void ResultSetProxy::Init(napi_env env, napi_value exports)
{
LOG_INFO("ResultSetProxy::Init");
auto lambda = []() -> std::vector<napi_property_descriptor> {
std::vector<napi_property_descriptor> properties = {
DECLARE_NAPI_FUNCTION("goToRow", GoToRow),
DECLARE_NAPI_FUNCTION("getLong", GetLong),
DECLARE_NAPI_FUNCTION("getColumnType", GetColumnType),
DECLARE_NAPI_FUNCTION("goTo", GoTo),
DECLARE_NAPI_FUNCTION("getColumnIndex", GetColumnIndex),
DECLARE_NAPI_FUNCTION("getColumnName", GetColumnName),
DECLARE_NAPI_FUNCTION("close", Close),
DECLARE_NAPI_FUNCTION("goToFirstRow", GoToFirstRow),
DECLARE_NAPI_FUNCTION("goToLastRow", GoToLastRow),
DECLARE_NAPI_FUNCTION("goToNextRow", GoToNextRow),
DECLARE_NAPI_FUNCTION("goToPreviousRow", GoToPreviousRow),
DECLARE_NAPI_FUNCTION("getInt", GetInt),
DECLARE_NAPI_FUNCTION("getBlob", GetBlob),
DECLARE_NAPI_FUNCTION("getAsset", GetAsset),
DECLARE_NAPI_FUNCTION("getAssets", GetAssets),
DECLARE_NAPI_FUNCTION("getString", GetString),
DECLARE_NAPI_FUNCTION("getDouble", GetDouble),
DECLARE_NAPI_FUNCTION("isColumnNull", IsColumnNull),
DECLARE_NAPI_FUNCTION("getRow", GetRow),
DECLARE_NAPI_GETTER("columnNames", GetAllColumnNames),
DECLARE_NAPI_GETTER("columnCount", GetColumnCount),
DECLARE_NAPI_GETTER("isEnded", IsEnded),
DECLARE_NAPI_GETTER("isStarted", IsBegin),
DECLARE_NAPI_GETTER("isClosed", IsClosed),
DECLARE_NAPI_GETTER("rowCount", GetRowCount),
DECLARE_NAPI_GETTER("rowIndex", GetRowIndex),
DECLARE_NAPI_GETTER("isAtFirstRow", IsAtFirstRow),
DECLARE_NAPI_GETTER("isAtLastRow", IsAtLastRow),
};
return properties;
};
auto jsCtor = JSUtils::DefineClass(env, "ohos.data.relationalStore", "ResultSet", lambda, Initialize);
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "ResultSet", jsCtor));
LOG_DEBUG("ResultSetProxy::Init end");
}
} // namespace RelationalStoreJsKit
} // namespace OHOS

View File

@ -32,6 +32,9 @@ public:
int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override;
int32_t NotifyDataChange(const std::string &eventId, const std::string &extraData, int32_t userId) override;
std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> AllocResourceAndShare(const std::string& storeId,
const DistributedRdb::PredicatesMemo& predicates, const std::vector<std::string>& columns,
const std::vector<Participant>& participants) override;
private:
sptr<IRemoteObject> remote_;
};

View File

@ -0,0 +1,70 @@
/*
* 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_CLOUD_CLOUD_TYPES_UTIL_H
#define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H
#include "itypes_util.h"
#include "cloud_types.h"
#include "values_bucket.h"
namespace OHOS::ITypesUtil {
using Participant = OHOS::CloudData::Participant;
using Privilege = OHOS::CloudData::Privilege;
using Role = OHOS::CloudData::Role;
using Confirmation = OHOS::CloudData::Confirmation;
using SharingCode = OHOS::CloudData::SharingCode;
using Asset = OHOS::NativeRdb::AssetValue;
using ValueObject = OHOS::NativeRdb::ValueObject;
using ValuesBucket = OHOS::NativeRdb::ValuesBucket;
template<>
bool Marshalling(const Participant &input, MessageParcel &data);
template<>
bool Unmarshalling(Participant &output, MessageParcel &data);
template<>
bool Marshalling(const Privilege &input, MessageParcel &data);
template<>
bool Unmarshalling(Privilege &output, MessageParcel &data);
template<>
bool Marshalling(const Role &input, MessageParcel &data);
template<>
bool Unmarshalling(Role &output, MessageParcel &data);
template<>
bool Marshalling(const Confirmation &input, MessageParcel &data);
template<>
bool Unmarshalling(Confirmation &output, MessageParcel &data);
template<>
bool Marshalling(const SharingCode &input, MessageParcel &data);
template<>
bool Unmarshalling(SharingCode &output, MessageParcel &data);
template<>
bool Marshalling(const Asset &input, MessageParcel &data);
template<>
bool Unmarshalling(Asset &output, MessageParcel &data);
template<>
bool Marshalling(const ValueObject &input, MessageParcel &data);
template<>
bool Unmarshalling(ValueObject &output, MessageParcel &data);
template<>
bool Marshalling(const ValuesBucket &input, MessageParcel &data);
template<>
bool Unmarshalling(ValuesBucket &output, MessageParcel &data);
} // namespace OHOS::ITypesUtil
#endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H

View File

@ -102,6 +102,20 @@ int32_t CloudServiceProxy::NotifyDataChange(const std::string &id, const std::st
return static_cast<Status>(status);
}
std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> CloudServiceProxy::AllocResourceAndShare(
const std::string &storeId, const DistributedRdb::PredicatesMemo &predicates,
const std::vector<std::string> &columns, const std::vector<Participant> &participants)
{
MessageParcel reply;
int32_t status = IPC_SEND(TRANS_ALLOC_RESOURCE_AND_SHARE, reply, storeId, predicates, columns, participants);
if (status != SUCCESS) {
LOG_ERROR("status:0x%{public}x storeName:%{public}.6s", status, storeId.c_str());
}
std::vector<NativeRdb::ValuesBucket> valueBuckets;
ITypesUtil::Unmarshal(reply, valueBuckets);
return { static_cast<Status>(status), valueBuckets };
}
int32_t CloudServiceProxy::NotifyDataChange(const std::string &eventId, const std::string &extraData, int32_t userId)
{
MessageParcel reply;

View File

@ -0,0 +1,128 @@
/*
* 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.
*/
#include "cloud_types_util.h"
namespace OHOS::ITypesUtil {
template<>
bool Marshalling(const Participant &input, MessageParcel &data)
{
return ITypesUtil::Marshal(
data, input.identity, input.role, input.status, input.privilege, input.attachInfo);
}
template<>
bool Unmarshalling(Participant &output, MessageParcel &data)
{
return ITypesUtil::Unmarshal(
data, output.identity, output.role, output.status, output.privilege, output.attachInfo);
}
template<>
bool Marshalling(const Privilege &input, MessageParcel &data)
{
return ITypesUtil::Marshal(data, input.writable, input.readable,
input.creatable, input.deletable, input.shareable);
}
template<>
bool Unmarshalling(Privilege &output, MessageParcel &data)
{
return ITypesUtil::Unmarshal(data, output.writable, output.readable,
output.creatable, output.deletable, output.shareable);
}
template<>
bool Marshalling(const Role &input, MessageParcel &data)
{
return data.WriteInt32(static_cast<int32_t>(input));
}
template<>
bool Unmarshalling(Role &output, MessageParcel &data)
{
int32_t result;
if (!data.ReadInt32(result) || result <= Role::ROLE_NIL || result >= Role::ROLE_BUTT) {
return false;
}
output = static_cast<Role>(result);
return true;
}
template<>
bool Marshalling(const Confirmation &input, MessageParcel &data)
{
return data.WriteInt32(static_cast<int32_t>(input));
}
template<>
bool Unmarshalling(Confirmation &output, MessageParcel &data)
{
int32_t result;
if (!data.ReadInt32(result) || result <= Confirmation::CFM_NIL ||
result >= Confirmation::CFM_BUTT) {
return false;
}
output = static_cast<Confirmation>(result);
return true;
}
template<>
bool Marshalling(const SharingCode &input, MessageParcel &data)
{
return data.WriteInt32(static_cast<int32_t>(input));
}
template<>
bool Unmarshalling(SharingCode &output, MessageParcel &data)
{
int32_t result;
if (!data.ReadInt32(result) || result < SharingCode::SUCCESS) {
return false;
}
output = static_cast< SharingCode>(result);
return true;
}
template<>
bool Marshalling(const Asset &input, MessageParcel &data)
{
return Marshal(data, input.version, input.name, input.size, input.modifyTime, input.uri);
}
template<>
bool Unmarshalling(Asset &output, MessageParcel &data)
{
return Unmarshal(data, output.version, output.name, output.size, output.modifyTime, output.uri);
}
template<>
bool Marshalling(const ValueObject &input, MessageParcel &data)
{
return Marshal(data, input.value);
}
template<>
bool Unmarshalling(ValueObject &output, MessageParcel &data)
{
return Unmarshal(data, output.value);
}
template<>
bool Marshalling(const ValuesBucket &input, MessageParcel &data)
{
return Marshal(data, input.values_);
}
template<>
bool Unmarshalling(ValuesBucket &output, MessageParcel &data)
{
return Unmarshal(data, output.values_);
}
} // namespace OHOS::ITypesUtil

View File

@ -70,6 +70,9 @@ public:
int32_t Delete(const RdbSyncerParam &param) override;
int32_t NotifyDataChange(const RdbSyncerParam& param, const RdbChangedData &clientChangedData) override;
std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> QuerySharingResource(const RdbSyncerParam &param,
const PredicatesMemo &predicates, const std::vector<std::string> &columns) override;
private:
using ChangeInfo = RdbStoreObserver::ChangeInfo;
using PrimaryFields = RdbStoreObserver::PrimaryFields;

View File

@ -141,6 +141,8 @@ public:
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns) override;
std::shared_ptr<AbsSharedResultSet> Query(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns) override;
std::pair<int32_t, std::shared_ptr<ResultSet>> QuerySharingResource(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns) override;
int Count(int64_t &outValue, const AbsRdbPredicates &predicates) override;
int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) override;
int Delete(int &deletedRows, const AbsRdbPredicates &predicates) override;

View File

@ -251,4 +251,70 @@ AbsPredicates *AbsRdbPredicates::In(const std::string &field, const std::vector<
predicates_.AddOperation(DistributedRdb::IN, field, values);
return (AbsRdbPredicates *)AbsPredicates::In(field, values);
}
AbsRdbPredicates *AbsRdbPredicates::Contains(const std::string &field, const std::string &value)
{
predicates_.AddOperation(DistributedRdb::CONTAIN, field, value);
return (AbsRdbPredicates *)AbsPredicates::Contains(field, value);
}
AbsRdbPredicates *AbsRdbPredicates::BeginsWith(const std::string &field, const std::string &value)
{
predicates_.AddOperation(DistributedRdb::BEGIN_WITH, field, value);
return (AbsRdbPredicates *)AbsPredicates::BeginsWith(field, value);
}
AbsRdbPredicates *AbsRdbPredicates::EndsWith(const std::string &field, const std::string &value)
{
predicates_.AddOperation(DistributedRdb::END_WITH, field, value);
return (AbsRdbPredicates *)AbsPredicates::EndsWith(field, value);
}
AbsRdbPredicates *AbsRdbPredicates::IsNull(const std::string &field)
{
predicates_.AddOperation(DistributedRdb::IS_NULL, field, "");
return (AbsRdbPredicates *)AbsPredicates::IsNull(field);
}
AbsRdbPredicates *AbsRdbPredicates::IsNotNull(const std::string &field)
{
predicates_.AddOperation(DistributedRdb::IS_NOT_NULL, field, "");
return (AbsRdbPredicates *)AbsPredicates::IsNotNull(field);
}
AbsRdbPredicates *AbsRdbPredicates::Like(const std::string &field, const std::string &value)
{
predicates_.AddOperation(DistributedRdb::LIKE, field, value);
return (AbsRdbPredicates *)AbsPredicates::Like(field, value);
}
AbsRdbPredicates *AbsRdbPredicates::Glob(const std::string &field, const std::string &value)
{
predicates_.AddOperation(DistributedRdb::GLOB, field, value);
return (AbsRdbPredicates *)AbsPredicates::Glob(field, value);
}
AbsRdbPredicates *AbsRdbPredicates::Distinct()
{
predicates_.AddOperation(DistributedRdb::DISTINCT, "", "");
return (AbsRdbPredicates *)AbsPredicates::Distinct();
}
AbsRdbPredicates *AbsRdbPredicates::IndexedBy(const std::string &indexName)
{
predicates_.AddOperation(DistributedRdb::INDEXED_BY, indexName, "");
return (AbsRdbPredicates *)AbsPredicates::IndexedBy(indexName);
}
AbsRdbPredicates *AbsRdbPredicates::NotIn(const std::string &field, const std::vector<std::string> &values)
{
predicates_.AddOperation(DistributedRdb::NOT_IN, field, values);
return (AbsRdbPredicates *)AbsPredicates::NotIn(field, values);
}
AbsRdbPredicates *AbsRdbPredicates::NotIn(const std::string &field, const std::vector<ValueObject> &values)
{
std::vector<std::string> vals;
vals.reserve(values.size());
for (const auto &value : values) {
auto val = std::get_if<std::string>(&value.value);
if (val == nullptr) {
return (AbsRdbPredicates *)AbsPredicates::NotIn(field, values);
}
vals.emplace_back(std::move(*val));
}
predicates_.AddOperation(DistributedRdb::NOT_IN, field, vals);
return (AbsRdbPredicates *)AbsPredicates::NotIn(field, values);
}
} // namespace OHOS::NativeRdb

View File

@ -0,0 +1,331 @@
/*
* Copyright (c) 2021 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 "CacheResultSet"
#include "cache_result_set.h"
#include <algorithm>
#include <string>
#include "abs_result_set.h"
#include "logger.h"
#include "rdb_errno.h"
#include "rdb_trace.h"
namespace OHOS {
namespace NativeRdb {
CacheResultSet::CacheResultSet(std::vector<NativeRdb::ValuesBucket> &&valueBuckets)
: row_(0), maxCol_(0), valueBuckets_(std::move(valueBuckets))
{
maxRow_ = valueBuckets_.size();
if (maxRow_ > 0) {
for (auto it = valueBuckets_[0].values_.begin(); it != valueBuckets_[0].values_.end(); it++) {
colNames_.push_back(it->first);
colTypes_.push_back(it->second.GetType());
}
maxCol_ = colNames_.size();
}
}
CacheResultSet::~CacheResultSet()
{
}
int CacheResultSet::GetRowCount(int &count)
{
count = static_cast<int>(colNames_.size());
return E_OK;
}
int CacheResultSet::GetAllColumnNames(std::vector<std::string> &columnNames)
{
columnNames = colNames_;
return E_OK;
}
int CacheResultSet::GetBlob(int columnIndex, std::vector<uint8_t> &blob)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetBlob(blob);
}
int CacheResultSet::GetString(int columnIndex, std::string &value)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetString(value);
}
int CacheResultSet::GetInt(int columnIndex, int &value)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetInt(value);
}
int CacheResultSet::GetLong(int columnIndex, int64_t &value)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetLong(value);
}
int CacheResultSet::GetDouble(int columnIndex, double &value)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetDouble(value);
}
int CacheResultSet::IsColumnNull(int columnIndex, bool &isNull)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[columnIndex];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
isNull = valueBuckets_[row_].values_[name].GetType() == ValueObject::TYPE_NULL;
return E_OK;
}
int CacheResultSet::GetRow(RowEntity &rowEntity)
{
rowEntity.Clear();
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
ValueObject object;
for (auto &columnName : colNames_) {
if (!valueBuckets_[row_].GetObject(columnName, object)) {
return E_ERROR;
}
rowEntity.Put(columnName, object);
}
return E_OK;
}
int CacheResultSet::GoToRow(int position)
{
std::unique_lock<decltype(rwMutex_)> lock(rwMutex_);
if (position > maxRow_) {
row_ = maxRow_;
return E_OK;
}
if (position < 0) {
row_ = 0;
return E_OK;
}
row_ = position;
return E_OK;
}
int CacheResultSet::GetColumnType(int columnIndex, ColumnType &columnType)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
auto index = colTypes_[columnIndex];
if (index < ValueObject::TYPE_NULL || index >= ValueObject::TYPE_MAX) {
return E_INVALID_ARGS;
}
columnType = COLUMNTYPES[index];
return E_OK;
}
int CacheResultSet::GetRowIndex(int &position) const
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
position = row_;
return E_OK;
}
int CacheResultSet::GoTo(int offset)
{
int target = offset;
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
target += row_;
}
return GoToRow(target);
}
int CacheResultSet::GoToFirstRow()
{
return GoToRow(0);
}
int CacheResultSet::GoToLastRow()
{
return GoToRow(maxRow_ - 1);
}
int CacheResultSet::GoToNextRow()
{
return GoTo(1);
}
int CacheResultSet::GoToPreviousRow()
{
return GoTo(-1);
}
int CacheResultSet::IsAtFirstRow(bool &result) const
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
result = row_ == 0;
return E_OK;
}
int CacheResultSet::IsAtLastRow(bool &result)
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
result = row_ == maxRow_ - 1;
return E_OK;
}
int CacheResultSet::IsStarted(bool &result) const
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
result = row_ == -1;
return E_OK;
}
int CacheResultSet::IsEnded(bool &result)
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
result = maxRow_ == 0 || row_ == maxRow_;
return E_OK;
}
int CacheResultSet::GetColumnCount(int &count)
{
return static_cast<int>(colNames_.size());
}
int CacheResultSet::GetColumnIndex(const std::string &columnName, int &columnIndex)
{
for (int i = 0; i < maxCol_; ++i) {
if (colNames_[i] == columnName) {
columnIndex = i;
return E_OK;
}
}
return E_ERROR;
}
int CacheResultSet::GetColumnName(int columnIndex, std::string &columnName)
{
if (columnIndex < 0 || columnIndex >= maxCol_) {
return E_INVALID_ARGS;
}
columnName = columnName[columnIndex];
return E_OK;
}
bool CacheResultSet::IsClosed() const
{
return false;
}
int CacheResultSet::Close()
{
return E_NOT_SUPPORT;
}
int CacheResultSet::GetModifyTime(std::string &modifyTime)
{
return E_NOT_SUPPORT;
}
int CacheResultSet::GetAsset(int32_t col, ValueObject::Asset &value)
{
if (col < 0 || col >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[col];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetAsset(value);
}
int CacheResultSet::GetAssets(int32_t col, ValueObject::Assets &value)
{
if (col < 0 || col >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[col];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
return valueBuckets_[row_].values_[name].GetAssets(value);
}
int CacheResultSet::Get(int32_t col, ValueObject &value)
{
if (col < 0 || col >= maxCol_) {
return E_INVALID_ARGS;
}
auto name = colNames_[col];
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (row_ < 0 || row_ >= maxRow_) {
return E_ERROR;
}
value = valueBuckets_[row_].values_[name];
return E_OK;
}
int CacheResultSet::GetSize(int columnIndex, size_t &size)
{
return E_NOT_SUPPORT;
}
}
} // namespace OHOS

View File

@ -342,6 +342,21 @@ int32_t RdbServiceProxy::Delete(const RdbSyncerParam &param)
return status;
}
std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> RdbServiceProxy::QuerySharingResource(
const RdbSyncerParam &param, const PredicatesMemo &predicates, const std::vector<std::string> &columns)
{
MessageParcel reply;
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_QUERY_SHARING_RESOURCE), reply,
param, predicates, columns);
std::vector<NativeRdb::ValuesBucket> valueBuckets;
bool success = ITypesUtil::Unmarshal(reply, valueBuckets);
if (status != RDB_OK || !success) {
LOG_ERROR("status:%{public}d, valueBuckets size:%{public}zu", status, valueBuckets.size());
return { RDB_ERROR, {} };
}
return { RDB_OK, valueBuckets };
}
int32_t RdbServiceProxy::RegisterAutoSyncCallback(
const RdbSyncerParam &param, std::shared_ptr<DetailProgressObserver> observer)
{

View File

@ -21,6 +21,7 @@
#include <sstream>
#include "logger.h"
#include "cache_result_set.h"
#include "rdb_errno.h"
#include "rdb_sql_utils.h"
#include "rdb_store.h"
@ -619,6 +620,18 @@ std::shared_ptr<AbsSharedResultSet> RdbStoreImpl::Query(
return QuerySql(sql, predicates.GetBindArgs());
}
std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStoreImpl::QuerySharingResource(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
{
auto [errCode, service] = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_);
if (errCode != E_OK) {
return { errCode, nullptr };
}
auto [status, valueBuckets] =
service->QuerySharingResource(syncerParam_, predicates.GetDistributedPredicates(), columns);
return { status, std::make_shared<CacheResultSet>(std::move(valueBuckets)) };
}
std::shared_ptr<ResultSet> RdbStoreImpl::QueryByStep(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
{

View File

@ -18,7 +18,12 @@
#include <cstdint>
#include <map>
#include <string>
namespace OHOS::CloudData {
#include <vector>
#include "cloud_types.h"
#include "rdb_types.h"
#include "values_bucket.h"
namespace OHOS {
namespace CloudData {
class CloudService {
public:
enum TransId : int32_t {
@ -29,6 +34,7 @@ public:
TRANS_CLEAN,
TRANS_NOTIFY_DATA_CHANGE,
TRANS_NOTIFY_DATA_CHANGE_EXT,
TRANS_ALLOC_RESOURCE_AND_SHARE,
TRANS_BUTT,
};
enum Action : int32_t {
@ -67,7 +73,11 @@ public:
virtual int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) = 0;
virtual int32_t NotifyDataChange(const std::string &eventId, const std::string &extraData, int32_t userId) = 0;
virtual std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> AllocResourceAndShare(const std::string &storeId,
const DistributedRdb::PredicatesMemo &predicates, const std::vector<std::string> &columns,
const std::vector<Participant> &participants) = 0;
inline static constexpr const char *SERVICE_NAME = "cloud";
};
} // namespace OHOS::CloudData
} // namespace CloudData
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_H

View File

@ -0,0 +1,129 @@
/*
* 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_CLOUD_CLOUD_TYPES_H
#define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_H
#include <string>
namespace OHOS::CloudData {
enum Role : int32_t {
ROLE_NIL = -1,
ROLE_INVITER,
ROLE_INVITEE,
ROLE_BUTT
};
enum Confirmation : int32_t {
CFM_NIL = -1,
CFM_UNKNOWN,
CFM_ACCEPTED,
CFM_REJECTED,
CFM_SUSPENDED,
CFM_BUTT
};
struct Privilege {
bool writable = false;
bool readable = false;
bool creatable = false;
bool deletable = false;
bool shareable = false;
};
struct Participant {
std::string identity;
int32_t role = Role::ROLE_NIL;
int32_t status = Confirmation::CFM_NIL;
Privilege privilege;
std::string attachInfo;
};
/**
* Enumerates the error code of sharing invitation.
*/
enum SharingCode : int32_t {
/**
* @brief means sharing success.
*/
SUCCESS = 0,
/**
* @brief means the user has been invited.
*/
REPEATED_REQUEST,
/**
* @brief means the participant is not inviter.
*/
NOT_INVITER,
/**
* @brief means the participant is not inviter or invitee.
*/
NOT_INVITER_OR_INVITEE,
/**
* @brief means the number of sharing times today of current user has reached maximum.
*/
OVER_QUOTA,
/**
* @brief means the number of participants reaches the maximum.
*/
TOO_MANY_PARTICIPANTS,
/**
* @brief means invalid arguments.
*/
INVALID_ARGS,
/**
* @brief means the network is unavailable.
*/
NETWORK_ERROR,
/**
* @brief means cloud is disabled.
*/
CLOUD_DISABLED,
/**
* @brief means invoke cloud space failed.
*/
SERVER_ERROR,
/**
* @brief means an unknown error has occurred.
*/
INNER_ERROR,
/**
* @brief means the invitation has expired or does not exist.
*/
INVALID_INVITATION,
/**
* @brief means the data transfer is rate-limited.
*/
RATE_LIMIT,
/**
* @brief means error codes that exceed this enumerated value are custom error codes.
*/
CUSTOM_ERROR = 1000,
};
} // namespace OHOS::CloudData
#endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_H

View File

@ -18,7 +18,7 @@ base_sources = [
"${relational_store_native_path}/rdb/src/abs_rdb_predicates.cpp",
"${relational_store_native_path}/rdb/src/abs_result_set.cpp",
"${relational_store_native_path}/rdb/src/base_transaction.cpp",
"${relational_store_native_path}/rdb/src/base_transaction.h",
"${relational_store_native_path}/rdb/src/cache_result_set.cpp",
"${relational_store_native_path}/rdb/src/raw_data_parser.cpp",
"${relational_store_native_path}/rdb/src/rdb_helper.cpp",
"${relational_store_native_path}/rdb/src/rdb_predicates.cpp",

View File

@ -151,6 +151,83 @@ public:
*/
API_EXPORT virtual AbsPredicates *In(const std::string &field, const std::vector<std::string> &values) override;
/**
* @brief Adds an Contains condition to the remote AbsRdbPredicates.
*
* This method indicates that the expected field contains value.
*/
API_EXPORT AbsRdbPredicates *Contains(const std::string &field, const std::string &value) override;
/**
* @brief Adds an BeginsWith condition to the remote AbsRdbPredicates.
*
* This method indicates that the expected field begin with value.
*/
API_EXPORT AbsRdbPredicates *BeginsWith(const std::string &field, const std::string &value) override;
/**
* @brief Adds an EndsWith condition to the remote AbsRdbPredicates.
*
* This method indicates that the expected field end with value.
*/
API_EXPORT AbsRdbPredicates *EndsWith(const std::string &field, const std::string &value) override;
/**
* @brief Adds an IsNull condition to the remote AbsRdbPredicates.
*
* This method indicates that the expected field is null.
*/
API_EXPORT AbsRdbPredicates *IsNull(const std::string &field) override;
/**
* @brief Adds an IsNotNull condition to the remote AbsRdbPredicates.
*
* This method indicates that the expected field is not null.
*/
API_EXPORT AbsRdbPredicates *IsNotNull(const std::string &field) override;
/**
* @brief Adds an Like condition to the remote AbsRdbPredicates.
*
* This method is similar to Like of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *Like(const std::string &field, const std::string &value) override;
/**
* @brief Adds an Glob condition to the remote AbsRdbPredicates.
*
* This method is similar to glob of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *Glob(const std::string &field, const std::string &value) override;
/**
* @brief Adds an Distinct condition to the remote AbsRdbPredicates.
*
* This method is similar to distinct of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *Distinct() override;
/**
* @brief Adds an IndexedBy condition to the remote AbsRdbPredicates.
*
* This method is similar to indexed by of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *IndexedBy(const std::string &indexName) override;
/**
* @brief Adds an NotIn condition to the remote AbsRdbPredicates.
*
* This method is similar to not in of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *NotIn(const std::string &field, const std::vector<std::string> &values) override;
/**
* @brief Adds an NotIn condition to the remote AbsRdbPredicates.
*
* This method is similar to not in of the SQL statement.
*/
API_EXPORT AbsRdbPredicates *NotIn(const std::string &field, const std::vector<ValueObject> &values) override;
/**
* @brief Restricts the ascending order of the return list. When there are several orders,
* the one close to the head has the highest priority.

View File

@ -0,0 +1,332 @@
/*
* Copyright (c) 2021 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 NATIVE_RDB_CACHE_RESULT_SET_H
#define NATIVE_RDB_CACHE_RESULT_SET_H
#include <map>
#include <memory>
#include <shared_mutex>
#include <string>
#include <vector>
#include "result_set.h"
#include "value_object.h"
#include "values_bucket.h"
namespace OHOS {
namespace NativeRdb {
/**
* The CacheResultSet class of RDB.
* Provides methods for accessing a database result set generated by querying the database.
*/
class API_EXPORT CacheResultSet : public ResultSet {
public:
/**
* @brief Constructor.
*/
API_EXPORT CacheResultSet(std::vector<NativeRdb::ValuesBucket> &&valueBuckets);
/**
* @brief Destructor.
*/
API_EXPORT virtual ~CacheResultSet();
/**
* @brief Obtains the number of rows in the result set.
*/
API_EXPORT int GetRowCount(int &count) override;
/**
* @brief Obtains the names of all columns in a result set.
*/
API_EXPORT int GetAllColumnNames(std::vector<std::string> &columnNames) override;
/**
* @brief Obtains the value of the specified column in the current row as a byte array.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the Blob type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a byte array.
*/
API_EXPORT int GetBlob(int columnIndex, std::vector<uint8_t> &blob) override;
/**
* @brief Obtains the value of the specified column in the current row as string.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the string type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a string.
*/
API_EXPORT int GetString(int columnIndex, std::string &value) override;
/**
* @brief Obtains the value of the specified column in the current row as int.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the integer type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a int.
*/
API_EXPORT int GetInt(int columnIndex, int &value) override;
/**
* @brief Obtains the value of the specified column in the current row as long.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the long type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a long.
*/
API_EXPORT int GetLong(int columnIndex, int64_t &value) override;
/**
* @brief Obtains the value of the specified column in the current row as double.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the double type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a double.
*/
API_EXPORT int GetDouble(int columnIndex, double &value) override;
/**
* @brief Obtains the value of the specified column in the current row as asset.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the Asset type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a double.
*/
API_EXPORT int GetAsset(int32_t col, ValueObject::Asset &value) override;
/**
* @brief Obtains the value of the specified column in the current row as assets.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the Assets type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a double.
*/
API_EXPORT int GetAssets(int32_t col, ValueObject::Assets &value) override;
/**
* @brief Obtains the value of the specified column in the current row as ValueObject.
*
* The implementation class determines whether to throw an exception if the value of the specified column
* in the current row is null or the specified column is not of the double type.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the value of the specified column as a double.
*/
API_EXPORT int Get(int32_t col, ValueObject &value) override;
/**
* @brief Get the modify time of the cloud data.
*
* @param modifyTime Indicates the data modify utc time.
*
* @return Returns true if the value of the specified column in the current row is null;
* returns false otherwise.
*/
API_EXPORT int GetModifyTime(std::string &modifyTime) override;
/**
* @brief Checks whether the value of the specified column in the current row is null.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns true if the value of the specified column in the current row is null;
* returns false otherwise.
*/
API_EXPORT int IsColumnNull(int columnIndex, bool &isNull) override;
/**
* @brief Gets the entire row of data for the current row from the result set.
*/
API_EXPORT int GetRow(RowEntity &rowEntity) override;
/**
* @brief Move the cursor to an absolute position.
*
* @param position Indicates the specified column index, which starts from 0.
*
* @return Returns whether the requested move succeeded.
*/
API_EXPORT int GoToRow(int position) override;
/**
* @brief Obtains data type of the given column's value.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns column value type.
*/
API_EXPORT int GetColumnType(int columnIndex, ColumnType &columnType) override;
/**
* @brief Returns the current position of the cursor in the result set.
*
* The value is zero-based. When the result set is first returned the cursor
* will be at position -1, which is before the first row.
* After the last row is returned another call to next() will leave the cursor past
* the last entry, at a position of count().
*
* @return Returns the current cursor position.
*/
API_EXPORT int GetRowIndex(int &position) const override;
/**
* @brief Go to the specified row of the result set forwards or backwards by an offset
* relative to its current position.
*
* A positive offset indicates moving backwards, and a negative offset indicates moving forwards.
*
* @param offset Indicates the offset relative to the current position.
*
* @return Returns whether true if the result set is moved successfully and does not go beyond the range;
* returns false otherwise.
*/
API_EXPORT int GoTo(int offset) override;
/**
* @brief Go to the first row of the result set.
*
* @return Returns if the result set is moved successfully;
* returns false otherwise, for example, if the result set is empty.
*/
API_EXPORT int GoToFirstRow() override;
/**
* @brief Go to the last row of the result set.
*
* @return Returns if the result set is moved successfully;
* returns false otherwise, for example, if the result set is empty.
*/
API_EXPORT int GoToLastRow() override;
/**
* @brief Go to the next row of the result set.
*
* @return Returns if the result set is moved successfully;
* returns false otherwise, for example, if the result set is already in the last row.
*/
API_EXPORT int GoToNextRow() override;
/**
* @brief Go to the previous row of the result set.
*
* @return Returns if the result set is moved successfully;
* returns false otherwise, for example, if the result set is already in the first row.
*/
API_EXPORT int GoToPreviousRow() override;
/**
* @brief Checks whether the result set is positioned at the first row.
*/
API_EXPORT int IsAtFirstRow(bool &result) const override;
/**
* @brief Checks whether the result set is positioned at the last row.
*/
API_EXPORT int IsAtLastRow(bool &result) override;
/**
* @brief Returns whether the cursor is pointing to the position before the first row.
*/
API_EXPORT int IsStarted(bool &result) const override;
/**
* @brief Checks whether the result set is positioned after the last row.
*/
API_EXPORT int IsEnded(bool &result) override;
/**
* @brief Obtains the number of columns in the result set.
*/
API_EXPORT int GetColumnCount(int &count) override;
/**
* @brief Returns the zero-based index for the given column name.
*
* @param columnName Indicates the specified name of the column.
*
* @return Returns the column index for the given column, or -1 if the column does not exist.
*/
API_EXPORT int GetColumnIndex(const std::string &columnName, int &columnIndex) override;
/**
* @brief Returns the column name at the given column index.
*
* @param columnIndex Indicates the specified column index, which starts from 0.
*
* @return Returns the column name for the given index.
*/
API_EXPORT int GetColumnName(int columnIndex, std::string &columnName) override;
/**
* @brief Checks whether the current result set is closed.
*
* @return Returns the true if the result set is closed by calling the close method.
*/
API_EXPORT bool IsClosed() const override;
/**
* @brief Closes the result set.
*
* Calling this method on the result set will release all of its resources and makes it ineffective.
*/
API_EXPORT int Close() override;
int GetSize(int columnIndex, size_t &size) override;
private:
static constexpr ColumnType COLUMNTYPES[ValueObject::TYPE_MAX] = {
[ValueObject::TYPE_NULL] = ColumnType::TYPE_NULL,
[ValueObject::TYPE_INT] = ColumnType::TYPE_INTEGER,
[ValueObject::TYPE_DOUBLE] = ColumnType::TYPE_FLOAT,
[ValueObject::TYPE_STRING] = ColumnType::TYPE_STRING,
[ValueObject::TYPE_BOOL] = ColumnType::TYPE_INTEGER,
[ValueObject::TYPE_BLOB] = ColumnType::TYPE_BLOB,
[ValueObject::TYPE_ASSET] = ColumnType::TYPE_BLOB,
[ValueObject::TYPE_ASSETS] = ColumnType::TYPE_BLOB,
};
int32_t row_;
mutable std::shared_mutex rwMutex_;
int32_t maxRow_;
int32_t maxCol_;
std::vector<std::string> colNames_;
std::vector<int32_t> colTypes_;
std::vector<NativeRdb::ValuesBucket> valueBuckets_;
};
} // namespace NativeRdb
} // namespace OHOS
#endif

View File

@ -80,6 +80,7 @@ enum class RdbServiceInterfaceCode {
RDB_SERVICE_CMD_REGISTER_AUTOSYNC_PROGRESS_OBSERVER,
RDB_SERVICE_CMD_UNREGISTER_AUTOSYNC_PROGRESS_OBSERVER,
RDB_SERVICE_CMD_NOTIFY_DATA_CHANGE,
RDB_SERVICE_CMD_QUERY_SHARING_RESOURCE,
RDB_SERVICE_CMD_MAX
};
} // namespace RelationalStore

View File

@ -22,6 +22,7 @@
#include "rdb_types.h"
#include "rdb_notifier.h"
#include "distributeddata_relational_store_ipc_interface_code.h"
#include "values_bucket.h"
namespace OHOS {
template <typename T>
@ -65,12 +66,15 @@ public:
virtual int32_t GetSchema(const RdbSyncerParam &param) = 0;
//only use param.storeName_
// only use param.storeName_
virtual int32_t Delete(const RdbSyncerParam &param) = 0;
inline static constexpr const char *SERVICE_NAME = "relational_store";
virtual std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> QuerySharingResource(
const RdbSyncerParam &param, const PredicatesMemo &predicates, const std::vector<std::string> &columns) = 0;
virtual int32_t NotifyDataChange(const RdbSyncerParam &param, const RdbChangedData &rdbChangedData) = 0;
inline static constexpr const char *SERVICE_NAME = "relational_store";
};
}
} // namespace OHOS::DistributedRdb

View File

@ -333,6 +333,18 @@ public:
virtual std::shared_ptr<AbsSharedResultSet> Query(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns) = 0;
/**
* @brief Queries data in the database based on specified conditions.
*
* @param predicates Indicates the specified query condition by the instance object of {@link AbsRdbPredicates}.
* @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
*/
virtual std::pair<int32_t, std::shared_ptr<ResultSet>> QuerySharingResource(
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
{
return { E_NOT_SUPPORT, nullptr };
}
/**
* @brief Queries data in the database based on specified conditions.
*

View File

@ -136,6 +136,22 @@ enum RdbPredicateOperator {
BEGIN_GROUP,
END_GROUP,
IN,
NOT_IN,
CONTAIN,
BEGIN_WITH,
END_WITH,
IS_NULL,
IS_NOT_NULL,
LIKE,
GLOB,
BETWEEN,
NOT_BETWEEN,
GREATER_THAN,
GREATER_THAN_OR_EQUAL,
LESS_THAN,
LESS_THAN_OR_EQUAL,
DISTINCT,
INDEXED_BY,
OPERATOR_MAX
};
@ -244,6 +260,7 @@ struct Field {
static constexpr const char *DELETED_FLAG_FIELD = "#_deleted_flag";
static constexpr const char *OWNER_FIELD = "#_cloud_owner";
static constexpr const char *PRIVILEGE_FIELD = "#_cloud_privilege";
static constexpr const char *SHARING_RESOURCE_FIELD = "#_sharing_resource_field";
};
struct RdbChangeProperties {