001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.rest.model; 021 022import java.io.Serializable; 023import java.util.LinkedHashMap; 024import java.util.Map; 025 026import javax.xml.bind.annotation.XmlAnyAttribute; 027import javax.xml.bind.annotation.XmlAttribute; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.namespace.QName; 030 031import org.apache.yetus.audience.InterfaceAudience; 032import org.apache.hadoop.hbase.HColumnDescriptor; 033import org.apache.hadoop.hbase.HConstants; 034 035import com.fasterxml.jackson.annotation.JsonAnyGetter; 036import com.fasterxml.jackson.annotation.JsonAnySetter; 037 038/** 039 * Representation of a column family schema. 040 * 041 * <pre> 042 * <complexType name="ColumnSchema"> 043 * <attribute name="name" type="string"></attribute> 044 * <anyAttribute></anyAttribute> 045 * </complexType> 046 * </pre> 047 */ 048@XmlRootElement(name="ColumnSchema") 049@InterfaceAudience.Private 050public class ColumnSchemaModel implements Serializable { 051 private static final long serialVersionUID = 1L; 052 private static QName BLOCKCACHE = new QName(HColumnDescriptor.BLOCKCACHE); 053 private static QName BLOCKSIZE = new QName(HColumnDescriptor.BLOCKSIZE); 054 private static QName BLOOMFILTER = new QName(HColumnDescriptor.BLOOMFILTER); 055 private static QName COMPRESSION = new QName(HColumnDescriptor.COMPRESSION); 056 private static QName IN_MEMORY = new QName(HConstants.IN_MEMORY); 057 private static QName TTL = new QName(HColumnDescriptor.TTL); 058 private static QName VERSIONS = new QName(HConstants.VERSIONS); 059 060 private String name; 061 private Map<QName,Object> attrs = new LinkedHashMap<>(); 062 063 /** 064 * Default constructor 065 */ 066 public ColumnSchemaModel() {} 067 068 /** 069 * Add an attribute to the column family schema 070 * @param name the attribute name 071 * @param value the attribute value 072 */ 073 @JsonAnySetter 074 public void addAttribute(String name, Object value) { 075 attrs.put(new QName(name), value); 076 } 077 078 /** 079 * @param name the attribute name 080 * @return the attribute value 081 */ 082 public String getAttribute(String name) { 083 Object o = attrs.get(new QName(name)); 084 return o != null ? o.toString(): null; 085 } 086 087 /** 088 * @return the column name 089 */ 090 @XmlAttribute 091 public String getName() { 092 return name; 093 } 094 095 /** 096 * @return the map for holding unspecified (user) attributes 097 */ 098 @XmlAnyAttribute 099 @JsonAnyGetter 100 public Map<QName,Object> getAny() { 101 return attrs; 102 } 103 104 /** 105 * @param name the table name 106 */ 107 public void setName(String name) { 108 this.name = name; 109 } 110 111 /* (non-Javadoc) 112 * @see java.lang.Object#toString() 113 */ 114 @Override 115 public String toString() { 116 StringBuilder sb = new StringBuilder(); 117 sb.append("{ NAME => '"); 118 sb.append(name); 119 sb.append('\''); 120 for (Map.Entry<QName,Object> e: attrs.entrySet()) { 121 sb.append(", "); 122 sb.append(e.getKey().getLocalPart()); 123 sb.append(" => '"); 124 sb.append(e.getValue().toString()); 125 sb.append('\''); 126 } 127 sb.append(" }"); 128 return sb.toString(); 129 } 130 131 // getters and setters for common schema attributes 132 133 // cannot be standard bean type getters and setters, otherwise this would 134 // confuse JAXB 135 136 /** 137 * @return true if the BLOCKCACHE attribute is present and true 138 */ 139 public boolean __getBlockcache() { 140 Object o = attrs.get(BLOCKCACHE); 141 return o != null ? 142 Boolean.parseBoolean(o.toString()) : HColumnDescriptor.DEFAULT_BLOCKCACHE; 143 } 144 145 /** 146 * @return the value of the BLOCKSIZE attribute or its default if it is unset 147 */ 148 public int __getBlocksize() { 149 Object o = attrs.get(BLOCKSIZE); 150 return o != null ? 151 Integer.parseInt(o.toString()) : HColumnDescriptor.DEFAULT_BLOCKSIZE; 152 } 153 154 /** 155 * @return the value of the BLOOMFILTER attribute or its default if unset 156 */ 157 public String __getBloomfilter() { 158 Object o = attrs.get(BLOOMFILTER); 159 return o != null ? o.toString() : HColumnDescriptor.DEFAULT_BLOOMFILTER; 160 } 161 162 /** 163 * @return the value of the COMPRESSION attribute or its default if unset 164 */ 165 public String __getCompression() { 166 Object o = attrs.get(COMPRESSION); 167 return o != null ? o.toString() : HColumnDescriptor.DEFAULT_COMPRESSION; 168 } 169 170 /** 171 * @return true if the IN_MEMORY attribute is present and true 172 */ 173 public boolean __getInMemory() { 174 Object o = attrs.get(IN_MEMORY); 175 return o != null ? 176 Boolean.parseBoolean(o.toString()) : HColumnDescriptor.DEFAULT_IN_MEMORY; 177 } 178 179 /** 180 * @return the value of the TTL attribute or its default if it is unset 181 */ 182 public int __getTTL() { 183 Object o = attrs.get(TTL); 184 return o != null ? 185 Integer.parseInt(o.toString()) : HColumnDescriptor.DEFAULT_TTL; 186 } 187 188 /** 189 * @return the value of the VERSIONS attribute or its default if it is unset 190 */ 191 public int __getVersions() { 192 Object o = attrs.get(VERSIONS); 193 return o != null ? 194 Integer.parseInt(o.toString()) : HColumnDescriptor.DEFAULT_VERSIONS; 195 } 196 197 /** 198 * @param value the desired value of the BLOCKSIZE attribute 199 */ 200 public void __setBlocksize(int value) { 201 attrs.put(BLOCKSIZE, Integer.toString(value)); 202 } 203 204 /** 205 * @param value the desired value of the BLOCKCACHE attribute 206 */ 207 public void __setBlockcache(boolean value) { 208 attrs.put(BLOCKCACHE, Boolean.toString(value)); 209 } 210 211 public void __setBloomfilter(String value) { 212 attrs.put(BLOOMFILTER, value); 213 } 214 215 /** 216 * @param value the desired value of the COMPRESSION attribute 217 */ 218 public void __setCompression(String value) { 219 attrs.put(COMPRESSION, value); 220 } 221 222 /** 223 * @param value the desired value of the IN_MEMORY attribute 224 */ 225 public void __setInMemory(boolean value) { 226 attrs.put(IN_MEMORY, Boolean.toString(value)); 227 } 228 229 /** 230 * @param value the desired value of the TTL attribute 231 */ 232 public void __setTTL(int value) { 233 attrs.put(TTL, Integer.toString(value)); 234 } 235 236 /** 237 * @param value the desired value of the VERSIONS attribute 238 */ 239 public void __setVersions(int value) { 240 attrs.put(VERSIONS, Integer.toString(value)); 241 } 242}