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