private UserpWriter write(ValRegister.StoType sto, long val_i64, Object val_obj) throws IOException { if (nodeCodec == null) tupleState.tupleCodec.nextElement(this); if (nodeCodecOverride != null) { CustomCodec cc = nodeCodecOverride; nodeCodecOverride = null; cc.encode(this, sto, val_i64, val_obj); } else if (sto == ValRegister.StoType.LONG) nodeCodec.writeValue(this, val_i64); else nodeCodec.writeValue(this, val_obj); nodeCodec = null; return this; }
public UserpWriter beginTuple(int elemCount) throws IOException { if (nodeCodec == null) tupleState.tupleCodec.nextElement(this); tupleStateStack.push(tupleState); tupleState = new TupleStackEntry(); nodeCodec.beginTuple(this, elemCount); return this; }
@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)); }
static ColumnMetadata build(TableMetadata tm, Row row) { try { String name = row.getString(COLUMN_NAME); AbstractType<?> t = TypeParser.parse(row.getString(VALIDATOR)); ColumnMetadata cm = new ColumnMetadata(tm, name, Codec.rawTypeToDataType(t), row); tm.add(cm); return cm; } catch (RequestValidationException e) { // The server will have validated the type throw new RuntimeException(e); } }
@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(); }
@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)); }
@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)); }
public UserpWriter select(CodecDescriptor unionMemberDesc) throws IOException { if (nodeCodec == null) tupleState.tupleCodec.nextElement(this); nodeCodec.selectType(this, unionMemberDesc); return this; }
public UserpWriter select(UserpType memberType) throws IOException { if (nodeCodec == null) tupleState.tupleCodec.nextElement(this); nodeCodec.selectType(this, memberType); return this; }
static Definition fromTransportSpecification(ColumnSpecification spec) { return new Definition( spec.ksName, spec.cfName, spec.name.toString(), Codec.rawTypeToDataType(spec.type)); }