• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "firmware_component_operator.h"
17 
18 #include <memory>
19 
20 namespace OHOS {
21 namespace UpdateService {
UpdateProgressByUrl(const std::string & url,UpgradeStatus status,int32_t progress)22 bool FirmwareComponentOperator::UpdateProgressByUrl(const std::string &url, UpgradeStatus status, int32_t progress)
23 {
24     NativeRdb::ValuesBucket values;
25     values.PutInt(COLUMN_COMPONENT_STATUS, CAST_INT(status));
26     values.PutInt(COLUMN_COMPONENT_PROGRESS, progress);
27 
28     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
29     predicates.EqualTo(COLUMN_COMPONENT_DOWNLOAD_URL, url);
30     return TableBaseOperator::Update(values, predicates);
31 }
32 
UpdateStatusByUrl(const std::string & url,UpgradeStatus status)33 bool FirmwareComponentOperator::UpdateStatusByUrl(const std::string &url, UpgradeStatus status)
34 {
35     NativeRdb::ValuesBucket values;
36     values.PutInt(COLUMN_COMPONENT_STATUS, CAST_INT(status));
37 
38     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
39     predicates.EqualTo(COLUMN_COMPONENT_DOWNLOAD_URL, url);
40     return TableBaseOperator::Update(values, predicates);
41 }
42 
UpdateUrlByVersionId(const std::string & versionId,const std::string & url)43 bool FirmwareComponentOperator::UpdateUrlByVersionId(const std::string &versionId, const std::string &url)
44 {
45     NativeRdb::ValuesBucket values;
46     values.PutString(COLUMN_COMPONENT_DOWNLOAD_URL, url);
47 
48     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
49     predicates.EqualTo(COLUMN_COMPONENT_VERSION_ID, versionId);
50     return TableBaseOperator::Update(values, predicates);
51 }
52 
UpdateRecordPointByUrl(const std::string & url,int64_t recordPoint)53 bool FirmwareComponentOperator::UpdateRecordPointByUrl(const std::string &url, int64_t recordPoint)
54 {
55     NativeRdb::ValuesBucket values;
56     values.PutInt(COLUMN_COMPONENT_RECORD_POINT, recordPoint);
57 
58     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
59     predicates.EqualTo(COLUMN_COMPONENT_DOWNLOAD_URL, url);
60     return TableBaseOperator::Update(values, predicates);
61 }
62 
QueryByVersionId(const std::string & versionId,FirmwareComponent & component)63 bool FirmwareComponentOperator::QueryByVersionId(const std::string &versionId, FirmwareComponent &component)
64 {
65     std::vector<FirmwareComponent> components;
66     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
67     predicates.EqualTo(COLUMN_COMPONENT_VERSION_ID, versionId);
68     if (Query(components, predicates) && !components.empty()) {
69         component = components[0];
70         return true;
71     }
72     return false;
73 }
74 
QueryByUrl(const std::string & url,FirmwareComponent & component)75 bool FirmwareComponentOperator::QueryByUrl(const std::string &url, FirmwareComponent &component)
76 {
77     std::vector<FirmwareComponent> components;
78     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
79     predicates.EqualTo(COLUMN_COMPONENT_DOWNLOAD_URL, url);
80     if (Query(components, predicates) && !components.empty()) {
81         component = components[0];
82         return true;
83     }
84     return false;
85 }
86 } // namespace UpdateService
87 } // namespace OHOS
88