18779efd5Sopenharmony_ci/** 28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License. 58779efd5Sopenharmony_ci * You may obtain a copy of the License at 68779efd5Sopenharmony_ci * 78779efd5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88779efd5Sopenharmony_ci * 98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and 138779efd5Sopenharmony_ci * limitations under the License. 148779efd5Sopenharmony_ci */ 158779efd5Sopenharmony_ci 168779efd5Sopenharmony_ciimport FeatureAbility from '@ohos.ability.featureAbility'; 178779efd5Sopenharmony_ci 188779efd5Sopenharmony_ciexport default class DAOperation { 198779efd5Sopenharmony_ci readonly uri: string; 208779efd5Sopenharmony_ci readonly type: number; 218779efd5Sopenharmony_ci valuesBucket?: object; 228779efd5Sopenharmony_ci valueBackReferences?: object; 238779efd5Sopenharmony_ci predicates?: object; 248779efd5Sopenharmony_ci predicatesBackReferences?: Map<number, number>; 258779efd5Sopenharmony_ci interrupted?: boolean; 268779efd5Sopenharmony_ci expectedCount?: number; 278779efd5Sopenharmony_ci constructor(uri: string, type: number) { 288779efd5Sopenharmony_ci this.uri = uri; 298779efd5Sopenharmony_ci this.type = type; 308779efd5Sopenharmony_ci } 318779efd5Sopenharmony_ci 328779efd5Sopenharmony_ci static newInsert(uri: string) { 338779efd5Sopenharmony_ci return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_INSERT) 348779efd5Sopenharmony_ci } 358779efd5Sopenharmony_ci 368779efd5Sopenharmony_ci static newDelete(uri: string) { 378779efd5Sopenharmony_ci return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_DELETE) 388779efd5Sopenharmony_ci } 398779efd5Sopenharmony_ci 408779efd5Sopenharmony_ci static newUpdate(uri: string) { 418779efd5Sopenharmony_ci return new DAOperation(uri, FeatureAbility.DataAbilityOperationType.TYPE_UPDATE) 428779efd5Sopenharmony_ci } 438779efd5Sopenharmony_ci 448779efd5Sopenharmony_ci withValueBackReferences(key: string, previousResult: number) { 458779efd5Sopenharmony_ci if (this.type != FeatureAbility.DataAbilityOperationType.TYPE_INSERT 468779efd5Sopenharmony_ci && this.type != FeatureAbility.DataAbilityOperationType.TYPE_UPDATE 478779efd5Sopenharmony_ci && this.type != FeatureAbility.DataAbilityOperationType.TYPE_ASSERT) { 488779efd5Sopenharmony_ci return; 498779efd5Sopenharmony_ci } 508779efd5Sopenharmony_ci if (this.valueBackReferences == undefined) { 518779efd5Sopenharmony_ci this.valueBackReferences = {}; 528779efd5Sopenharmony_ci } 538779efd5Sopenharmony_ci this.valueBackReferences[key] = previousResult; 548779efd5Sopenharmony_ci } 558779efd5Sopenharmony_ci 568779efd5Sopenharmony_ci withValue(key: string, obj: object) { 578779efd5Sopenharmony_ci if (this.type != FeatureAbility.DataAbilityOperationType.TYPE_INSERT 588779efd5Sopenharmony_ci && this.type != FeatureAbility.DataAbilityOperationType.TYPE_UPDATE 598779efd5Sopenharmony_ci && this.type != FeatureAbility.DataAbilityOperationType.TYPE_ASSERT) { 608779efd5Sopenharmony_ci return; 618779efd5Sopenharmony_ci } 628779efd5Sopenharmony_ci if (this.valuesBucket == undefined) { 638779efd5Sopenharmony_ci this.valuesBucket = {}; 648779efd5Sopenharmony_ci } 658779efd5Sopenharmony_ci this.valuesBucket[key] = obj; 668779efd5Sopenharmony_ci } 678779efd5Sopenharmony_ci}