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.model;
21  
22  import com.fasterxml.jackson.annotation.JsonProperty;
23  
24  import java.io.IOException;
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import javax.xml.bind.annotation.XmlAccessType;
30  import javax.xml.bind.annotation.XmlAccessorType;
31  import javax.xml.bind.annotation.XmlAttribute;
32  import javax.xml.bind.annotation.XmlElement;
33  import javax.xml.bind.annotation.XmlRootElement;
34  
35  import org.apache.hadoop.hbase.classification.InterfaceAudience;
36  import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
37  
38  /**
39   * Representation of a row. A row is a related set of cells, grouped by common
40   * row key. RowModels do not appear in results by themselves. They are always
41   * encapsulated within CellSetModels.
42   * 
43   * <pre>
44   * &lt;complexType name="Row"&gt;
45   *   &lt;sequence&gt;
46   *     &lt;element name="key" type="base64Binary"&gt;&lt;/element&gt;
47   *     &lt;element name="cell" type="tns:Cell" 
48   *       maxOccurs="unbounded" minOccurs="1"&gt;&lt;/element&gt;
49   *   &lt;/sequence&gt;
50   * &lt;/complexType&gt;
51   * </pre>
52   */
53  @XmlRootElement(name="Row")
54  @XmlAccessorType(XmlAccessType.FIELD)
55  @InterfaceAudience.Private
56  public class RowModel implements ProtobufMessageHandler, Serializable {
57    private static final long serialVersionUID = 1L;
58  
59    @JsonProperty("key")
60    @XmlAttribute
61    private byte[] key;
62  
63    @JsonProperty("Cell")
64    @XmlElement(name="Cell")
65    private List<CellModel> cells = new ArrayList<CellModel>();
66  
67  
68    /**
69     * Default constructor
70     */
71    public RowModel() { }
72  
73    /**
74     * Constructor
75     * @param key the row key
76     */
77    public RowModel(final String key) {
78      this(key.getBytes());
79    }
80    
81    /**
82     * Constructor
83     * @param key the row key
84     */
85    public RowModel(final byte[] key) {
86      this.key = key;
87      cells = new ArrayList<CellModel>();
88    }
89  
90    /**
91     * Constructor
92     * @param key the row key
93     * @param cells the cells
94     */
95    public RowModel(final String key, final List<CellModel> cells) {
96      this(key.getBytes(), cells);
97    }
98    
99    /**
100    * Constructor
101    * @param key the row key
102    * @param cells the cells
103    */
104   public RowModel(final byte[] key, final List<CellModel> cells) {
105     this.key = key;
106     this.cells = cells;
107   }
108   
109   /**
110    * Adds a cell to the list of cells for this row
111    * @param cell the cell
112    */
113   public void addCell(CellModel cell) {
114     cells.add(cell);
115   }
116 
117   /**
118    * @return the row key
119    */
120   public byte[] getKey() {
121     return key;
122   }
123 
124   /**
125    * @param key the row key
126    */
127   public void setKey(byte[] key) {
128     this.key = key;
129   }
130 
131   /**
132    * @return the cells
133    */
134   public List<CellModel> getCells() {
135     return cells;
136   }
137 
138   @Override
139   public byte[] createProtobufOutput() {
140     // there is no standalone row protobuf message
141     throw new UnsupportedOperationException(
142         "no protobuf equivalent to RowModel");
143   }
144 
145   @Override
146   public ProtobufMessageHandler getObjectFromMessage(byte[] message)
147       throws IOException {
148     // there is no standalone row protobuf message
149     throw new UnsupportedOperationException(
150         "no protobuf equivalent to RowModel");
151   }
152 }