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