View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.thrift.generated;
19  
20  import org.apache.commons.lang.builder.HashCodeBuilder;
21  import java.util.List;
22  import java.util.ArrayList;
23  import java.util.Map;
24  import java.util.HashMap;
25  import java.util.EnumMap;
26  import java.util.Set;
27  import java.util.HashSet;
28  import java.util.EnumSet;
29  import java.util.Collections;
30  import java.util.BitSet;
31  import java.util.Arrays;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  import org.apache.thrift.*;
36  import org.apache.thrift.meta_data.*;
37  import org.apache.thrift.protocol.*;
38  
39  /**
40   * A BatchMutation object is used to apply a number of Mutations to a single row.
41   */
42  public class BatchMutation implements TBase<BatchMutation._Fields>, java.io.Serializable, Cloneable, Comparable<BatchMutation> {
43    private static final TStruct STRUCT_DESC = new TStruct("BatchMutation");
44  
45    private static final TField ROW_FIELD_DESC = new TField("row", TType.STRING, (short)1);
46    private static final TField MUTATIONS_FIELD_DESC = new TField("mutations", TType.LIST, (short)2);
47  
48    public byte[] row;
49    public List<Mutation> mutations;
50  
51    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
52    public enum _Fields implements TFieldIdEnum {
53      ROW((short)1, "row"),
54      MUTATIONS((short)2, "mutations");
55  
56      private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
57      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
58  
59      static {
60        for (_Fields field : EnumSet.allOf(_Fields.class)) {
61          byId.put((int)field._thriftId, field);
62          byName.put(field.getFieldName(), field);
63        }
64      }
65  
66      /**
67       * Find the _Fields constant that matches fieldId, or null if its not found.
68       */
69      public static _Fields findByThriftId(int fieldId) {
70        return byId.get(fieldId);
71      }
72  
73      /**
74       * Find the _Fields constant that matches fieldId, throwing an exception
75       * if it is not found.
76       */
77      public static _Fields findByThriftIdOrThrow(int fieldId) {
78        _Fields fields = findByThriftId(fieldId);
79        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
80        return fields;
81      }
82  
83      /**
84       * Find the _Fields constant that matches name, or null if its not found.
85       */
86      public static _Fields findByName(String name) {
87        return byName.get(name);
88      }
89  
90      private final short _thriftId;
91      private final String _fieldName;
92  
93      _Fields(short thriftId, String fieldName) {
94        _thriftId = thriftId;
95        _fieldName = fieldName;
96      }
97  
98      public short getThriftFieldId() {
99        return _thriftId;
100     }
101 
102     public String getFieldName() {
103       return _fieldName;
104     }
105   }
106 
107   // isset id assignments
108 
109   public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
110     put(_Fields.ROW, new FieldMetaData("row", TFieldRequirementType.DEFAULT,
111         new FieldValueMetaData(TType.STRING)));
112     put(_Fields.MUTATIONS, new FieldMetaData("mutations", TFieldRequirementType.DEFAULT,
113         new ListMetaData(TType.LIST,
114             new StructMetaData(TType.STRUCT, Mutation.class))));
115   }});
116 
117   static {
118     FieldMetaData.addStructMetaDataMap(BatchMutation.class, metaDataMap);
119   }
120 
121   public BatchMutation() {
122   }
123 
124   public BatchMutation(
125     byte[] row,
126     List<Mutation> mutations)
127   {
128     this();
129     this.row = row;
130     this.mutations = mutations;
131   }
132 
133   /**
134    * Performs a deep copy on <i>other</i>.
135    */
136   public BatchMutation(BatchMutation other) {
137     if (other.isSetRow()) {
138       this.row = other.row;
139     }
140     if (other.isSetMutations()) {
141       List<Mutation> __this__mutations = new ArrayList<Mutation>();
142       for (Mutation other_element : other.mutations) {
143         __this__mutations.add(new Mutation(other_element));
144       }
145       this.mutations = __this__mutations;
146     }
147   }
148 
149   public BatchMutation deepCopy() {
150     return new BatchMutation(this);
151   }
152 
153   @Deprecated
154   public BatchMutation clone() {
155     return new BatchMutation(this);
156   }
157 
158   public byte[] getRow() {
159     return this.row;
160   }
161 
162   public BatchMutation setRow(byte[] row) {
163     this.row = row;
164     return this;
165   }
166 
167   public void unsetRow() {
168     this.row = null;
169   }
170 
171   /** Returns true if field row is set (has been asigned a value) and false otherwise */
172   public boolean isSetRow() {
173     return this.row != null;
174   }
175 
176   public void setRowIsSet(boolean value) {
177     if (!value) {
178       this.row = null;
179     }
180   }
181 
182   public int getMutationsSize() {
183     return (this.mutations == null) ? 0 : this.mutations.size();
184   }
185 
186   public java.util.Iterator<Mutation> getMutationsIterator() {
187     return (this.mutations == null) ? null : this.mutations.iterator();
188   }
189 
190   public void addToMutations(Mutation elem) {
191     if (this.mutations == null) {
192       this.mutations = new ArrayList<Mutation>();
193     }
194     this.mutations.add(elem);
195   }
196 
197   public List<Mutation> getMutations() {
198     return this.mutations;
199   }
200 
201   public BatchMutation setMutations(List<Mutation> mutations) {
202     this.mutations = mutations;
203     return this;
204   }
205 
206   public void unsetMutations() {
207     this.mutations = null;
208   }
209 
210   /** Returns true if field mutations is set (has been asigned a value) and false otherwise */
211   public boolean isSetMutations() {
212     return this.mutations != null;
213   }
214 
215   public void setMutationsIsSet(boolean value) {
216     if (!value) {
217       this.mutations = null;
218     }
219   }
220 
221   public void setFieldValue(_Fields field, Object value) {
222     switch (field) {
223     case ROW:
224       if (value == null) {
225         unsetRow();
226       } else {
227         setRow((byte[])value);
228       }
229       break;
230 
231     case MUTATIONS:
232       if (value == null) {
233         unsetMutations();
234       } else {
235         setMutations((List<Mutation>)value);
236       }
237       break;
238 
239     }
240   }
241 
242   public void setFieldValue(int fieldID, Object value) {
243     setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
244   }
245 
246   public Object getFieldValue(_Fields field) {
247     switch (field) {
248     case ROW:
249       return getRow();
250 
251     case MUTATIONS:
252       return getMutations();
253 
254     }
255     throw new IllegalStateException();
256   }
257 
258   public Object getFieldValue(int fieldId) {
259     return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
260   }
261 
262   /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
263   public boolean isSet(_Fields field) {
264     switch (field) {
265     case ROW:
266       return isSetRow();
267     case MUTATIONS:
268       return isSetMutations();
269     }
270     throw new IllegalStateException();
271   }
272 
273   public boolean isSet(int fieldID) {
274     return isSet(_Fields.findByThriftIdOrThrow(fieldID));
275   }
276 
277   @Override
278   public boolean equals(Object that) {
279     if (that == null)
280       return false;
281     if (that instanceof BatchMutation)
282       return this.equals((BatchMutation)that);
283     return false;
284   }
285 
286   public boolean equals(BatchMutation that) {
287     if (that == null)
288       return false;
289 
290     boolean this_present_row = true && this.isSetRow();
291     boolean that_present_row = true && that.isSetRow();
292     if (this_present_row || that_present_row) {
293       if (!(this_present_row && that_present_row))
294         return false;
295       if (!java.util.Arrays.equals(this.row, that.row))
296         return false;
297     }
298 
299     boolean this_present_mutations = true && this.isSetMutations();
300     boolean that_present_mutations = true && that.isSetMutations();
301     if (this_present_mutations || that_present_mutations) {
302       if (!(this_present_mutations && that_present_mutations))
303         return false;
304       if (!this.mutations.equals(that.mutations))
305         return false;
306     }
307 
308     return true;
309   }
310 
311   @Override
312   public int hashCode() {
313     HashCodeBuilder builder = new HashCodeBuilder();
314 
315     boolean present_row = true && (isSetRow());
316     builder.append(present_row);
317     if (present_row)
318       builder.append(row);
319 
320     boolean present_mutations = true && (isSetMutations());
321     builder.append(present_mutations);
322     if (present_mutations)
323       builder.append(mutations);
324 
325     return builder.toHashCode();
326   }
327 
328   public int compareTo(BatchMutation other) {
329     if (!getClass().equals(other.getClass())) {
330       return getClass().getName().compareTo(other.getClass().getName());
331     }
332 
333     int lastComparison = 0;
334     BatchMutation typedOther = (BatchMutation)other;
335 
336     lastComparison = Boolean.valueOf(isSetRow()).compareTo(isSetRow());
337     if (lastComparison != 0) {
338       return lastComparison;
339     }
340     lastComparison = TBaseHelper.compareTo(row, typedOther.row);
341     if (lastComparison != 0) {
342       return lastComparison;
343     }
344     lastComparison = Boolean.valueOf(isSetMutations()).compareTo(isSetMutations());
345     if (lastComparison != 0) {
346       return lastComparison;
347     }
348     lastComparison = TBaseHelper.compareTo(mutations, typedOther.mutations);
349     if (lastComparison != 0) {
350       return lastComparison;
351     }
352     return 0;
353   }
354 
355   public void read(TProtocol iprot) throws TException {
356     TField field;
357     iprot.readStructBegin();
358     while (true)
359     {
360       field = iprot.readFieldBegin();
361       if (field.type == TType.STOP) {
362         break;
363       }
364       _Fields fieldId = _Fields.findByThriftId(field.id);
365       if (fieldId == null) {
366         TProtocolUtil.skip(iprot, field.type);
367       } else {
368         switch (fieldId) {
369           case ROW:
370             if (field.type == TType.STRING) {
371               this.row = iprot.readBinary();
372             } else {
373               TProtocolUtil.skip(iprot, field.type);
374             }
375             break;
376           case MUTATIONS:
377             if (field.type == TType.LIST) {
378               {
379                 TList _list0 = iprot.readListBegin();
380                 this.mutations = new ArrayList<Mutation>(_list0.size);
381                 for (int _i1 = 0; _i1 < _list0.size; ++_i1)
382                 {
383                   Mutation _elem2;
384                   _elem2 = new Mutation();
385                   _elem2.read(iprot);
386                   this.mutations.add(_elem2);
387                 }
388                 iprot.readListEnd();
389               }
390             } else {
391               TProtocolUtil.skip(iprot, field.type);
392             }
393             break;
394         }
395         iprot.readFieldEnd();
396       }
397     }
398     iprot.readStructEnd();
399 
400     // check for required fields of primitive type, which can't be checked in the validate method
401     validate();
402   }
403 
404   public void write(TProtocol oprot) throws TException {
405     validate();
406 
407     oprot.writeStructBegin(STRUCT_DESC);
408     if (this.row != null) {
409       oprot.writeFieldBegin(ROW_FIELD_DESC);
410       oprot.writeBinary(this.row);
411       oprot.writeFieldEnd();
412     }
413     if (this.mutations != null) {
414       oprot.writeFieldBegin(MUTATIONS_FIELD_DESC);
415       {
416         oprot.writeListBegin(new TList(TType.STRUCT, this.mutations.size()));
417         for (Mutation _iter3 : this.mutations)
418         {
419           _iter3.write(oprot);
420         }
421         oprot.writeListEnd();
422       }
423       oprot.writeFieldEnd();
424     }
425     oprot.writeFieldStop();
426     oprot.writeStructEnd();
427   }
428 
429   @Override
430   public String toString() {
431     StringBuilder sb = new StringBuilder("BatchMutation(");
432     boolean first = true;
433 
434     sb.append("row:");
435     if (this.row == null) {
436       sb.append("null");
437     } else {
438       sb.append(this.row);
439     }
440     first = false;
441     if (!first) sb.append(", ");
442     sb.append("mutations:");
443     if (this.mutations == null) {
444       sb.append("null");
445     } else {
446       sb.append(this.mutations);
447     }
448     first = false;
449     sb.append(")");
450     return sb.toString();
451   }
452 
453   public void validate() throws TException {
454     // check for required fields
455   }
456 
457 }
458