1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.expreval.expr.ifthenstmt;
22
23 import org.apache.expreval.client.NullColumnValueException;
24 import org.apache.expreval.client.ResultMissingColumnException;
25 import org.apache.expreval.expr.DelegateStmt;
26 import org.apache.expreval.expr.ExpressionType;
27 import org.apache.expreval.expr.node.GenericValue;
28 import org.apache.hadoop.hbase.hbql.client.HBqlException;
29 import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
30
31 public abstract class GenericIfThen extends DelegateStmt<GenericIfThen> {
32
33 protected GenericIfThen(final ExpressionType type,
34 final GenericValue arg0,
35 final GenericValue arg1,
36 final GenericValue arg2) {
37 super(type, arg0, arg1, arg2);
38 }
39
40 public Object getValue(final HConnectionImpl conn, final Object object) throws HBqlException,
41 ResultMissingColumnException,
42 NullColumnValueException {
43 if ((Boolean)this.getExprArg(0).getValue(conn, object))
44 return this.getExprArg(1).getValue(conn, object);
45 else
46 return this.getExprArg(2).getValue(conn, object);
47 }
48
49 public String asString() {
50 return "IF " + this.getExprArg(0).asString() + " THEN " + this.getExprArg(1).asString()
51 + " ELSE " + this.getExprArg(2).asString() + " END";
52 }
53 }