• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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/**
17 * @file
18 * @kit ArkData
19 */
20
21import { AsyncCallback } from './@ohos.base';
22import ExtensionContext from './application/ExtensionContext';
23import Want from './@ohos.app.ability.Want';
24import dataSharePredicates from './@ohos.data.dataSharePredicates';
25import { ValuesBucket } from './@ohos.data.ValuesBucket';
26import dataShare from './@ohos.data.dataShare';
27
28/**
29   * Struct for a batch update operation.
30   *
31   * @typedef { dataShare.UpdateOperation }
32   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
33   * @systemapi
34   * @stagemodelonly
35   * @since 12
36   */
37type UpdateOperation = dataShare.UpdateOperation;
38
39/**
40 * This module provides data sharing and expansion capabilities.
41 *
42 * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
43 * @systemapi
44 * @StageModelOnly
45 * @since 9
46 */
47export default class DataShareExtensionAbility {
48  /**
49   * Indicates datashare extension ability context.
50   *
51   * @type { ExtensionContext }
52   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
53   * @systemapi
54   * @StageModelOnly
55   * @since 10
56   */
57  context: ExtensionContext;
58
59  /**
60   * Called back when a datashare extension ability is started for initialization.
61   *
62   * @param { Want } want - Indicates connection information about the datashare extension ability.
63   * @param { AsyncCallback<void> } callback - callback function, no return value.
64   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
65   * @systemapi
66   * @StageModelOnly
67   * @since 9
68   */
69  onCreate?(want: Want, callback: AsyncCallback<void>): void;
70
71  /**
72   * Inserts a data record into the database. This method should be implemented by a data share.
73   *
74   * @param { string } uri - Indicates the position where the data is to insert.
75   * @param { ValuesBucket } valueBucket - Indicates the data to insert.
76   * @param { AsyncCallback<number> } callback - Returns the index of the newly inserted data record.
77   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
78   * @systemapi
79   * @StageModelOnly
80   * @since 9
81   */
82  insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>): void;
83
84  /**
85   * Updates one or more data records in the database. This method should be implemented by a data share.
86   *
87   * @param { string } uri - Indicates the database table storing the data to update.
88   * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is
89   *                                                               null, all data records will be updated by default.
90   * @param { ValuesBucket } valueBucket - Indicates the data to update. This parameter can be null.
91   * @param { AsyncCallback<number> } callback - Returns the number of data records updated.
92   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
93   * @systemapi
94   * @StageModelOnly
95   * @since 9
96   */
97  update?(
98    uri: string,
99    predicates: dataSharePredicates.DataSharePredicates,
100    valueBucket: ValuesBucket,
101    callback: AsyncCallback<number>
102  ): void;
103
104  /**
105   * Updates data records in the database.
106   *
107   * @param { Record<string, Array<UpdateOperation>> } operations - Indicates the data to update.
108   * @param { AsyncCallback<Record<string, Array<number>>> } callback - Callback used to return the result.
109   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
110   * @systemapi
111   * @StageModelOnly
112   * @since 12
113   */
114  batchUpdate?(
115    operations: Record<string, Array<UpdateOperation>>,
116    callback: AsyncCallback<Record<string, Array<number>>>
117  ): void;
118
119  /**
120   * Deletes one or more data records. This method should be implemented by a data share.
121   *
122   * @param { string } uri - Indicates the database table storing the data to delete.
123   * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is
124   *                                                                 null, all data records will be deleted by default.
125   * @param { AsyncCallback<number> } callback - Returns the number of data records deleted.
126   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
127   * @systemapi
128   * @StageModelOnly
129   * @since 9
130   */
131  delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>): void;
132
133  /**
134   * Queries one or more data records in the database. This method should be implemented by a data share.
135   * Only RDB and distributed KVDB resultsets are supported. The current version does not support custom resultsets.
136   *
137   * @param { string } uri - Indicates the database table storing the data to query.
138   * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is
139   *                                                                 null, all data records will be queried by default.
140   * @param { Array<string> } columns - Indicates the columns to be queried, in array, for example, {"name","age"}.
141   *                                    You should define the processing logic when this parameter is null.
142   * @param { AsyncCallback<Object> } callback - Returns the queried data, only support result set of rdb or kvstore.
143   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
144   * @systemapi
145   * @StageModelOnly
146   * @since 9
147   */
148  query?(
149    uri: string,
150    predicates: dataSharePredicates.DataSharePredicates,
151    columns: Array<string>,
152    callback: AsyncCallback<Object>
153  ): void;
154
155  /**
156   * Inserts multiple data records into the database. This method should be implemented by a data share.
157   *
158   * @param { string } uri - Indicates the position where the data is to insert.
159   * @param { Array<ValuesBucket> } valueBuckets - Indicates the data to insert.
160   * @param { AsyncCallback<number> } callback - Returns the number of data records inserted.
161   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
162   * @systemapi
163   * @StageModelOnly
164   * @since 9
165   */
166  batchInsert?(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>): void;
167
168  /**
169   * Converts the given {@code uri} that refer to the data share into a normalized URI. A normalized URI can be
170   * used across devices, persisted, backed up, and restored. It can refer to the same item in the data share
171   * even if the context has changed.
172   *
173   * @param { string } uri - Indicates the uri to normalize.
174   * @param { AsyncCallback<string> } callback - Returns the normalized uri if the data share supports URI normalization;
175   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
176   * @systemapi
177   * @StageModelOnly
178   * @since 9
179   */
180  normalizeUri?(uri: string, callback: AsyncCallback<string>): void;
181
182  /**
183   * Converts the given normalized {@code uri} generated by {@link #normalizeUri(uri)} into a denormalized one.
184   * The default implementation of this method returns the original uri passed to it.
185   *
186   * @param { string } uri - Indicates the uri to denormalize.
187   * @param { AsyncCallback<string> } callback - Returns the denormalized {@code uri} object if the denormalization is
188   *                                             successful; returns the original {@code uri} passed to this method if
189   *                                             there is nothing to do; returns {@code null} if the data identified by
190   *                                             the original {@code uri} cannot be found in the current environment.
191   * @syscap SystemCapability.DistributedDataManager.DataShare.Provider
192   * @systemapi
193   * @StageModelOnly
194   * @since 9
195   */
196  denormalizeUri?(uri: string, callback: AsyncCallback<string>): void;
197}
198