• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_OPERATION_BUILDER_H
17 #define FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_OPERATION_BUILDER_H
18 
19 #include <map>
20 #include <memory>
21 #include "data_ability_operation.h"
22 #include "uri.h"
23 #include "parcel.h"
24 
25 using Uri = OHOS::Uri;
26 namespace OHOS {
27 namespace NativeRdb {
28 class DataAbilityPredicates;
29 class ValuesBucket;
30 }
31 namespace AppExecFwk {
32 class DataAbilityOperation;
33 class DataAbilityOperationBuilder final : public std::enable_shared_from_this<DataAbilityOperationBuilder> {
34     friend class DataAbilityOperation;
35 
36 public:
37     DataAbilityOperationBuilder(const int type, const std::shared_ptr<Uri> &uri);
38     ~DataAbilityOperationBuilder();
39     /**
40      * @brief Creates a DataAbilityOperation object.
41      * @return Returns the DataAbilityOperation object.
42      */
43     std::shared_ptr<DataAbilityOperation> Build();
44     /**
45      * @brief Sets the data records to be inserted or updated.
46      * @param values Indicates the data values to be set.
47      * @return Returns a DataAbilityOperationBuilder object containing the given values parameter.
48      */
49     std::shared_ptr<DataAbilityOperationBuilder> WithValuesBucket(std::shared_ptr<NativeRdb::ValuesBucket> &values);
50     /**
51      * @brief Sets filter criteria used for deleting updating or assert query data.
52      * @param predicates Indicates the filter criteria to set. If this parameter is null, all data records will be
53      * operated by default.
54      * @return Returns an object containing the given filter criteria.
55      */
56     std::shared_ptr<DataAbilityOperationBuilder> WithPredicates(std::shared_ptr<NativeRdb::DataAbilityPredicates> &predicates);
57     /**
58      * @brief Sets the expected number of rows to update ,delete or assert query.
59      * @param count Indicates the expected number of rows to update or delete.
60      * @return Returns a DataAbilityOperationBuilder object containing the given count parameter.
61      */
62     std::shared_ptr<DataAbilityOperationBuilder> WithExpectedCount(int count);
63     /**
64      * @brief Adds a back reference to be used as a filter criterion in withPredicates(DataAbilityPredicates).
65      * @param requestArgIndex Indicates the index referencing the predicate parameter whose value is to be replaced.
66      * @param previousResult Indicates the index referencing the historical DataAbilityResult used to replace the value
67      * of the specified predicate parameter.
68      * @return Returns a DataAbilityOperationBuilder object containing the given requestArgIndex and previousResult
69      * parameters.
70      */
71     std::shared_ptr<DataAbilityOperationBuilder> WithPredicatesBackReference(int requestArgIndex, int previousResult);
72     /**
73      * @brief Adds a back reference to be used in withValuesBucket(ValuesBucket).
74      * @param backReferences Indicates the ValuesBucket object containing a set of key-value pairs. In each pair, the
75      * key specifies the value to be updated and the value specifies the index referencing the DataAbilityResult used to
76      * replace the specified value. This parameter cannot be null.
77      * @return Returns a DataAbilityOperationBuilder object containing the given backReferences parameter.
78      */
79     std::shared_ptr<DataAbilityOperationBuilder> WithValueBackReferences(std::shared_ptr<NativeRdb::ValuesBucket> &backReferences);
80     /**
81      * @brief Sets an interrupt flag bit for a batch operation, which can be insert, update, delete, or assert.
82      * @param interrupted Specifies whether a batch operation can be interrupted. The value true indicates that the
83      * operation can be interrupted, and false indicates the opposite.
84      * @return Returns a DataAbilityOperationBuilder object containing the given interrupted parameter.
85      */
86     std::shared_ptr<DataAbilityOperationBuilder> WithInterruptionAllowed(bool interrupted);
87 
88 private:
89     int type_;
90     int expectedCount_;
91     bool interrupted_;
92     std::shared_ptr<Uri> uri_;
93     std::shared_ptr<NativeRdb::ValuesBucket> valuesBucket_;
94     std::shared_ptr<NativeRdb::DataAbilityPredicates> dataAbilityPredicates_;
95     std::shared_ptr<NativeRdb::ValuesBucket> valuesBucketReferences_;
96     std::map<int, int> dataAbilityPredicatesBackReferences_;
97 };
98 }  // namespace AppExecFwk
99 }  // namespace OHOS
100 #endif  // FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_OPERATION_BUILDER_H