Esempio 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));
  }
Esempio 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();
 }
Esempio n. 3
0
  public ByteBuffer getBytesUnsafe(int i) {
    metadata.checkBounds(i);

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

    return value.duplicate();
  }
Esempio n. 4
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);
  }
Esempio 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);
  }
Esempio n. 6
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);
  }
Esempio n. 7
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);
  }
Esempio n. 8
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);
  }
Esempio n. 9
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);
  }
Esempio n. 10
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);
  }
Esempio n. 11
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);
  }
Esempio n. 12
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);
  }
Esempio n. 13
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);
  }
Esempio n. 14
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));
  }
Esempio n. 15
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));
  }
Esempio n. 16
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);
  }
Esempio n. 17
0
 public int getInt(String name) {
   return getInt(metadata.getIdx(name));
 }
Esempio n. 18
0
 public BigInteger getVarint(String name) {
   return getVarint(metadata.getIdx(name));
 }
Esempio n. 19
0
 public boolean getBool(String name) {
   return getBool(metadata.getIdx(name));
 }
Esempio n. 20
0
 public BigDecimal getDecimal(String name) {
   return getDecimal(metadata.getIdx(name));
 }
Esempio n. 21
0
 public boolean isNull(String name) {
   return isNull(metadata.getIdx(name));
 }
Esempio n. 22
0
 public boolean isNull(int i) {
   metadata.checkBounds(i);
   return data.get(i) == null;
 }
Esempio n. 23
0
 public double getDouble(String name) {
   return getDouble(metadata.getIdx(name));
 }
Esempio n. 24
0
 public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass) {
   return getMap(metadata.getIdx(name), keysClass, valuesClass);
 }
Esempio n. 25
0
 public ByteBuffer getBytes(int i) {
   metadata.checkType(i, DataType.Name.BLOB);
   return getBytesUnsafe(i);
 }
Esempio n. 26
0
 public long getLong(String name) {
   return getLong(metadata.getIdx(name));
 }
Esempio n. 27
0
 public UUID getUUID(String name) {
   return getUUID(metadata.getIdx(name));
 }
Esempio n. 28
0
 public InetAddress getInet(String name) {
   return getInet(metadata.getIdx(name));
 }
Esempio n. 29
0
 public <T> Set<T> getSet(String name, Class<T> elementsClass) {
   return getSet(metadata.getIdx(name), elementsClass);
 }
Esempio n. 30
0
 public ByteBuffer getBytes(String name) {
   return getBytes(metadata.getIdx(name));
 }