1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "rdb_data_ability_utils.h"
17
18 #include "raw_data_parser.h"
19 #include "result_set_utils.h"
20
21 using namespace OHOS::RdbDataAbilityAdapter;
22 using namespace OHOS::DataShare;
23 using namespace OHOS::NativeRdb;
24
RdbDataAbilityUtils()25 RdbDataAbilityUtils::RdbDataAbilityUtils()
26 {
27 }
28
~RdbDataAbilityUtils()29 RdbDataAbilityUtils::~RdbDataAbilityUtils()
30 {
31 }
32
ToDataShareValuesBucket(ValuesBucket valuesBucket)33 DataShareValuesBucket RdbDataAbilityUtils::ToDataShareValuesBucket(ValuesBucket valuesBucket)
34 {
35 std::map<std::string, DataShareValueObject::Type> values;
36 for (auto &[key, value] : valuesBucket.values_) {
37 DataShareValueObject::Type dsValue;
38 RawDataParser::Convert(std::move(value.value), dsValue);
39 values.insert(std::make_pair(key, std::move(dsValue)));
40 }
41 return DataShareValuesBucket(std::move(values));
42 }
43
ToDataSharePredicates(const DataAbilityPredicates & predicates)44 DataSharePredicates RdbDataAbilityUtils::ToDataSharePredicates(const DataAbilityPredicates &predicates)
45 {
46 DataSharePredicates dataSharePredicates;
47
48 if (predicates.IsDistinct()) {
49 dataSharePredicates.Distinct();
50 }
51 if (!predicates.GetGroup().empty()) {
52 std::vector<std::string> groups;
53 groups.push_back(predicates.GetGroup());
54 dataSharePredicates.GroupBy(groups);
55 }
56 if (!predicates.GetIndex().empty()) {
57 dataSharePredicates.IndexedBy(predicates.GetIndex());
58 }
59 if (predicates.GetLimit() != 0 || predicates.GetOffset()) {
60 dataSharePredicates.Limit(predicates.GetLimit(), predicates.GetOffset());
61 }
62
63 dataSharePredicates.SetSettingMode(QUERY_LANGUAGE);
64 dataSharePredicates.SetWhereClause(predicates.GetWhereClause());
65 dataSharePredicates.SetWhereArgs(predicates.GetWhereArgs());
66 dataSharePredicates.SetOrder(predicates.GetOrder());
67 return dataSharePredicates;
68 }
69
ToAbsSharedResultSet(std::shared_ptr<DSResultSet> resultSet)70 std::shared_ptr<AbsSharedResultSet> RdbDataAbilityUtils::ToAbsSharedResultSet(std::shared_ptr<DSResultSet> resultSet)
71 {
72 return std::make_shared<ResultSetUtils>(resultSet);
73 }
74