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.mapping;
22
23 import org.apache.hadoop.hbase.HColumnDescriptor;
24 import org.apache.hadoop.hbase.hbql.client.HBqlException;
25
26 import java.util.List;
27
28 public class FamilyDefinition {
29
30 private final String familyName;
31 private final List<FamilyProperty> familyPropertyList;
32
33 private FamilyProperty maxVersions = null;
34 private FamilyProperty ttl = null;
35 private FamilyProperty blockSize = null;
36 private FamilyProperty blockCacheEnabled = null;
37 private FamilyProperty inMemoryEnabled = null;
38 private BloomFilterTypeProperty bloomFilterType = null;
39 private CompressionTypeProperty compressionType = null;
40
41 public FamilyDefinition(final String familyName, final List<FamilyProperty> familyPropertyList) {
42 this.familyName = familyName;
43 this.familyPropertyList = familyPropertyList;
44 }
45
46 public String getFamilyName() {
47 return this.familyName;
48 }
49
50 private List<FamilyProperty> getFamilyPropertyList() {
51 return this.familyPropertyList;
52 }
53
54 public HColumnDescriptor getColumnDescription() throws HBqlException {
55
56 this.validateFamilyPropertyList();
57
58 final HColumnDescriptor columnDescriptor = new HColumnDescriptor(this.getFamilyName());
59 this.assignFamilyProperties(columnDescriptor);
60 return columnDescriptor;
61 }
62
63 private void assignFamilyProperties(final HColumnDescriptor columnDesc) throws HBqlException {
64
65 if (this.maxVersions != null)
66 columnDesc.setMaxVersions(this.maxVersions.getIntegerValue());
67 if (this.ttl != null)
68 columnDesc.setTimeToLive(this.ttl.getIntegerValue());
69 if (this.blockSize != null)
70 columnDesc.setBlocksize(this.blockSize.getIntegerValue());
71 if (this.blockCacheEnabled != null)
72 columnDesc.setBlockCacheEnabled(this.blockCacheEnabled.getBooleanValue());
73 if (this.inMemoryEnabled != null)
74 columnDesc.setInMemory(this.inMemoryEnabled.getBooleanValue());
75 if (this.bloomFilterType != null)
76 columnDesc.setBloomFilterType(this.bloomFilterType.getBloomValue());
77 if (this.compressionType != null)
78 columnDesc.setCompressionType(this.compressionType.getCompressionValue());
79 }
80
81 private FamilyProperty validateProperty(final FamilyProperty assignee,
82 final FamilyProperty value) throws HBqlException {
83 if (assignee != null)
84 throw new HBqlException("Multiple " + value.getPropertyType().getDescription()
85 + " values for " + this.getFamilyName() + " not allowed");
86 return value;
87 }
88
89 private void validateFamilyPropertyList() throws HBqlException {
90
91 if (this.getFamilyPropertyList() == null)
92 return;
93
94 for (final FamilyProperty familyProperty : this.getFamilyPropertyList()) {
95
96 familyProperty.validate();
97
98 switch (familyProperty.getEnumType()) {
99
100 case MAX_VERSIONS:
101 this.maxVersions = this.validateProperty(this.maxVersions, familyProperty);
102 break;
103
104 case TTL:
105 this.ttl = this.validateProperty(this.ttl, familyProperty);
106 break;
107
108 case BLOCK_SIZE:
109 this.blockSize = this.validateProperty(this.blockSize, familyProperty);
110 break;
111
112 case BLOCK_CACHE_ENABLED:
113 this.blockCacheEnabled = this.validateProperty(this.blockCacheEnabled, familyProperty);
114 break;
115
116 case IN_MEMORY:
117 this.inMemoryEnabled = this.validateProperty(this.inMemoryEnabled, familyProperty);
118 break;
119
120 case BLOOMFILTER_TYPE:
121 this.bloomFilterType = (BloomFilterTypeProperty)this
122 .validateProperty(this.bloomFilterType, familyProperty);
123 break;
124
125 case COMPRESSION_TYPE:
126 this.compressionType = (CompressionTypeProperty)this
127 .validateProperty(this.compressionType, familyProperty);
128 break;
129 }
130 }
131 }
132 }