View Javadoc

1   /**
2    * Autogenerated by Thrift Compiler (0.8.0)
3    *
4    * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5    *  @generated
6    */
7   package org.apache.hadoop.hbase.thrift.generated;
8   
9   import org.apache.thrift.scheme.IScheme;
10  import org.apache.thrift.scheme.SchemeFactory;
11  import org.apache.thrift.scheme.StandardScheme;
12  
13  import org.apache.thrift.scheme.TupleScheme;
14  import org.apache.thrift.protocol.TTupleProtocol;
15  import java.util.List;
16  import java.util.ArrayList;
17  import java.util.Map;
18  import java.util.HashMap;
19  import java.util.EnumMap;
20  import java.util.Set;
21  import java.util.HashSet;
22  import java.util.EnumSet;
23  import java.util.Collections;
24  import java.util.BitSet;
25  import java.nio.ByteBuffer;
26  import java.util.Arrays;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /**
31   * A BatchMutation object is used to apply a number of Mutations to a single row.
32   */
33  public class BatchMutation implements org.apache.thrift.TBase<BatchMutation, BatchMutation._Fields>, java.io.Serializable, Cloneable {
34    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("BatchMutation");
35  
36    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);
37    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);
38  
39    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
40    static {
41      schemes.put(StandardScheme.class, new BatchMutationStandardSchemeFactory());
42      schemes.put(TupleScheme.class, new BatchMutationTupleSchemeFactory());
43    }
44  
45    public ByteBuffer row; // required
46    public List<Mutation> mutations; // required
47  
48    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
49    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
50      ROW((short)1, "row"),
51      MUTATIONS((short)2, "mutations");
52  
53      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
54  
55      static {
56        for (_Fields field : EnumSet.allOf(_Fields.class)) {
57          byName.put(field.getFieldName(), field);
58        }
59      }
60  
61      /**
62       * Find the _Fields constant that matches fieldId, or null if its not found.
63       */
64      public static _Fields findByThriftId(int fieldId) {
65        switch(fieldId) {
66          case 1: // ROW
67            return ROW;
68          case 2: // MUTATIONS
69            return MUTATIONS;
70          default:
71            return null;
72        }
73      }
74  
75      /**
76       * Find the _Fields constant that matches fieldId, throwing an exception
77       * if it is not found.
78       */
79      public static _Fields findByThriftIdOrThrow(int fieldId) {
80        _Fields fields = findByThriftId(fieldId);
81        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
82        return fields;
83      }
84  
85      /**
86       * Find the _Fields constant that matches name, or null if its not found.
87       */
88      public static _Fields findByName(String name) {
89        return byName.get(name);
90      }
91  
92      private final short _thriftId;
93      private final String _fieldName;
94  
95      _Fields(short thriftId, String fieldName) {
96        _thriftId = thriftId;
97        _fieldName = fieldName;
98      }
99  
100     public short getThriftFieldId() {
101       return _thriftId;
102     }
103 
104     public String getFieldName() {
105       return _fieldName;
106     }
107   }
108 
109   // isset id assignments
110   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
111   static {
112     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
113     tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.DEFAULT, 
114         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , "Text")));
115     tmpMap.put(_Fields.MUTATIONS, new org.apache.thrift.meta_data.FieldMetaData("mutations", org.apache.thrift.TFieldRequirementType.DEFAULT, 
116         new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
117             new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Mutation.class))));
118     metaDataMap = Collections.unmodifiableMap(tmpMap);
119     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(BatchMutation.class, metaDataMap);
120   }
121 
122   public BatchMutation() {
123   }
124 
125   public BatchMutation(
126     ByteBuffer row,
127     List<Mutation> mutations)
128   {
129     this();
130     this.row = row;
131     this.mutations = mutations;
132   }
133 
134   /**
135    * Performs a deep copy on <i>other</i>.
136    */
137   public BatchMutation(BatchMutation other) {
138     if (other.isSetRow()) {
139       this.row = other.row;
140     }
141     if (other.isSetMutations()) {
142       List<Mutation> __this__mutations = new ArrayList<Mutation>();
143       for (Mutation other_element : other.mutations) {
144         __this__mutations.add(new Mutation(other_element));
145       }
146       this.mutations = __this__mutations;
147     }
148   }
149 
150   public BatchMutation deepCopy() {
151     return new BatchMutation(this);
152   }
153 
154   @Override
155   public void clear() {
156     this.row = null;
157     this.mutations = null;
158   }
159 
160   public byte[] getRow() {
161     setRow(org.apache.thrift.TBaseHelper.rightSize(row));
162     return row == null ? null : row.array();
163   }
164 
165   public ByteBuffer bufferForRow() {
166     return row;
167   }
168 
169   public BatchMutation setRow(byte[] row) {
170     setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row));
171     return this;
172   }
173 
174   public BatchMutation setRow(ByteBuffer row) {
175     this.row = row;
176     return this;
177   }
178 
179   public void unsetRow() {
180     this.row = null;
181   }
182 
183   /** Returns true if field row is set (has been assigned a value) and false otherwise */
184   public boolean isSetRow() {
185     return this.row != null;
186   }
187 
188   public void setRowIsSet(boolean value) {
189     if (!value) {
190       this.row = null;
191     }
192   }
193 
194   public int getMutationsSize() {
195     return (this.mutations == null) ? 0 : this.mutations.size();
196   }
197 
198   public java.util.Iterator<Mutation> getMutationsIterator() {
199     return (this.mutations == null) ? null : this.mutations.iterator();
200   }
201 
202   public void addToMutations(Mutation elem) {
203     if (this.mutations == null) {
204       this.mutations = new ArrayList<Mutation>();
205     }
206     this.mutations.add(elem);
207   }
208 
209   public List<Mutation> getMutations() {
210     return this.mutations;
211   }
212 
213   public BatchMutation setMutations(List<Mutation> mutations) {
214     this.mutations = mutations;
215     return this;
216   }
217 
218   public void unsetMutations() {
219     this.mutations = null;
220   }
221 
222   /** Returns true if field mutations is set (has been assigned a value) and false otherwise */
223   public boolean isSetMutations() {
224     return this.mutations != null;
225   }
226 
227   public void setMutationsIsSet(boolean value) {
228     if (!value) {
229       this.mutations = null;
230     }
231   }
232 
233   public void setFieldValue(_Fields field, Object value) {
234     switch (field) {
235     case ROW:
236       if (value == null) {
237         unsetRow();
238       } else {
239         setRow((ByteBuffer)value);
240       }
241       break;
242 
243     case MUTATIONS:
244       if (value == null) {
245         unsetMutations();
246       } else {
247         setMutations((List<Mutation>)value);
248       }
249       break;
250 
251     }
252   }
253 
254   public Object getFieldValue(_Fields field) {
255     switch (field) {
256     case ROW:
257       return getRow();
258 
259     case MUTATIONS:
260       return getMutations();
261 
262     }
263     throw new IllegalStateException();
264   }
265 
266   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
267   public boolean isSet(_Fields field) {
268     if (field == null) {
269       throw new IllegalArgumentException();
270     }
271 
272     switch (field) {
273     case ROW:
274       return isSetRow();
275     case MUTATIONS:
276       return isSetMutations();
277     }
278     throw new IllegalStateException();
279   }
280 
281   @Override
282   public boolean equals(Object that) {
283     if (that == null)
284       return false;
285     if (that instanceof BatchMutation)
286       return this.equals((BatchMutation)that);
287     return false;
288   }
289 
290   public boolean equals(BatchMutation that) {
291     if (that == null)
292       return false;
293 
294     boolean this_present_row = true && this.isSetRow();
295     boolean that_present_row = true && that.isSetRow();
296     if (this_present_row || that_present_row) {
297       if (!(this_present_row && that_present_row))
298         return false;
299       if (!this.row.equals(that.row))
300         return false;
301     }
302 
303     boolean this_present_mutations = true && this.isSetMutations();
304     boolean that_present_mutations = true && that.isSetMutations();
305     if (this_present_mutations || that_present_mutations) {
306       if (!(this_present_mutations && that_present_mutations))
307         return false;
308       if (!this.mutations.equals(that.mutations))
309         return false;
310     }
311 
312     return true;
313   }
314 
315   @Override
316   public int hashCode() {
317     return 0;
318   }
319 
320   public int compareTo(BatchMutation other) {
321     if (!getClass().equals(other.getClass())) {
322       return getClass().getName().compareTo(other.getClass().getName());
323     }
324 
325     int lastComparison = 0;
326     BatchMutation typedOther = (BatchMutation)other;
327 
328     lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow());
329     if (lastComparison != 0) {
330       return lastComparison;
331     }
332     if (isSetRow()) {
333       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row);
334       if (lastComparison != 0) {
335         return lastComparison;
336       }
337     }
338     lastComparison = Boolean.valueOf(isSetMutations()).compareTo(typedOther.isSetMutations());
339     if (lastComparison != 0) {
340       return lastComparison;
341     }
342     if (isSetMutations()) {
343       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mutations, typedOther.mutations);
344       if (lastComparison != 0) {
345         return lastComparison;
346       }
347     }
348     return 0;
349   }
350 
351   public _Fields fieldForId(int fieldId) {
352     return _Fields.findByThriftId(fieldId);
353   }
354 
355   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
356     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
357   }
358 
359   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
360     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
361   }
362 
363   @Override
364   public String toString() {
365     StringBuilder sb = new StringBuilder("BatchMutation(");
366     boolean first = true;
367 
368     sb.append("row:");
369     if (this.row == null) {
370       sb.append("null");
371     } else {
372       sb.append(this.row);
373     }
374     first = false;
375     if (!first) sb.append(", ");
376     sb.append("mutations:");
377     if (this.mutations == null) {
378       sb.append("null");
379     } else {
380       sb.append(this.mutations);
381     }
382     first = false;
383     sb.append(")");
384     return sb.toString();
385   }
386 
387   public void validate() throws org.apache.thrift.TException {
388     // check for required fields
389   }
390 
391   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
392     try {
393       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
394     } catch (org.apache.thrift.TException te) {
395       throw new java.io.IOException(te);
396     }
397   }
398 
399   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
400     try {
401       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
402     } catch (org.apache.thrift.TException te) {
403       throw new java.io.IOException(te);
404     }
405   }
406 
407   private static class BatchMutationStandardSchemeFactory implements SchemeFactory {
408     public BatchMutationStandardScheme getScheme() {
409       return new BatchMutationStandardScheme();
410     }
411   }
412 
413   private static class BatchMutationStandardScheme extends StandardScheme<BatchMutation> {
414 
415     public void read(org.apache.thrift.protocol.TProtocol iprot, BatchMutation struct) throws org.apache.thrift.TException {
416       org.apache.thrift.protocol.TField schemeField;
417       iprot.readStructBegin();
418       while (true)
419       {
420         schemeField = iprot.readFieldBegin();
421         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
422           break;
423         }
424         switch (schemeField.id) {
425           case 1: // ROW
426             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
427               struct.row = iprot.readBinary();
428               struct.setRowIsSet(true);
429             } else { 
430               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
431             }
432             break;
433           case 2: // MUTATIONS
434             if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
435               {
436                 org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
437                 struct.mutations = new ArrayList<Mutation>(_list0.size);
438                 for (int _i1 = 0; _i1 < _list0.size; ++_i1)
439                 {
440                   Mutation _elem2; // optional
441                   _elem2 = new Mutation();
442                   _elem2.read(iprot);
443                   struct.mutations.add(_elem2);
444                 }
445                 iprot.readListEnd();
446               }
447               struct.setMutationsIsSet(true);
448             } else { 
449               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
450             }
451             break;
452           default:
453             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
454         }
455         iprot.readFieldEnd();
456       }
457       iprot.readStructEnd();
458 
459       // check for required fields of primitive type, which can't be checked in the validate method
460       struct.validate();
461     }
462 
463     public void write(org.apache.thrift.protocol.TProtocol oprot, BatchMutation struct) throws org.apache.thrift.TException {
464       struct.validate();
465 
466       oprot.writeStructBegin(STRUCT_DESC);
467       if (struct.row != null) {
468         oprot.writeFieldBegin(ROW_FIELD_DESC);
469         oprot.writeBinary(struct.row);
470         oprot.writeFieldEnd();
471       }
472       if (struct.mutations != null) {
473         oprot.writeFieldBegin(MUTATIONS_FIELD_DESC);
474         {
475           oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.mutations.size()));
476           for (Mutation _iter3 : struct.mutations)
477           {
478             _iter3.write(oprot);
479           }
480           oprot.writeListEnd();
481         }
482         oprot.writeFieldEnd();
483       }
484       oprot.writeFieldStop();
485       oprot.writeStructEnd();
486     }
487 
488   }
489 
490   private static class BatchMutationTupleSchemeFactory implements SchemeFactory {
491     public BatchMutationTupleScheme getScheme() {
492       return new BatchMutationTupleScheme();
493     }
494   }
495 
496   private static class BatchMutationTupleScheme extends TupleScheme<BatchMutation> {
497 
498     @Override
499     public void write(org.apache.thrift.protocol.TProtocol prot, BatchMutation struct) throws org.apache.thrift.TException {
500       TTupleProtocol oprot = (TTupleProtocol) prot;
501       BitSet optionals = new BitSet();
502       if (struct.isSetRow()) {
503         optionals.set(0);
504       }
505       if (struct.isSetMutations()) {
506         optionals.set(1);
507       }
508       oprot.writeBitSet(optionals, 2);
509       if (struct.isSetRow()) {
510         oprot.writeBinary(struct.row);
511       }
512       if (struct.isSetMutations()) {
513         {
514           oprot.writeI32(struct.mutations.size());
515           for (Mutation _iter4 : struct.mutations)
516           {
517             _iter4.write(oprot);
518           }
519         }
520       }
521     }
522 
523     @Override
524     public void read(org.apache.thrift.protocol.TProtocol prot, BatchMutation struct) throws org.apache.thrift.TException {
525       TTupleProtocol iprot = (TTupleProtocol) prot;
526       BitSet incoming = iprot.readBitSet(2);
527       if (incoming.get(0)) {
528         struct.row = iprot.readBinary();
529         struct.setRowIsSet(true);
530       }
531       if (incoming.get(1)) {
532         {
533           org.apache.thrift.protocol.TList _list5 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
534           struct.mutations = new ArrayList<Mutation>(_list5.size);
535           for (int _i6 = 0; _i6 < _list5.size; ++_i6)
536           {
537             Mutation _elem7; // optional
538             _elem7 = new Mutation();
539             _elem7.read(iprot);
540             struct.mutations.add(_elem7);
541           }
542         }
543         struct.setMutationsIsSet(true);
544       }
545     }
546   }
547 
548 }
549