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.literal;
22  
23  import org.apache.expreval.client.InternalErrorException;
24  import org.apache.expreval.expr.MultipleExpressionContext;
25  import org.apache.expreval.expr.node.GenericValue;
26  import org.apache.hadoop.hbase.client.Result;
27  import org.apache.hadoop.hbase.filter.Filter;
28  import org.apache.hadoop.hbase.hbql.client.HBqlException;
29  import org.apache.hadoop.hbase.hbql.impl.AggregateValue;
30  import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
31  import org.apache.hadoop.hbase.hbql.impl.InvalidServerFilterException;
32  
33  import java.io.Serializable;
34  
35  public abstract class GenericLiteral<T extends Serializable> implements GenericValue {
36  
37      private final T value;
38  
39      public GenericLiteral(final T value) {
40          this.value = value;
41      }
42  
43      public T getValue(final HConnectionImpl conn, final Object object) {
44          return this.value;
45      }
46  
47      public GenericValue getOptimizedValue() throws HBqlException {
48          return this;
49      }
50  
51      public boolean isAConstant() {
52          return true;
53      }
54  
55      public boolean isDefaultKeyword() {
56          return false;
57      }
58  
59      public boolean isAnAggregateValue() {
60          return false;
61      }
62  
63      public void initAggregateValue(final AggregateValue aggregateValue) throws HBqlException {
64          throw new InternalErrorException("Not applicable");
65      }
66  
67      public void applyResultToAggregateValue(final AggregateValue aggregateValue,
68                                              final Result result) throws HBqlException {
69          throw new InternalErrorException("Not applicable");
70      }
71  
72      public boolean hasAColumnReference() {
73          return false;
74      }
75  
76      public boolean isAColumnReference() {
77          return false;
78      }
79  
80      public void reset() {
81  
82      }
83  
84      public void setExpressionContext(final MultipleExpressionContext context) {
85      }
86  
87      public Class<? extends GenericValue> validateTypes(final GenericValue parentExpr,
88                                                         final boolean allowCollections) throws HBqlException {
89          return this.getReturnType();
90      }
91  
92      protected abstract Class<? extends GenericValue> getReturnType();
93  
94      public String asString() {
95          return "" + this.getValue(null, null);
96      }
97  
98      public Filter getFilter() throws HBqlException {
99          throw new InvalidServerFilterException();
100     }
101 }