Debian Codegraph @

src/main/org/h2/expression/condition/Condition.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.function.CastSpecification;
11 import org.h2.value.TypeInfo;
12 import org.h2.value.Value;
13
14 /**
15 * Represents a condition returning a boolean value, or NULL.
16 */
17 abstract class Condition extends Expression {
18
19 /**
20 * Add a cast around the expression (if necessary) so that the type is boolean.
21 *
22 * @param session the session
23 * @param expression the expression
24 * @return the new expression
25 */
26 static Expression castToBoolean(SessionLocal session, Expression expression) {
27 if (expression.getType().getValueType() == Value.BOOLEAN) {
28 return expression;
29 }
30 return new CastSpecification(expression, TypeInfo.TYPE_BOOLEAN);
31 }
32
33 @Override
34 public TypeInfo getType() {
35 return TypeInfo.TYPE_BOOLEAN;
36 }
37
38 }