Beispiel #1
0
  public boolean equals(SliceRange that) {
    if (that == null) return false;

    boolean this_present_start = true && this.isSetStart();
    boolean that_present_start = true && that.isSetStart();
    if (this_present_start || that_present_start) {
      if (!(this_present_start && that_present_start)) return false;
      if (!java.util.Arrays.equals(this.start, that.start)) return false;
    }

    boolean this_present_finish = true && this.isSetFinish();
    boolean that_present_finish = true && that.isSetFinish();
    if (this_present_finish || that_present_finish) {
      if (!(this_present_finish && that_present_finish)) return false;
      if (!java.util.Arrays.equals(this.finish, that.finish)) return false;
    }

    boolean this_present_reversed = true;
    boolean that_present_reversed = true;
    if (this_present_reversed || that_present_reversed) {
      if (!(this_present_reversed && that_present_reversed)) return false;
      if (this.reversed != that.reversed) return false;
    }

    boolean this_present_count = true;
    boolean that_present_count = true;
    if (this_present_count || that_present_count) {
      if (!(this_present_count && that_present_count)) return false;
      if (this.count != that.count) return false;
    }

    return true;
  }
 private SlicePredicate predicateWithCount(int count) {
   SliceRange range = new SliceRange();
   range.setStart("".getBytes());
   range.setFinish("".getBytes());
   range.setCount(count);
   SlicePredicate predicate = new SlicePredicate();
   predicate.setSlice_range(range);
   return predicate;
 }
Beispiel #3
0
 /** Performs a deep copy on <i>other</i>. */
 public SliceRange(SliceRange other) {
   __isset_bitfield = other.__isset_bitfield;
   if (other.isSetStart()) {
     this.start = org.apache.thrift.TBaseHelper.copyBinary(other.start);
     ;
   }
   if (other.isSetFinish()) {
     this.finish = org.apache.thrift.TBaseHelper.copyBinary(other.finish);
     ;
   }
   this.reversed = other.reversed;
   this.count = other.count;
 }
Beispiel #4
0
 /** Performs a deep copy on <i>other</i>. */
 public SliceRange(SliceRange other) {
   __isset_bit_vector.clear();
   __isset_bit_vector.or(other.__isset_bit_vector);
   if (other.isSetStart()) {
     this.start = new byte[other.start.length];
     System.arraycopy(other.start, 0, start, 0, other.start.length);
   }
   if (other.isSetFinish()) {
     this.finish = new byte[other.finish.length];
     System.arraycopy(other.finish, 0, finish, 0, other.finish.length);
   }
   this.reversed = other.reversed;
   this.count = other.count;
 }
Beispiel #5
0
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, SliceRange struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   struct.start = iprot.readBinary();
   struct.setStartIsSet(true);
   struct.finish = iprot.readBinary();
   struct.setFinishIsSet(true);
   struct.reversed = iprot.readBool();
   struct.setReversedIsSet(true);
   struct.count = iprot.readI32();
   struct.setCountIsSet(true);
 }
	public static void main(String[] args) throws UnsupportedEncodingException,
	InvalidRequestException, UnavailableException, TimedOutException,
	TException, NotFoundException {

		TTransport tr = new TSocket(“192.168.1.204″, 9160);
		TProtocol proto = new TBinaryProtocol(tr);
		Cassandra.Client client = new Cassandra.Client(proto);

		tr.open();

		String keyspace = “Historical_Info”;
		String columnFamily = “Historical_Info_Column”;
		//String keyUserID = “3”;

		// read entire row
		SlicePredicate predicate = new SlicePredicate();
		SliceRange sliceRange = new SliceRange();
		sliceRange.setStart(new byte[0]);
		sliceRange.setFinish(new byte[0]);
		predicate.setSlice_range(sliceRange);

		KeyRange keyrRange = new KeyRange();
		keyrRange.setStart_key(“1″);
		keyrRange.setEnd_key(“”);
		//keyrRange.setCount(100);

		ColumnParent parent = new ColumnParent(columnFamily);

		List < KeySlice > ls = client.get_range_slices(keyspace, parent, predicate, keyrRange, ConsistencyLevel.ONE);

		for (KeySlice result: ls) {
			List < ColumnOrSuperColumn > column = result.columns;
			for (ColumnOrSuperColumn result2: column) {
				Column column2 = result2.column;
				System.out.println(new String(column2.name, UTF8) + ” - > ” + new String(column2.value, UTF8));
			}
		}

		tr.close();
	}
