View Javadoc

1   /*
2    * Copyright (c) 2011.  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.mapping;
22  
23  import org.apache.expreval.expr.TypeSupport;
24  import org.apache.hadoop.hbase.hbql.client.ColumnVersionMap;
25  import org.apache.hadoop.hbase.hbql.client.HBqlException;
26  
27  import java.lang.reflect.Field;
28  import java.lang.reflect.ParameterizedType;
29  import java.lang.reflect.Type;
30  import java.util.Map;
31  
32  public class VersionAnnotationAttrib extends FieldAttrib {
33  
34      public VersionAnnotationAttrib(final String familyName,
35                                     final String columnName,
36                                     final Field field,
37                                     final FieldType fieldType,
38                                     final String getter,
39                                     final String setter) throws HBqlException {
40          super(familyName, columnName, field, fieldType, getter, setter);
41  
42          final ColumnVersionMap versionAnno = field.getAnnotation(ColumnVersionMap.class);
43  
44          final String annoname = "@ColumnVersionMap annotation";
45  
46          // Check if type is a Map
47          if (!TypeSupport.isParentClass(Map.class, field.getType()))
48              throw new HBqlException(getObjectQualifiedName(field) + "has a " + annoname + " so it "
49                                      + "must implement the Map interface");
50  
51          // Look up type of map value
52          final ParameterizedType ptype = (ParameterizedType)field.getGenericType();
53          final Type[] typeargs = ptype.getActualTypeArguments();
54          final Type mapValueType = typeargs[1];
55  
56          // TODO Deal with type check on mapValueType
57  
58          this.defineAccessors();
59      }
60  
61      public boolean isACurrentValue() {
62          return false;
63      }
64  
65      public boolean isAVersionValue() {
66          return true;
67      }
68  }