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.var.NamedParameter;
24 import org.apache.hadoop.hbase.hbql.client.HBqlException;
25 import org.apache.hadoop.hbase.hbql.mapping.MappingContext;
26 import org.apache.hadoop.hbase.hbql.util.Lists;
27
28 import java.util.List;
29
30 public class KeyRangeArgs {
31
32 private final List<KeyRange> keyRangeList;
33 private final List<NamedParameter> namedParamList = Lists.newArrayList();
34
35 public KeyRangeArgs() {
36 this(null);
37 }
38
39 public KeyRangeArgs(final List<KeyRange> keyRangeList) {
40 this.keyRangeList = (keyRangeList == null) ? Lists.newArrayList(KeyRange.newAllRange()) : keyRangeList;
41 }
42
43 public List<KeyRange> getKeyRangeList() {
44 return this.keyRangeList;
45 }
46
47 public void setMappingContext(final MappingContext mappingContext) throws HBqlException {
48 for (final KeyRange keyRange : this.getKeyRangeList())
49 keyRange.setMappingContext(mappingContext);
50
51 for (final KeyRange keyRange : this.getKeyRangeList())
52 this.getParameterList().addAll(keyRange.getParameterList());
53 }
54
55 public void validate() throws HBqlException {
56 for (final KeyRange keyRange : this.getKeyRangeList())
57 keyRange.validate();
58 }
59
60 public String asString() {
61 final StringBuilder sbuf = new StringBuilder("KEYS ");
62 boolean first = true;
63 for (final KeyRange keyRange : this.getKeyRangeList()) {
64 if (!first)
65 sbuf.append(", ");
66 sbuf.append(keyRange.asString());
67 first = false;
68 }
69 return sbuf.toString();
70 }
71
72 public List<NamedParameter> getParameterList() {
73 return this.namedParamList;
74 }
75
76 public void reset() {
77 for (final KeyRange keyRange : this.getKeyRangeList())
78 keyRange.reset();
79 }
80
81 public int setParameter(final String name, final Object val) throws HBqlException {
82 int cnt = 0;
83 for (final KeyRange keyRange : this.getKeyRangeList())
84 cnt += keyRange.setParameter(name, val);
85 return cnt;
86 }
87 }