1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.statement.args;
22
23 import org.apache.expreval.expr.ArgumentListTypeSignature;
24 import org.apache.expreval.expr.ExpressionProperty;
25 import org.apache.expreval.expr.node.GenericValue;
26 import org.apache.hadoop.hbase.hbql.client.HBqlException;
27
28 import java.io.Serializable;
29 import java.util.concurrent.atomic.AtomicBoolean;
30
31 public class DefaultArg extends ExpressionProperty implements Serializable {
32
33 private static final long serialVersionUID = 1L;
34
35
36
37 private Serializable value = null;
38 private AtomicBoolean atomicComputed = new AtomicBoolean(false);
39
40 public DefaultArg(final Class<? extends GenericValue> exprType, final GenericValue expr) throws HBqlException {
41 super(new ArgumentListTypeSignature(exprType), expr);
42
43 this.validate();
44
45
46 this.getDefaultValue();
47 }
48
49 private AtomicBoolean getAtomicComputed() {
50 return this.atomicComputed;
51 }
52
53 public void reset() {
54 this.getAtomicComputed().set(false);
55 this.value = null;
56 }
57
58 public Object getDefaultValue() throws HBqlException {
59 if (!this.getAtomicComputed().get()) {
60 synchronized (this) {
61 if (!this.getAtomicComputed().get()) {
62
63 this.value = (Serializable)this.evaluateConstant(0, false);
64
65 this.getAtomicComputed().set(true);
66 }
67 }
68 }
69 return this.value;
70 }
71
72 public String asString() {
73 return this.getGenericValue(0).asString();
74 }
75 }