View Javadoc

1   /**
2    * Autogenerated by Thrift Compiler (0.9.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.thrift2.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 org.apache.thrift.protocol.TProtocolException;
16  import org.apache.thrift.EncodingUtils;
17  import org.apache.thrift.TException;
18  import java.util.List;
19  import java.util.ArrayList;
20  import java.util.Map;
21  import java.util.HashMap;
22  import java.util.EnumMap;
23  import java.util.Set;
24  import java.util.HashSet;
25  import java.util.EnumSet;
26  import java.util.Collections;
27  import java.util.BitSet;
28  import java.nio.ByteBuffer;
29  import java.util.Arrays;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  /**
34   * Used to perform Increment operations for a single row.
35   * 
36   * You can specify if this Increment should be written
37   * to the write-ahead Log (WAL) or not. It defaults to true.
38   */
39  public class TIncrement implements org.apache.thrift.TBase<TIncrement, TIncrement._Fields>, java.io.Serializable, Cloneable {
40    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TIncrement");
41  
42    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);
43    private static final org.apache.thrift.protocol.TField COLUMNS_FIELD_DESC = new org.apache.thrift.protocol.TField("columns", org.apache.thrift.protocol.TType.LIST, (short)2);
44    private static final org.apache.thrift.protocol.TField WRITE_TO_WAL_FIELD_DESC = new org.apache.thrift.protocol.TField("writeToWal", org.apache.thrift.protocol.TType.BOOL, (short)3);
45  
46    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
47    static {
48      schemes.put(StandardScheme.class, new TIncrementStandardSchemeFactory());
49      schemes.put(TupleScheme.class, new TIncrementTupleSchemeFactory());
50    }
51  
52    public ByteBuffer row; // required
53    public List<TColumnIncrement> columns; // required
54    public boolean writeToWal; // optional
55  
56    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
57    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
58      ROW((short)1, "row"),
59      COLUMNS((short)2, "columns"),
60      WRITE_TO_WAL((short)3, "writeToWal");
61  
62      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
63  
64      static {
65        for (_Fields field : EnumSet.allOf(_Fields.class)) {
66          byName.put(field.getFieldName(), field);
67        }
68      }
69  
70      /**
71       * Find the _Fields constant that matches fieldId, or null if its not found.
72       */
73      public static _Fields findByThriftId(int fieldId) {
74        switch(fieldId) {
75          case 1: // ROW
76            return ROW;
77          case 2: // COLUMNS
78            return COLUMNS;
79          case 3: // WRITE_TO_WAL
80            return WRITE_TO_WAL;
81          default:
82            return null;
83        }
84      }
85  
86      /**
87       * Find the _Fields constant that matches fieldId, throwing an exception
88       * if it is not found.
89       */
90      public static _Fields findByThriftIdOrThrow(int fieldId) {
91        _Fields fields = findByThriftId(fieldId);
92        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
93        return fields;
94      }
95  
96      /**
97       * Find the _Fields constant that matches name, or null if its not found.
98       */
99      public static _Fields findByName(String name) {
100       return byName.get(name);
101     }
102 
103     private final short _thriftId;
104     private final String _fieldName;
105 
106     _Fields(short thriftId, String fieldName) {
107       _thriftId = thriftId;
108       _fieldName = fieldName;
109     }
110 
111     public short getThriftFieldId() {
112       return _thriftId;
113     }
114 
115     public String getFieldName() {
116       return _fieldName;
117     }
118   }
119 
120   // isset id assignments
121   private static final int __WRITETOWAL_ISSET_ID = 0;
122   private byte __isset_bitfield = 0;
123   private _Fields optionals[] = {_Fields.WRITE_TO_WAL};
124   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
125   static {
126     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
127     tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.REQUIRED, 
128         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
129     tmpMap.put(_Fields.COLUMNS, new org.apache.thrift.meta_data.FieldMetaData("columns", org.apache.thrift.TFieldRequirementType.REQUIRED, 
130         new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
131             new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TColumnIncrement.class))));
132     tmpMap.put(_Fields.WRITE_TO_WAL, new org.apache.thrift.meta_data.FieldMetaData("writeToWal", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
133         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
134     metaDataMap = Collections.unmodifiableMap(tmpMap);
135     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TIncrement.class, metaDataMap);
136   }
137 
138   public TIncrement() {
139     this.writeToWal = true;
140 
141   }
142 
143   public TIncrement(
144     ByteBuffer row,
145     List<TColumnIncrement> columns)
146   {
147     this();
148     this.row = row;
149     this.columns = columns;
150   }
151 
152   /**
153    * Performs a deep copy on <i>other</i>.
154    */
155   public TIncrement(TIncrement other) {
156     __isset_bitfield = other.__isset_bitfield;
157     if (other.isSetRow()) {
158       this.row = org.apache.thrift.TBaseHelper.copyBinary(other.row);
159 ;
160     }
161     if (other.isSetColumns()) {
162       List<TColumnIncrement> __this__columns = new ArrayList<TColumnIncrement>();
163       for (TColumnIncrement other_element : other.columns) {
164         __this__columns.add(new TColumnIncrement(other_element));
165       }
166       this.columns = __this__columns;
167     }
168     this.writeToWal = other.writeToWal;
169   }
170 
171   public TIncrement deepCopy() {
172     return new TIncrement(this);
173   }
174 
175   @Override
176   public void clear() {
177     this.row = null;
178     this.columns = null;
179     this.writeToWal = true;
180 
181   }
182 
183   public byte[] getRow() {
184     setRow(org.apache.thrift.TBaseHelper.rightSize(row));
185     return row == null ? null : row.array();
186   }
187 
188   public ByteBuffer bufferForRow() {
189     return row;
190   }
191 
192   public TIncrement setRow(byte[] row) {
193     setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row));
194     return this;
195   }
196 
197   public TIncrement setRow(ByteBuffer row) {
198     this.row = row;
199     return this;
200   }
201 
202   public void unsetRow() {
203     this.row = null;
204   }
205 
206   /** Returns true if field row is set (has been assigned a value) and false otherwise */
207   public boolean isSetRow() {
208     return this.row != null;
209   }
210 
211   public void setRowIsSet(boolean value) {
212     if (!value) {
213       this.row = null;
214     }
215   }
216 
217   public int getColumnsSize() {
218     return (this.columns == null) ? 0 : this.columns.size();
219   }
220 
221   public java.util.Iterator<TColumnIncrement> getColumnsIterator() {
222     return (this.columns == null) ? null : this.columns.iterator();
223   }
224 
225   public void addToColumns(TColumnIncrement elem) {
226     if (this.columns == null) {
227       this.columns = new ArrayList<TColumnIncrement>();
228     }
229     this.columns.add(elem);
230   }
231 
232   public List<TColumnIncrement> getColumns() {
233     return this.columns;
234   }
235 
236   public TIncrement setColumns(List<TColumnIncrement> columns) {
237     this.columns = columns;
238     return this;
239   }
240 
241   public void unsetColumns() {
242     this.columns = null;
243   }
244 
245   /** Returns true if field columns is set (has been assigned a value) and false otherwise */
246   public boolean isSetColumns() {
247     return this.columns != null;
248   }
249 
250   public void setColumnsIsSet(boolean value) {
251     if (!value) {
252       this.columns = null;
253     }
254   }
255 
256   public boolean isWriteToWal() {
257     return this.writeToWal;
258   }
259 
260   public TIncrement setWriteToWal(boolean writeToWal) {
261     this.writeToWal = writeToWal;
262     setWriteToWalIsSet(true);
263     return this;
264   }
265 
266   public void unsetWriteToWal() {
267     __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __WRITETOWAL_ISSET_ID);
268   }
269 
270   /** Returns true if field writeToWal is set (has been assigned a value) and false otherwise */
271   public boolean isSetWriteToWal() {
272     return EncodingUtils.testBit(__isset_bitfield, __WRITETOWAL_ISSET_ID);
273   }
274 
275   public void setWriteToWalIsSet(boolean value) {
276     __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __WRITETOWAL_ISSET_ID, value);
277   }
278 
279   public void setFieldValue(_Fields field, Object value) {
280     switch (field) {
281     case ROW:
282       if (value == null) {
283         unsetRow();
284       } else {
285         setRow((ByteBuffer)value);
286       }
287       break;
288 
289     case COLUMNS:
290       if (value == null) {
291         unsetColumns();
292       } else {
293         setColumns((List<TColumnIncrement>)value);
294       }
295       break;
296 
297     case WRITE_TO_WAL:
298       if (value == null) {
299         unsetWriteToWal();
300       } else {
301         setWriteToWal((Boolean)value);
302       }
303       break;
304 
305     }
306   }
307 
308   public Object getFieldValue(_Fields field) {
309     switch (field) {
310     case ROW:
311       return getRow();
312 
313     case COLUMNS:
314       return getColumns();
315 
316     case WRITE_TO_WAL:
317       return Boolean.valueOf(isWriteToWal());
318 
319     }
320     throw new IllegalStateException();
321   }
322 
323   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
324   public boolean isSet(_Fields field) {
325     if (field == null) {
326       throw new IllegalArgumentException();
327     }
328 
329     switch (field) {
330     case ROW:
331       return isSetRow();
332     case COLUMNS:
333       return isSetColumns();
334     case WRITE_TO_WAL:
335       return isSetWriteToWal();
336     }
337     throw new IllegalStateException();
338   }
339 
340   @Override
341   public boolean equals(Object that) {
342     if (that == null)
343       return false;
344     if (that instanceof TIncrement)
345       return this.equals((TIncrement)that);
346     return false;
347   }
348 
349   public boolean equals(TIncrement that) {
350     if (that == null)
351       return false;
352 
353     boolean this_present_row = true && this.isSetRow();
354     boolean that_present_row = true && that.isSetRow();
355     if (this_present_row || that_present_row) {
356       if (!(this_present_row && that_present_row))
357         return false;
358       if (!this.row.equals(that.row))
359         return false;
360     }
361 
362     boolean this_present_columns = true && this.isSetColumns();
363     boolean that_present_columns = true && that.isSetColumns();
364     if (this_present_columns || that_present_columns) {
365       if (!(this_present_columns && that_present_columns))
366         return false;
367       if (!this.columns.equals(that.columns))
368         return false;
369     }
370 
371     boolean this_present_writeToWal = true && this.isSetWriteToWal();
372     boolean that_present_writeToWal = true && that.isSetWriteToWal();
373     if (this_present_writeToWal || that_present_writeToWal) {
374       if (!(this_present_writeToWal && that_present_writeToWal))
375         return false;
376       if (this.writeToWal != that.writeToWal)
377         return false;
378     }
379 
380     return true;
381   }
382 
383   @Override
384   public int hashCode() {
385     return 0;
386   }
387 
388   public int compareTo(TIncrement other) {
389     if (!getClass().equals(other.getClass())) {
390       return getClass().getName().compareTo(other.getClass().getName());
391     }
392 
393     int lastComparison = 0;
394     TIncrement typedOther = (TIncrement)other;
395 
396     lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow());
397     if (lastComparison != 0) {
398       return lastComparison;
399     }
400     if (isSetRow()) {
401       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row);
402       if (lastComparison != 0) {
403         return lastComparison;
404       }
405     }
406     lastComparison = Boolean.valueOf(isSetColumns()).compareTo(typedOther.isSetColumns());
407     if (lastComparison != 0) {
408       return lastComparison;
409     }
410     if (isSetColumns()) {
411       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.columns, typedOther.columns);
412       if (lastComparison != 0) {
413         return lastComparison;
414       }
415     }
416     lastComparison = Boolean.valueOf(isSetWriteToWal()).compareTo(typedOther.isSetWriteToWal());
417     if (lastComparison != 0) {
418       return lastComparison;
419     }
420     if (isSetWriteToWal()) {
421       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.writeToWal, typedOther.writeToWal);
422       if (lastComparison != 0) {
423         return lastComparison;
424       }
425     }
426     return 0;
427   }
428 
429   public _Fields fieldForId(int fieldId) {
430     return _Fields.findByThriftId(fieldId);
431   }
432 
433   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
434     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
435   }
436 
437   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
438     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
439   }
440 
441   @Override
442   public String toString() {
443     StringBuilder sb = new StringBuilder("TIncrement(");
444     boolean first = true;
445 
446     sb.append("row:");
447     if (this.row == null) {
448       sb.append("null");
449     } else {
450       org.apache.thrift.TBaseHelper.toString(this.row, sb);
451     }
452     first = false;
453     if (!first) sb.append(", ");
454     sb.append("columns:");
455     if (this.columns == null) {
456       sb.append("null");
457     } else {
458       sb.append(this.columns);
459     }
460     first = false;
461     if (isSetWriteToWal()) {
462       if (!first) sb.append(", ");
463       sb.append("writeToWal:");
464       sb.append(this.writeToWal);
465       first = false;
466     }
467     sb.append(")");
468     return sb.toString();
469   }
470 
471   public void validate() throws org.apache.thrift.TException {
472     // check for required fields
473     if (row == null) {
474       throw new org.apache.thrift.protocol.TProtocolException("Required field 'row' was not present! Struct: " + toString());
475     }
476     if (columns == null) {
477       throw new org.apache.thrift.protocol.TProtocolException("Required field 'columns' was not present! Struct: " + toString());
478     }
479     // check for sub-struct validity
480   }
481 
482   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
483     try {
484       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
485     } catch (org.apache.thrift.TException te) {
486       throw new java.io.IOException(te);
487     }
488   }
489 
490   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
491     try {
492       // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
493       __isset_bitfield = 0;
494       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
495     } catch (org.apache.thrift.TException te) {
496       throw new java.io.IOException(te);
497     }
498   }
499 
500   private static class TIncrementStandardSchemeFactory implements SchemeFactory {
501     public TIncrementStandardScheme getScheme() {
502       return new TIncrementStandardScheme();
503     }
504   }
505 
506   private static class TIncrementStandardScheme extends StandardScheme<TIncrement> {
507 
508     public void read(org.apache.thrift.protocol.TProtocol iprot, TIncrement struct) throws org.apache.thrift.TException {
509       org.apache.thrift.protocol.TField schemeField;
510       iprot.readStructBegin();
511       while (true)
512       {
513         schemeField = iprot.readFieldBegin();
514         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
515           break;
516         }
517         switch (schemeField.id) {
518           case 1: // ROW
519             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
520               struct.row = iprot.readBinary();
521               struct.setRowIsSet(true);
522             } else { 
523               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
524             }
525             break;
526           case 2: // COLUMNS
527             if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
528               {
529                 org.apache.thrift.protocol.TList _list32 = iprot.readListBegin();
530                 struct.columns = new ArrayList<TColumnIncrement>(_list32.size);
531                 for (int _i33 = 0; _i33 < _list32.size; ++_i33)
532                 {
533                   TColumnIncrement _elem34; // required
534                   _elem34 = new TColumnIncrement();
535                   _elem34.read(iprot);
536                   struct.columns.add(_elem34);
537                 }
538                 iprot.readListEnd();
539               }
540               struct.setColumnsIsSet(true);
541             } else { 
542               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
543             }
544             break;
545           case 3: // WRITE_TO_WAL
546             if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
547               struct.writeToWal = iprot.readBool();
548               struct.setWriteToWalIsSet(true);
549             } else { 
550               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
551             }
552             break;
553           default:
554             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
555         }
556         iprot.readFieldEnd();
557       }
558       iprot.readStructEnd();
559 
560       // check for required fields of primitive type, which can't be checked in the validate method
561       struct.validate();
562     }
563 
564     public void write(org.apache.thrift.protocol.TProtocol oprot, TIncrement struct) throws org.apache.thrift.TException {
565       struct.validate();
566 
567       oprot.writeStructBegin(STRUCT_DESC);
568       if (struct.row != null) {
569         oprot.writeFieldBegin(ROW_FIELD_DESC);
570         oprot.writeBinary(struct.row);
571         oprot.writeFieldEnd();
572       }
573       if (struct.columns != null) {
574         oprot.writeFieldBegin(COLUMNS_FIELD_DESC);
575         {
576           oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.columns.size()));
577           for (TColumnIncrement _iter35 : struct.columns)
578           {
579             _iter35.write(oprot);
580           }
581           oprot.writeListEnd();
582         }
583         oprot.writeFieldEnd();
584       }
585       if (struct.isSetWriteToWal()) {
586         oprot.writeFieldBegin(WRITE_TO_WAL_FIELD_DESC);
587         oprot.writeBool(struct.writeToWal);
588         oprot.writeFieldEnd();
589       }
590       oprot.writeFieldStop();
591       oprot.writeStructEnd();
592     }
593 
594   }
595 
596   private static class TIncrementTupleSchemeFactory implements SchemeFactory {
597     public TIncrementTupleScheme getScheme() {
598       return new TIncrementTupleScheme();
599     }
600   }
601 
602   private static class TIncrementTupleScheme extends TupleScheme<TIncrement> {
603 
604     @Override
605     public void write(org.apache.thrift.protocol.TProtocol prot, TIncrement struct) throws org.apache.thrift.TException {
606       TTupleProtocol oprot = (TTupleProtocol) prot;
607       oprot.writeBinary(struct.row);
608       {
609         oprot.writeI32(struct.columns.size());
610         for (TColumnIncrement _iter36 : struct.columns)
611         {
612           _iter36.write(oprot);
613         }
614       }
615       BitSet optionals = new BitSet();
616       if (struct.isSetWriteToWal()) {
617         optionals.set(0);
618       }
619       oprot.writeBitSet(optionals, 1);
620       if (struct.isSetWriteToWal()) {
621         oprot.writeBool(struct.writeToWal);
622       }
623     }
624 
625     @Override
626     public void read(org.apache.thrift.protocol.TProtocol prot, TIncrement struct) throws org.apache.thrift.TException {
627       TTupleProtocol iprot = (TTupleProtocol) prot;
628       struct.row = iprot.readBinary();
629       struct.setRowIsSet(true);
630       {
631         org.apache.thrift.protocol.TList _list37 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
632         struct.columns = new ArrayList<TColumnIncrement>(_list37.size);
633         for (int _i38 = 0; _i38 < _list37.size; ++_i38)
634         {
635           TColumnIncrement _elem39; // required
636           _elem39 = new TColumnIncrement();
637           _elem39.read(iprot);
638           struct.columns.add(_elem39);
639         }
640       }
641       struct.setColumnsIsSet(true);
642       BitSet incoming = iprot.readBitSet(1);
643       if (incoming.get(0)) {
644         struct.writeToWal = iprot.readBool();
645         struct.setWriteToWalIsSet(true);
646       }
647     }
648   }
649 
650 }
651