2
* Copyright 2010 The Apache Software Foundation
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
12
* http://www.apache.org/licenses/LICENSE-2.0
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.
21
package org.apache.hadoop.hbase.stargate.model;
23
import java.io.IOException;
24
import java.io.Serializable;
26
import javax.xml.bind.annotation.XmlAttribute;
27
import javax.xml.bind.annotation.XmlRootElement;
28
import javax.xml.bind.annotation.XmlType;
29
import javax.xml.bind.annotation.XmlValue;
31
import org.apache.hadoop.hbase.HConstants;
32
import org.apache.hadoop.hbase.KeyValue;
33
import org.apache.hadoop.hbase.stargate.ProtobufMessageHandler;
34
import org.apache.hadoop.hbase.stargate.protobuf.generated.CellMessage.Cell;
35
import org.apache.hadoop.hbase.util.Bytes;
37
import com.google.protobuf.ByteString;
40
* Representation of a cell. A cell is a single value associated a column and
41
* optional qualifier, and either the timestamp when it was stored or the user-
42
* provided timestamp if one was explicitly supplied.
45
* <complexType name="Cell">
47
* <element name="value" maxOccurs="1" minOccurs="1">
49
* <restriction base="base64Binary"/>
53
* <attribute name="column" type="base64Binary" />
54
* <attribute name="timestamp" type="int" />
55
* </complexType>
58
@XmlRootElement(name="Cell")
59
@XmlType(propOrder={"column","timestamp"})
60
public class CellModel implements ProtobufMessageHandler, Serializable {
61
private static final long serialVersionUID = 1L;
63
private long timestamp = HConstants.LATEST_TIMESTAMP;
64
private byte[] column;
77
public CellModel(byte[] column, byte[] value) {
78
this(column, HConstants.LATEST_TIMESTAMP, value);
87
public CellModel(byte[] column, byte[] qualifier, byte[] value) {
88
this(column, qualifier, HConstants.LATEST_TIMESTAMP, value);
92
* Constructor from KeyValue
95
public CellModel(KeyValue kv) {
96
this(kv.getFamily(), kv.getQualifier(), kv.getTimestamp(), kv.getValue());
105
public CellModel(byte[] column, long timestamp, byte[] value) {
106
this.column = column;
107
this.timestamp = timestamp;
118
public CellModel(byte[] column, byte[] qualifier, long timestamp,
120
this.column = Bytes.add(column, KeyValue.COLUMN_FAMILY_DELIM_ARRAY,
122
this.timestamp = timestamp;
130
public byte[] getColumn() {
135
* @param column the column to set
137
public void setColumn(byte[] column) {
138
this.column = column;
142
* @return true if the timestamp property has been specified by the
145
public boolean hasUserTimestamp() {
146
return timestamp != HConstants.LATEST_TIMESTAMP;
150
* @return the timestamp
153
public long getTimestamp() {
158
* @param timestamp the timestamp to set
160
public void setTimestamp(long timestamp) {
161
this.timestamp = timestamp;
168
public byte[] getValue() {
173
* @param value the value to set
175
public void setValue(byte[] value) {
180
public byte[] createProtobufOutput() {
181
Cell.Builder builder = Cell.newBuilder();
182
builder.setColumn(ByteString.copyFrom(getColumn()));
183
builder.setData(ByteString.copyFrom(getValue()));
184
if (hasUserTimestamp()) {
185
builder.setTimestamp(getTimestamp());
187
return builder.build().toByteArray();
191
public ProtobufMessageHandler getObjectFromMessage(byte[] message)
193
Cell.Builder builder = Cell.newBuilder();
194
builder.mergeFrom(message);
195
setColumn(builder.getColumn().toByteArray());
196
setValue(builder.getData().toByteArray());
197
if (builder.hasTimestamp()) {
198
setTimestamp(builder.getTimestamp());