Beispiel #7
0
  public int compareTo(SliceRange other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;
    SliceRange typedOther = (SliceRange) other;

    lastComparison = Boolean.valueOf(isSetStart()).compareTo(typedOther.isSetStart());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStart()) {
      lastComparison = TBaseHelper.compareTo(this.start, typedOther.start);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetFinish()).compareTo(typedOther.isSetFinish());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetFinish()) {
      lastComparison = TBaseHelper.compareTo(this.finish, typedOther.finish);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetReversed()).compareTo(typedOther.isSetReversed());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetReversed()) {
      lastComparison = TBaseHelper.compareTo(this.reversed, typedOther.reversed);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetCount()).compareTo(typedOther.isSetCount());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetCount()) {
      lastComparison = TBaseHelper.compareTo(this.count, typedOther.count);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }
Beispiel #8
0
  @Override
  public int compareTo(SliceRange other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetStart()).compareTo(other.isSetStart());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStart()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.start, other.start);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetFinish()).compareTo(other.isSetFinish());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetFinish()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.finish, other.finish);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetReversed()).compareTo(other.isSetReversed());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetReversed()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reversed, other.reversed);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetCount()).compareTo(other.isSetCount());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetCount()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.count, other.count);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }
  public static void validateRange(String keyspace, ColumnParent column_parent, SliceRange range)
      throws InvalidRequestException {
    AbstractType comparator =
        ColumnFamily.getComparatorFor(
            keyspace, column_parent.column_family, column_parent.super_column);
    try {
      comparator.validate(range.start);
      comparator.validate(range.finish);
    } catch (MarshalException e) {
      throw new InvalidRequestException(e.getMessage());
    }

    if (range.count < 0) throw new InvalidRequestException("get_slice requires non-negative count");

    Comparator<ByteBuffer> orderedComparator =
        range.isReversed() ? comparator.getReverseComparator() : comparator;
    if (range.start.remaining() > 0
        && range.finish.remaining() > 0
        && orderedComparator.compare(range.start, range.finish) > 0) {
      throw new InvalidRequestException(
          "range finish must come after start in the order of traversal");
    }
  }
Beispiel #10
0
    public void write(org.apache.thrift.protocol.TProtocol oprot, SliceRange struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.start != null) {
        oprot.writeFieldBegin(START_FIELD_DESC);
        oprot.writeBinary(struct.start);
        oprot.writeFieldEnd();
      }
      if (struct.finish != null) {
        oprot.writeFieldBegin(FINISH_FIELD_DESC);
        oprot.writeBinary(struct.finish);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(REVERSED_FIELD_DESC);
      oprot.writeBool(struct.reversed);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(COUNT_FIELD_DESC);
      oprot.writeI32(struct.count);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
Beispiel #11
0
    public void read(org.apache.thrift.protocol.TProtocol iprot, SliceRange struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // START
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.start = iprot.readBinary();
              struct.setStartIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // FINISH
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.finish = iprot.readBinary();
              struct.setFinishIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // REVERSED
            if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
              struct.reversed = iprot.readBool();
              struct.setReversedIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // COUNT
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.count = iprot.readI32();
              struct.setCountIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      if (!struct.isSetReversed()) {
        throw new org.apache.thrift.protocol.TProtocolException(
            "Required field 'reversed' was not found in serialized data! Struct: " + toString());
      }
      if (!struct.isSetCount()) {
        throw new org.apache.thrift.protocol.TProtocolException(
            "Required field 'count' was not found in serialized data! Struct: " + toString());
      }
      struct.validate();
    }