View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client;
21  
22  import org.apache.hadoop.hbase.HColumnDescriptor;
23  import org.apache.hadoop.hbase.HTableDescriptor;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.classification.InterfaceStability;
26  
27  /**
28   * Read-only table descriptor.
29   */
30  @InterfaceAudience.Public
31  @InterfaceStability.Evolving
32  public class UnmodifyableHTableDescriptor extends HTableDescriptor {
33    /**
34     * Default constructor.
35     * @deprecated  As of release 2.0.0. This will be removed in HBase 3.0.0.
36     *              Use {@link #UnmodifyableHTableDescriptor(HTableDescriptor)}.
37     */
38    @Deprecated
39    public UnmodifyableHTableDescriptor() {
40      super();
41    }
42  
43    /*
44     * Create an unmodifyable copy of an HTableDescriptor
45     * @param desc
46     */
47    UnmodifyableHTableDescriptor(final HTableDescriptor desc) {
48      super(desc.getTableName(), getUnmodifyableFamilies(desc), desc.getValues());
49    }
50  
51  
52    /*
53     * @param desc
54     * @return Families as unmodifiable array.
55     */
56    private static HColumnDescriptor[] getUnmodifyableFamilies(
57        final HTableDescriptor desc) {
58      HColumnDescriptor [] f = new HColumnDescriptor[desc.getFamilies().size()];
59      int i = 0;
60      for (HColumnDescriptor c: desc.getFamilies()) {
61        f[i++] = c;
62      }
63      return f;
64    }
65  
66    /**
67     * Does NOT add a column family. This object is immutable
68     * @param family HColumnDescriptor of familyto add.
69     */
70    @Override
71    public HTableDescriptor addFamily(final HColumnDescriptor family) {
72      throw new UnsupportedOperationException("HTableDescriptor is read-only");
73    }
74  
75    @Override
76    public HTableDescriptor modifyFamily(HColumnDescriptor family) {
77      throw new UnsupportedOperationException("HTableDescriptor is read-only");
78    }
79  
80    /**
81     * @param column
82     * @return Column descriptor for the passed family name or the family on
83     * passed in column.
84     */
85    @Override
86    public HColumnDescriptor removeFamily(final byte [] column) {
87      throw new UnsupportedOperationException("HTableDescriptor is read-only");
88    }
89  
90    /**
91     * @see org.apache.hadoop.hbase.HTableDescriptor#setReadOnly(boolean)
92     */
93    @Override
94    public HTableDescriptor setReadOnly(boolean readOnly) {
95      throw new UnsupportedOperationException("HTableDescriptor is read-only");
96    }
97  
98    /**
99     * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(byte[], byte[])
100    */
101   @Override
102   public HTableDescriptor setValue(byte[] key, byte[] value) {
103     throw new UnsupportedOperationException("HTableDescriptor is read-only");
104   }
105 
106   /**
107    * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(java.lang.String, java.lang.String)
108    */
109   @Override
110   public HTableDescriptor setValue(String key, String value) {
111     throw new UnsupportedOperationException("HTableDescriptor is read-only");
112   }
113 
114   /**
115    * @see org.apache.hadoop.hbase.HTableDescriptor#setMaxFileSize(long)
116    */
117   @Override
118   public HTableDescriptor setMaxFileSize(long maxFileSize) {
119     throw new UnsupportedOperationException("HTableDescriptor is read-only");
120   }
121 
122   /**
123    * @see org.apache.hadoop.hbase.HTableDescriptor#setMemStoreFlushSize(long)
124    */
125   @Override
126   public HTableDescriptor setMemStoreFlushSize(long memstoreFlushSize) {
127     throw new UnsupportedOperationException("HTableDescriptor is read-only");
128   }
129 }