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