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