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