Debian Codegraph @

src/main/org/h2/expression/Operation2.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.expression;
7
8 import org.h2.engine.SessionLocal;
9 import org.h2.table.ColumnResolver;
10 import org.h2.table.TableFilter;
11 import org.h2.value.TypeInfo;
12
13 /**
14 * Operation with two arguments.
15 */
16 public abstract class Operation2 extends Expression {
17
18 /**
19 * The left part of the operation (the first argument).
20 */
21 protected Expression left;
22
23 /**
24 * The right part of the operation (the second argument).
25 */
26 protected Expression right;
27
28 /**
29 * The type of the result.
30 */
31 protected TypeInfo type;
32
33 protected Operation2(Expression left, Expression right) {
34 this.left = left;
35 this.right = right;
36 }
37
38 @Override
39 public TypeInfo getType() {
40 return type;
41 }
42
43 @Override
44 public void mapColumns(ColumnResolver resolver, int level, int state) {
45 left.mapColumns(resolver, level, state);
46 right.mapColumns(resolver, level, state);
47 }
48
49 @Override
50 public void setEvaluatable(TableFilter tableFilter, boolean value) {
51 left.setEvaluatable(tableFilter, value);
52 right.setEvaluatable(tableFilter, value);
53 }
54
55 @Override
56 public void updateAggregate(SessionLocal session, int stage) {
57 left.updateAggregate(session, stage);
58 right.updateAggregate(session, stage);
59 }
60
61 @Override
62 public boolean isEverything(ExpressionVisitor visitor) {
63 return left.isEverything(visitor) && right.isEverything(visitor);
64 }
65
66 @Override
67 public int getCost() {
68 return left.getCost() + right.getCost() + 1;
69 }
70
71 @Override
72 public int getSubexpressionCount() {
73 return 2;
74 }
75
76 @Override
77 public Expression getSubexpression(int index) {
78 switch (index) {
79 case 0:
80 return left;
81 case 1:
82 return right;
83 default:
84 throw new IndexOutOfBoundsException();
85 }
86 }
87
88 }