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.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.classification.InterfaceStability;
24  import org.apache.hadoop.hbase.HColumnDescriptor;
25  import org.apache.hadoop.hbase.HTableDescriptor;
26  
27  /**
28   * Read-only table descriptor.
29   */
30  @InterfaceAudience.Public
31  @InterfaceStability.Evolving
32  public class UnmodifyableHTableDescriptor extends HTableDescriptor {
33    /** Default constructor */
34    public UnmodifyableHTableDescriptor() {
35      super();
36    }
37  
38    /*
39     * Create an unmodifyable copy of an HTableDescriptor
40     * @param desc
41     */
42    UnmodifyableHTableDescriptor(final HTableDescriptor desc) {
43      super(desc.getTableName(), getUnmodifyableFamilies(desc), desc.getValues());
44    }
45  
46  
47    /*
48     * @param desc
49     * @return Families as unmodifiable array.
50     */
51    private static HColumnDescriptor[] getUnmodifyableFamilies(
52        final HTableDescriptor desc) {
53      HColumnDescriptor [] f = new HColumnDescriptor[desc.getFamilies().size()];
54      int i = 0;
55      for (HColumnDescriptor c: desc.getFamilies()) {
56        f[i++] = c;
57      }
58      return f;
59    }
60  
61    /**
62     * Does NOT add a column family. This object is immutable
63     * @param family HColumnDescriptor of familyto add.
64     */
65    @Override
66    public HTableDescriptor addFamily(final HColumnDescriptor family) {
67      throw new UnsupportedOperationException("HTableDescriptor is read-only");
68    }
69  
70    @Override
71    public HTableDescriptor modifyFamily(HColumnDescriptor family) {
72      throw new UnsupportedOperationException("HTableDescriptor is read-only");
73    }
74  
75    /**
76     * @param column
77     * @return Column descriptor for the passed family name or the family on
78     * passed in column.
79     */
80    @Override
81    public HColumnDescriptor removeFamily(final byte [] column) {
82      throw new UnsupportedOperationException("HTableDescriptor is read-only");
83    }
84  
85    /**
86     * @see org.apache.hadoop.hbase.HTableDescriptor#setReadOnly(boolean)
87     */
88    @Override
89    public HTableDescriptor setReadOnly(boolean readOnly) {
90      throw new UnsupportedOperationException("HTableDescriptor is read-only");
91    }
92  
93    /**
94     * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(byte[], byte[])
95     */
96    @Override
97    public HTableDescriptor setValue(byte[] key, byte[] value) {
98      throw new UnsupportedOperationException("HTableDescriptor is read-only");
99    }
100 
101   /**
102    * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(java.lang.String, java.lang.String)
103    */
104   @Override
105   public HTableDescriptor setValue(String key, String value) {
106     throw new UnsupportedOperationException("HTableDescriptor is read-only");
107   }
108 
109   /**
110    * @see org.apache.hadoop.hbase.HTableDescriptor#setMaxFileSize(long)
111    */
112   @Override
113   public HTableDescriptor setMaxFileSize(long maxFileSize) {
114     throw new UnsupportedOperationException("HTableDescriptor is read-only");
115   }
116 
117   /**
118    * @see org.apache.hadoop.hbase.HTableDescriptor#setMemStoreFlushSize(long)
119    */
120   @Override
121   public HTableDescriptor setMemStoreFlushSize(long memstoreFlushSize) {
122     throw new UnsupportedOperationException("HTableDescriptor is read-only");
123   }
124 
125 //  /**
126 //   * @see org.apache.hadoop.hbase.HTableDescriptor#addIndex(org.apache.hadoop.hbase.client.tableindexed.IndexSpecification)
127 //   */
128 //  @Override
129 //  public void addIndex(IndexSpecification index) {
130 //    throw new UnsupportedOperationException("HTableDescriptor is read-only");
131 //  }
132 }