View Javadoc

1   /**
2    * Autogenerated by Thrift Compiler (0.7.0)
3    *
4    * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5    */
6   package org.apache.hadoop.hbase.thrift.generated;
7   
8   import java.util.List;
9   import java.util.ArrayList;
10  import java.util.Map;
11  import java.util.HashMap;
12  import java.util.EnumMap;
13  import java.util.Set;
14  import java.util.HashSet;
15  import java.util.EnumSet;
16  import java.util.Collections;
17  import java.util.BitSet;
18  import java.nio.ByteBuffer;
19  import java.util.Arrays;
20  import org.slf4j.Logger;
21  import org.slf4j.LoggerFactory;
22  
23  /**
24   * A BatchMutation object is used to apply a number of Mutations to a single row.
25   */
26  public class BatchMutation implements org.apache.thrift.TBase<BatchMutation, BatchMutation._Fields>, java.io.Serializable, Cloneable {
27    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("BatchMutation");
28  
29    private static final org.apache.thrift.protocol.TField ROW_FIELD_DESC = new org.apache.thrift.protocol.TField("row", org.apache.thrift.protocol.TType.STRING, (short)1);
30    private static final org.apache.thrift.protocol.TField MUTATIONS_FIELD_DESC = new org.apache.thrift.protocol.TField("mutations", org.apache.thrift.protocol.TType.LIST, (short)2);
31  
32    public ByteBuffer row; // required
33    public List<Mutation> mutations; // required
34  
35    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
36    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
37      ROW((short)1, "row"),
38      MUTATIONS((short)2, "mutations");
39  
40      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
41  
42      static {
43        for (_Fields field : EnumSet.allOf(_Fields.class)) {
44          byName.put(field.getFieldName(), field);
45        }
46      }
47  
48      /**
49       * Find the _Fields constant that matches fieldId, or null if its not found.
50       */
51      public static _Fields findByThriftId(int fieldId) {
52        switch(fieldId) {
53          case 1: // ROW
54            return ROW;
55          case 2: // MUTATIONS
56            return MUTATIONS;
57          default:
58            return null;
59        }
60      }
61  
62      /**
63       * Find the _Fields constant that matches fieldId, throwing an exception
64       * if it is not found.
65       */
66      public static _Fields findByThriftIdOrThrow(int fieldId) {
67        _Fields fields = findByThriftId(fieldId);
68        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
69        return fields;
70      }
71  
72      /**
73       * Find the _Fields constant that matches name, or null if its not found.
74       */
75      public static _Fields findByName(String name) {
76        return byName.get(name);
77      }
78  
79      private final short _thriftId;
80      private final String _fieldName;
81  
82      _Fields(short thriftId, String fieldName) {
83        _thriftId = thriftId;
84        _fieldName = fieldName;
85      }
86  
87      public short getThriftFieldId() {
88        return _thriftId;
89      }
90  
91      public String getFieldName() {
92        return _fieldName;
93      }
94    }
95  
96    // isset id assignments
97  
98    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
99    static {
100     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
101     tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.DEFAULT, 
102         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , "Text")));
103     tmpMap.put(_Fields.MUTATIONS, new org.apache.thrift.meta_data.FieldMetaData("mutations", org.apache.thrift.TFieldRequirementType.DEFAULT, 
104         new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
105             new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Mutation.class))));
106     metaDataMap = Collections.unmodifiableMap(tmpMap);
107     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(BatchMutation.class, metaDataMap);
108   }
109 
110   public BatchMutation() {
111   }
112 
113   public BatchMutation(
114     ByteBuffer row,
115     List<Mutation> mutations)
116   {
117     this();
118     this.row = row;
119     this.mutations = mutations;
120   }
121 
122   /**
123    * Performs a deep copy on <i>other</i>.
124    */
125   public BatchMutation(BatchMutation other) {
126     if (other.isSetRow()) {
127       this.row = other.row;
128     }
129     if (other.isSetMutations()) {
130       List<Mutation> __this__mutations = new ArrayList<Mutation>();
131       for (Mutation other_element : other.mutations) {
132         __this__mutations.add(new Mutation(other_element));
133       }
134       this.mutations = __this__mutations;
135     }
136   }
137 
138   public BatchMutation deepCopy() {
139     return new BatchMutation(this);
140   }
141 
142   @Override
143   public void clear() {
144     this.row = null;
145     this.mutations = null;
146   }
147 
148   public byte[] getRow() {
149     setRow(org.apache.thrift.TBaseHelper.rightSize(row));
150     return row == null ? null : row.array();
151   }
152 
153   public ByteBuffer bufferForRow() {
154     return row;
155   }
156 
157   public BatchMutation setRow(byte[] row) {
158     setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row));
159     return this;
160   }
161 
162   public BatchMutation setRow(ByteBuffer 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 assigned 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 assigned 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((ByteBuffer)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 Object getFieldValue(_Fields field) {
243     switch (field) {
244     case ROW:
245       return getRow();
246 
247     case MUTATIONS:
248       return getMutations();
249 
250     }
251     throw new IllegalStateException();
252   }
253 
254   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
255   public boolean isSet(_Fields field) {
256     if (field == null) {
257       throw new IllegalArgumentException();
258     }
259 
260     switch (field) {
261     case ROW:
262       return isSetRow();
263     case MUTATIONS:
264       return isSetMutations();
265     }
266     throw new IllegalStateException();
267   }
268 
269   @Override
270   public boolean equals(Object that) {
271     if (that == null)
272       return false;
273     if (that instanceof BatchMutation)
274       return this.equals((BatchMutation)that);
275     return false;
276   }
277 
278   public boolean equals(BatchMutation that) {
279     if (that == null)
280       return false;
281 
282     boolean this_present_row = true && this.isSetRow();
283     boolean that_present_row = true && that.isSetRow();
284     if (this_present_row || that_present_row) {
285       if (!(this_present_row && that_present_row))
286         return false;
287       if (!this.row.equals(that.row))
288         return false;
289     }
290 
291     boolean this_present_mutations = true && this.isSetMutations();
292     boolean that_present_mutations = true && that.isSetMutations();
293     if (this_present_mutations || that_present_mutations) {
294       if (!(this_present_mutations && that_present_mutations))
295         return false;
296       if (!this.mutations.equals(that.mutations))
297         return false;
298     }
299 
300     return true;
301   }
302 
303   @Override
304   public int hashCode() {
305     return 0;
306   }
307 
308   public int compareTo(BatchMutation other) {
309     if (!getClass().equals(other.getClass())) {
310       return getClass().getName().compareTo(other.getClass().getName());
311     }
312 
313     int lastComparison = 0;
314     BatchMutation typedOther = (BatchMutation)other;
315 
316     lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow());
317     if (lastComparison != 0) {
318       return lastComparison;
319     }
320     if (isSetRow()) {
321       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row);
322       if (lastComparison != 0) {
323         return lastComparison;
324       }
325     }
326     lastComparison = Boolean.valueOf(isSetMutations()).compareTo(typedOther.isSetMutations());
327     if (lastComparison != 0) {
328       return lastComparison;
329     }
330     if (isSetMutations()) {
331       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mutations, typedOther.mutations);
332       if (lastComparison != 0) {
333         return lastComparison;
334       }
335     }
336     return 0;
337   }
338 
339   public _Fields fieldForId(int fieldId) {
340     return _Fields.findByThriftId(fieldId);
341   }
342 
343   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
344     org.apache.thrift.protocol.TField field;
345     iprot.readStructBegin();
346     while (true)
347     {
348       field = iprot.readFieldBegin();
349       if (field.type == org.apache.thrift.protocol.TType.STOP) { 
350         break;
351       }
352       switch (field.id) {
353         case 1: // ROW
354           if (field.type == org.apache.thrift.protocol.TType.STRING) {
355             this.row = iprot.readBinary();
356           } else { 
357             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
358           }
359           break;
360         case 2: // MUTATIONS
361           if (field.type == org.apache.thrift.protocol.TType.LIST) {
362             {
363               org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
364               this.mutations = new ArrayList<Mutation>(_list0.size);
365               for (int _i1 = 0; _i1 < _list0.size; ++_i1)
366               {
367                 Mutation _elem2; // required
368                 _elem2 = new Mutation();
369                 _elem2.read(iprot);
370                 this.mutations.add(_elem2);
371               }
372               iprot.readListEnd();
373             }
374           } else { 
375             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
376           }
377           break;
378         default:
379           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
380       }
381       iprot.readFieldEnd();
382     }
383     iprot.readStructEnd();
384 
385     // check for required fields of primitive type, which can't be checked in the validate method
386     validate();
387   }
388 
389   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
390     validate();
391 
392     oprot.writeStructBegin(STRUCT_DESC);
393     if (this.row != null) {
394       oprot.writeFieldBegin(ROW_FIELD_DESC);
395       oprot.writeBinary(this.row);
396       oprot.writeFieldEnd();
397     }
398     if (this.mutations != null) {
399       oprot.writeFieldBegin(MUTATIONS_FIELD_DESC);
400       {
401         oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.mutations.size()));
402         for (Mutation _iter3 : this.mutations)
403         {
404           _iter3.write(oprot);
405         }
406         oprot.writeListEnd();
407       }
408       oprot.writeFieldEnd();
409     }
410     oprot.writeFieldStop();
411     oprot.writeStructEnd();
412   }
413 
414   @Override
415   public String toString() {
416     StringBuilder sb = new StringBuilder("BatchMutation(");
417     boolean first = true;
418 
419     sb.append("row:");
420     if (this.row == null) {
421       sb.append("null");
422     } else {
423       sb.append(this.row);
424     }
425     first = false;
426     if (!first) sb.append(", ");
427     sb.append("mutations:");
428     if (this.mutations == null) {
429       sb.append("null");
430     } else {
431       sb.append(this.mutations);
432     }
433     first = false;
434     sb.append(")");
435     return sb.toString();
436   }
437 
438   public void validate() throws org.apache.thrift.TException {
439     // check for required fields
440   }
441 
442   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
443     try {
444       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
445     } catch (org.apache.thrift.TException te) {
446       throw new java.io.IOException(te);
447     }
448   }
449 
450   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
451     try {
452       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
453     } catch (org.apache.thrift.TException te) {
454       throw new java.io.IOException(te);
455     }
456   }
457 
458 }
459