1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.impl;
22
23 import org.apache.hadoop.hbase.hbql.client.HBqlException;
24 import org.apache.hadoop.hbase.hbql.mapping.ColumnAttrib;
25
26 import java.io.Serializable;
27 import java.util.HashMap;
28
29 public class ElementMap<T extends Value> extends HashMap<String, T> implements Serializable {
30
31 private static final long serialVersionUID = 1L;
32
33 private HRecordImpl record;
34
35 public ElementMap() {
36 }
37
38 public ElementMap(final HRecordImpl record) {
39 this.record = record;
40 }
41
42 private HRecordImpl getRecord() {
43 return this.record;
44 }
45
46 public void addElement(final T value) throws HBqlException {
47 final ColumnAttrib attrib = this.getRecord().getResultAccessor().getColumnAttribByName(value.getName());
48 final String name = (attrib == null) ? value.getName() : attrib.getFamilyQualifiedName();
49 this.put(name, value);
50 }
51
52 public boolean containsName(final String name) {
53 return this.containsKey(name);
54 }
55
56 private T getElement(final String name) {
57 return this.get(name);
58 }
59
60 public T findElement(final String name) throws HBqlException {
61
62
63
64 if (this.containsName(name))
65 return this.getElement(name);
66
67
68 final ColumnAttrib attrib = this.getRecord().getResultAccessor().getColumnAttribByName(name);
69
70 if (attrib != null) {
71 final String qualifiedName = attrib.getFamilyQualifiedName();
72 if (!qualifiedName.equals(name) && this.containsName(qualifiedName))
73 return this.getElement(qualifiedName);
74 }
75
76 return null;
77 }
78 }