View Javadoc

1   /*
2    * Copyright (c) 2010.  The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
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  }