Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass) {
    DataType type = metadata.getType(i);
    if (type.getName() != DataType.Name.MAP)
      throw new InvalidTypeException(
          String.format("Column %s is not of map type", metadata.getName(i)));

    Class<?> expectedKeysClass = type.getTypeArguments().get(0).getName().javaType;
    Class<?> expectedValuesClass = type.getTypeArguments().get(1).getName().javaType;
    if (!keysClass.isAssignableFrom(expectedKeysClass)
        || !valuesClass.isAssignableFrom(expectedValuesClass))
      throw new InvalidTypeException(
          String.format(
              "Column %s is a map of %s->%s (CQL type %s), cannot be retrieve as a map of %s->%s",
              metadata.getName(i),
              expectedKeysClass,
              expectedValuesClass,
              type,
              keysClass,
              valuesClass));

    ByteBuffer value = data.get(i);
    if (value == null) return Collections.<K, V>emptyMap();

    return Collections.unmodifiableMap(Codec.<Map<K, V>>getCodec(type).compose(value));
  }
Exemplo n.º 2
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("Row[");
   for (int i = 0; i < metadata.size(); i++) {
     if (i != 0) sb.append(", ");
     ByteBuffer bb = data.get(i);
     if (bb == null) sb.append("NULL");
     else sb.append(Codec.getCodec(metadata.getType(i)).getString(bb));
   }
   sb.append("]");
   return sb.toString();
 }
Exemplo n.º 3
0
  // This method checks the value of the "[applied]" column manually, to avoid instantiating an
  // ArrayBackedRow
  // object that we would throw away immediately.
  private static boolean checkWasApplied(List<ByteBuffer> firstRow, ColumnDefinitions metadata) {
    // If the column is not present or not a boolean, we assume the query
    // was not a conditional statement, and therefore return true.
    if (firstRow == null) return true;
    int[] is = metadata.findAllIdx("[applied]");
    if (is == null) return true;
    int i = is[0];
    if (!DataType.cboolean().equals(metadata.getType(i))) return true;

    // Otherwise return the value of the column
    ByteBuffer value = firstRow.get(i);
    if (value == null || value.remaining() == 0) return false;

    return TypeCodec.BooleanCodec.instance.deserializeNoBoxing(value);
  }
Exemplo n.º 4
0
  public ByteBuffer getBytesUnsafe(int i) {
    metadata.checkBounds(i);

    ByteBuffer value = data.get(i);
    if (value == null) return null;

    return value.duplicate();
  }
Exemplo n.º 5
0
  public float getFloat(int i) {
    metadata.checkType(i, DataType.Name.FLOAT);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return 0.0f;

    return FloatType.instance.compose(value);
  }
Exemplo n.º 6
0
  public InetAddress getInet(int i) {
    metadata.checkType(i, DataType.Name.INET);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return null;

    return InetAddressType.instance.compose(value);
  }
Exemplo n.º 7
0
  public double getDouble(int i) {
    metadata.checkType(i, DataType.Name.DOUBLE);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return 0.0;

    return DoubleType.instance.compose(value);
  }
Exemplo n.º 8
0
  public boolean getBool(int i) {
    metadata.checkType(i, DataType.Name.BOOLEAN);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return false;

    return BooleanType.instance.compose(value);
  }
Exemplo n.º 9
0
  public long getLong(int i) {
    metadata.checkType(i, DataType.Name.BIGINT, DataType.Name.COUNTER);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return 0L;

    return LongType.instance.compose(value);
  }
Exemplo n.º 10
0
  public int getInt(int i) {
    metadata.checkType(i, DataType.Name.INT);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return 0;

    return Int32Type.instance.compose(value);
  }
Exemplo n.º 11
0
  public BigDecimal getDecimal(int i) {
    metadata.checkType(i, DataType.Name.DECIMAL);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return null;

    return DecimalType.instance.compose(value);
  }
Exemplo n.º 12
0
  public Date getDate(int i) {
    metadata.checkType(i, DataType.Name.TIMESTAMP);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return null;

    return DateType.instance.compose(value);
  }
Exemplo n.º 13
0
  public BigInteger getVarint(int i) {
    metadata.checkType(i, DataType.Name.VARINT);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return null;

    return IntegerType.instance.compose(value);
  }
