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.mapping;
22  
23  import org.apache.hadoop.hbase.hbql.client.HBqlException;
24  
25  import java.lang.reflect.Field;
26  import java.lang.reflect.Modifier;
27  
28  public class CurrentValueAnnotationAttrib extends FieldAttrib {
29  
30      final ColumnAttrib columnAttrib;
31  
32      public CurrentValueAnnotationAttrib(final Field field, final ColumnAttrib columnAttrib) throws HBqlException {
33  
34          super(columnAttrib.getFamilyName(),
35                columnAttrib.getColumnName(),
36                field,
37                columnAttrib.getFieldType(),
38                columnAttrib.getGetter(),
39                columnAttrib.getSetter());
40  
41          this.columnAttrib = columnAttrib;
42  
43          this.defineAccessors();
44  
45          if (isFinal(this.getField()))
46              throw new HBqlException(this + "." + this.getField().getName() + " cannot have a @Column "
47                                      + "annotation and be marked final");
48  
49          // TODO Check for type match
50  
51      }
52  
53      private ColumnAttrib getColumnAttrib() {
54          return columnAttrib;
55      }
56  
57      public boolean isAKeyAttrib() {
58          return this.getColumnAttrib().isAKeyAttrib();
59      }
60  
61      private static boolean isFinal(final Field field) {
62          return Modifier.isFinal(field.getModifiers());
63      }
64  
65      public Object getDefaultValue() throws HBqlException {
66          return this.getColumnAttrib().getDefaultValue();
67      }
68  
69      public boolean hasDefaultArg() throws HBqlException {
70          return this.getDefaultValue() != null;
71      }
72  }