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.rest;
21  
22  import java.io.IOException;
23  
24  import javax.ws.rs.Encoded;
25  import javax.ws.rs.Path;
26  import javax.ws.rs.PathParam;
27  import javax.ws.rs.QueryParam;
28  
29  import org.apache.hadoop.classification.InterfaceAudience;
30  
31  @InterfaceAudience.Private
32  public class TableResource extends ResourceBase {
33  
34    String table;
35  
36    /**
37     * Constructor
38     * @param table
39     * @throws IOException
40     */
41    public TableResource(String table) throws IOException {
42      super();
43      this.table = table;
44    }
45  
46    /** @return the table name */
47    String getName() {
48      return table;
49    }
50  
51    /**
52     * @return true if the table exists
53     * @throws IOException
54     */
55    boolean exists() throws IOException {
56      return servlet.getAdmin().tableExists(table);
57    }
58  
59    @Path("exists")
60    public ExistsResource getExistsResource() throws IOException {
61      return new ExistsResource(this);
62    }
63  
64    @Path("regions")
65    public RegionsResource getRegionsResource() throws IOException {
66      return new RegionsResource(this);
67    }
68  
69    @Path("scanner")
70    public ScannerResource getScannerResource() throws IOException {
71      return new ScannerResource(this);
72    }
73  
74    @Path("schema")
75    public SchemaResource getSchemaResource() throws IOException {
76      return new SchemaResource(this);
77    }
78  
79    @Path("multiget")
80    public MultiRowResource getMultipleRowResource(
81            final @QueryParam("v") String versions) throws IOException {
82      return new MultiRowResource(this, versions);
83    }
84  
85    @Path("{rowspec: .+}")
86    public RowResource getRowResource(
87        // We need the @Encoded decorator so Jersey won't urldecode before
88        // the RowSpec constructor has a chance to parse
89        final @PathParam("rowspec") @Encoded String rowspec,
90        final @QueryParam("v") String versions,
91        final @QueryParam("check") String check) throws IOException {
92      return new RowResource(this, rowspec, versions, check);
93    }
94  }