1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.yaoql.impl;
22
23 import org.apache.expreval.expr.ExpressionTree;
24 import org.apache.hadoop.hbase.hbql.client.HBqlException;
25 import org.apache.hadoop.hbase.hbql.util.Maps;
26
27 import java.util.Map;
28
29 public abstract class ParameterBinding {
30
31 final Map<String, Object> parameterMap = Maps.newHashMap();
32
33 public abstract String getQuery();
34
35 public void setParameter(final String name, final Object val) {
36 this.getParameterMap().put(name, val);
37 }
38
39 protected void applyParameters(final ExpressionTree expressionTree) throws HBqlException {
40 for (final String key : this.getParameterMap().keySet()) {
41 int cnt = expressionTree.setParameter(key, this.getParameterMap().get(key));
42 if (cnt == 0)
43 throw new HBqlException("Parameter name " + key + " does not exist in " + this.getQuery());
44 }
45 }
46
47 private Map<String, Object> getParameterMap() {
48 return parameterMap;
49 }
50 }