View Javadoc

1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.rest;
22  
23  import java.io.IOException;
24  
25  import javax.ws.rs.Encoded;
26  import javax.ws.rs.Path;
27  import javax.ws.rs.PathParam;
28  import javax.ws.rs.QueryParam;
29  
30  public class TableResource extends ResourceBase {
31  
32    String table;
33  
34    /**
35     * Constructor
36     * @param table
37     * @throws IOException
38     */
39    public TableResource(String table) throws IOException {
40      super();
41      this.table = table;
42    }
43  
44    /** @return the table name */
45    String getName() {
46      return table;
47    }
48  
49    /**
50     * @return true if the table exists
51     * @throws IOException
52     */
53    boolean exists() throws IOException {
54      return servlet.getAdmin().tableExists(table);
55    }
56  
57    @Path("exists")
58    public ExistsResource getExistsResource() throws IOException {
59      return new ExistsResource(this);
60    }
61  
62    @Path("regions")
63    public RegionsResource getRegionsResource() throws IOException {
64      return new RegionsResource(this);
65    }
66  
67    @Path("scanner")
68    public ScannerResource getScannerResource() throws IOException {
69      return new ScannerResource(this);
70    }
71  
72    @Path("schema")
73    public SchemaResource getSchemaResource() throws IOException {
74      return new SchemaResource(this);
75    }
76  
77    @Path("multiget")
78    public MultiRowResource getMultipleRowResource(
79            final @QueryParam("v") String versions) throws IOException {
80      return new MultiRowResource(this, versions);
81    }
82  
83    @Path("{rowspec: .+}")
84    public RowResource getRowResource(
85        // We need the @Encoded decorator so Jersey won't urldecode before
86        // the RowSpec constructor has a chance to parse
87        final @PathParam("rowspec") @Encoded String rowspec,
88        final @QueryParam("v") String versions,
89        final @QueryParam("check") String check) throws IOException {
90      return new RowResource(this, rowspec, versions, check);
91    }
92  }