Debian Codegraph @

src/main/org/h2/expression/condition/SimplePredicate.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.condition;
7
8 import org.h2.engine.SessionLocal;
9 import org.h2.expression.Expression;
10 import org.h2.expression.ExpressionVisitor;
11 import org.h2.expression.ValueExpression;
12 import org.h2.table.ColumnResolver;
13 import org.h2.table.TableFilter;
14
15 /**
16 * Base class for simple predicates.
17 */
18 public abstract class SimplePredicate extends Condition {
19
20 /**
21 * The left hand side of the expression.
22 */
23 Expression left;
24
25 /**
26 * Whether it is a "not" condition (e.g. "is not null").
27 */
28 final boolean not;
29
30 /**
31 * Where this is the when operand of the simple case.
32 */
33 final boolean whenOperand;
34
35 SimplePredicate(Expression left, boolean not, boolean whenOperand) {
36 this.left = left;
37 this.not = not;
38 this.whenOperand = whenOperand;
39 }
40
41 @Override
42 public Expression optimize(SessionLocal session) {
43 left = left.optimize(session);
44 if (!whenOperand && left.isConstant()) {
45 return ValueExpression.getBoolean(getValue(session));
46 }
47 return this;
48 }
49
50 @Override
51 public void setEvaluatable(TableFilter tableFilter, boolean b) {
52 left.setEvaluatable(tableFilter, b);
53 }
54
55 @Override
56 public final boolean needParentheses() {
57 return true;
58 }
59
60 @Override
61 public void updateAggregate(SessionLocal session, int stage) {
62 left.updateAggregate(session, stage);
63 }
64
65 @Override
66 public void mapColumns(ColumnResolver resolver, int level, int state) {
67 left.mapColumns(resolver, level, state);
68 }
69
70 @Override
71 public boolean isEverything(ExpressionVisitor visitor) {
72 return left.isEverything(visitor);
73 }
74
75 @Override
76 public int getCost() {
77 return left.getCost() + 1;
78 }
79
80 @Override
81 public int getSubexpressionCount() {
82 return 1;
83 }
84
85 @Override
86 public Expression getSubexpression(int index) {
87 if (index == 0) {
88 return left;
89 }
90 throw new IndexOutOfBoundsException();
91 }
92
93 @Override
94 public final boolean isWhenConditionOperand() {
95 return whenOperand;
96 }
97
98 }