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 FeatureAbility from '@ohos.ability.featureAbility'; 17 18export default class DAOperation { 19 readonly uri: string; 20 readonly type: number; 21 valuesBucket?: object; 22 valueBackReferences?: object; 23 predicates?: object; 24 predicatesBackReferences?: Map<number, number>; 25 interrupted?: boolean; 26 expectedCount?: number; 27 constructor(uri: string, type: number) { 28 this.uri = uri; 29 this.type = type; 30 } 31 32 static newInsert(uri: string) { 33 return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_INSERT) 34 } 35 36 static newDelete(uri: string) { 37 return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_DELETE) 38 } 39 40 static newUpdate(uri: string) { 41 return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_UPDATE) 42 } 43 44 withValueBackReferences(key: string, previousResult: number) { 45 if (this.type != FeatureAbility.DataAbilityOperationType.TYPE_INSERT 46 && this.type != FeatureAbility.DataAbilityOperationType.TYPE_UPDATE 47 && this.type != FeatureAbility.DataAbilityOperationType.TYPE_ASSERT) { 48 return; 49 } 50 if (this.valueBackReferences == undefined) { 51 this.valueBackReferences = {}; 52 } 53 this.valueBackReferences[key] = previousResult; 54 } 55 56 withValue(key: string, obj: object) { 57 if (this.type != FeatureAbility.DataAbilityOperationType.TYPE_INSERT 58 && this.type != FeatureAbility.DataAbilityOperationType.TYPE_UPDATE 59 && this.type != FeatureAbility.DataAbilityOperationType.TYPE_ASSERT) { 60 return; 61 } 62 if (this.valuesBucket == undefined) { 63 this.valuesBucket = {}; 64 } 65 this.valuesBucket[key] = obj; 66 } 67}