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