Exemplo n.º 14
0
  public UUID getUUID(int i) {
    DataType.Name type = metadata.checkType(i, DataType.Name.UUID, DataType.Name.TIMEUUID);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0) return null;

    return type == DataType.Name.UUID
        ? UUIDType.instance.compose(value)
        : TimeUUIDType.instance.compose(value);
  }
Exemplo n.º 15
0
  @SuppressWarnings("unchecked")
  public <T> Set<T> getSet(int i, Class<T> elementsClass) {
    DataType type = metadata.getType(i);
    if (type.getName() != DataType.Name.SET)
      throw new InvalidTypeException(
          String.format("Column %s is not of set type", metadata.getName(i)));

    Class<?> expectedClass = type.getTypeArguments().get(0).getName().javaType;
    if (!elementsClass.isAssignableFrom(expectedClass))
      throw new InvalidTypeException(
          String.format(
              "Column %s is a set of %s (CQL type %s), cannot be retrieve as a set of %s",
              metadata.getName(i), expectedClass, type, elementsClass));

    ByteBuffer value = data.get(i);
    if (value == null) return Collections.<T>emptySet();

    return Collections.unmodifiableSet(Codec.<Set<T>>getCodec(type).compose(value));
  }
Exemplo n.º 16
0
  @SuppressWarnings("unchecked")
  public <T> List<T> getList(int i, Class<T> elementsClass) {
    DataType type = metadata.getType(i);
    if (type.getName() != DataType.Name.LIST)
      throw new InvalidTypeException(
          String.format("Column %s is not of list type", metadata.getName(i)));

    Class<?> expectedClass = type.getTypeArguments().get(0).getName().javaType;
    if (!elementsClass.isAssignableFrom(expectedClass))
      throw new InvalidTypeException(
          String.format(
              "Column %s is a list of %s (CQL type %s), cannot be retrieve as a list of %s",
              metadata.getName(i), expectedClass, type, elementsClass));

    ByteBuffer value = data.get(i);
    if (value == null) return Collections.<T>emptyList();

    // TODO: we could avoid the getCodec call if we kept a reference to the original message.
    return Collections.unmodifiableList(Codec.<List<T>>getCodec(type).compose(value));
  }
Exemplo n.º 17
0
  public String getString(int i) {
    DataType.Name type =
        metadata.checkType(i, DataType.Name.VARCHAR, DataType.Name.TEXT, DataType.Name.ASCII);

    ByteBuffer value = data.get(i);
    if (value == null) return null;

    return type == DataType.Name.ASCII
        ? AsciiType.instance.compose(value)
        : UTF8Type.instance.compose(value);
  }
Exemplo n.º 18
0
 public BigInteger getVarint(String name) {
   return getVarint(metadata.getIdx(name));
 }
Exemplo n.º 19
0
 public ByteBuffer getBytes(String name) {
   return getBytes(metadata.getIdx(name));
 }
Exemplo n.º 20
0
 public BigDecimal getDecimal(String name) {
   return getDecimal(metadata.getIdx(name));
 }
Exemplo n.º 21
0
 public long getLong(String name) {
   return getLong(metadata.getIdx(name));
 }
Exemplo n.º 22
0
 public UUID getUUID(String name) {
   return getUUID(metadata.getIdx(name));
 }
Exemplo n.º 23
0
 public int getInt(String name) {
   return getInt(metadata.getIdx(name));
 }
Exemplo n.º 24
0
 public InetAddress getInet(String name) {
   return getInet(metadata.getIdx(name));
 }
Exemplo n.º 25
0
 public boolean getBool(String name) {
   return getBool(metadata.getIdx(name));
 }
Exemplo n.º 26
0
 public boolean isNull(String name) {
   return isNull(metadata.getIdx(name));
 }
Exemplo n.º 27
0
 public boolean isNull(int i) {
   metadata.checkBounds(i);
   return data.get(i) == null;
 }
Exemplo n.º 28
0
 public ByteBuffer getBytes(int i) {
   metadata.checkType(i, DataType.Name.BLOB);
   return getBytesUnsafe(i);
 }
Exemplo n.º 29
0
 public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass) {
   return getMap(metadata.getIdx(name), keysClass, valuesClass);
 }
Exemplo n.º 30
0
 public <T> Set<T> getSet(String name, Class<T> elementsClass) {
   return getSet(metadata.getIdx(name), elementsClass);
 }