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.expreval.expr.betweenstmt;
22  
23  import org.apache.expreval.expr.ExpressionType;
24  import org.apache.expreval.expr.NotValue;
25  import org.apache.expreval.expr.node.BooleanValue;
26  import org.apache.expreval.expr.node.GenericValue;
27  import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
28  import org.apache.hadoop.hbase.hbql.impl.InvalidServerFilterException;
29  
30  public abstract class GenericBetweenStmt extends NotValue<GenericBetweenStmt> implements BooleanValue {
31  
32      protected GenericBetweenStmt(final ExpressionType type,
33                                   final boolean not,
34                                   final GenericValue arg0,
35                                   final GenericValue arg1,
36                                   final GenericValue arg2) {
37          super(type, not, arg0, arg1, arg2);
38      }
39  
40      public String asString() {
41          return this.getExprArg(0).asString() + notAsString() + " BETWEEN "
42                 + this.getExprArg(1).asString() + " AND " + this.getExprArg(2).asString();
43      }
44  
45      protected abstract static class GenericBetweenComparable<T> extends WritableByteArrayComparable {
46  
47          private T lowerValue;
48          private T upperValue;
49  
50          protected T getLowerValue() {
51              return this.lowerValue;
52          }
53  
54          protected T getUpperValue() {
55              return this.upperValue;
56          }
57  
58          protected void setLowerValue(final T lowerValue) {
59              this.lowerValue = lowerValue;
60          }
61  
62          protected void setUpperValue(final T upperValue) {
63              this.upperValue = upperValue;
64          }
65      }
66  
67      protected void validateArgsForBetweenFilter() throws InvalidServerFilterException {
68  
69          if (this.getExprArg(0).isAColumnReference()
70              && this.getExprArg(1).isAConstant()
71              && this.getExprArg(2).isAConstant())
72              return;
73  
74          throw new InvalidServerFilterException("Filter requires a column reference and two constants");
75      }
76  }