use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method setDouble.
/**
* Sets the {@code i}th value to the provided Java primitive double.
*
* <p>By default, this works with CQL type {@code double}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Double.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setDouble(int i, double v) {
DataType cqlType = getType(i);
TypeCodec<Double> codec = codecRegistry().codecFor(cqlType, Double.class);
return (codec instanceof PrimitiveDoubleCodec) ? setBytesUnsafe(i, ((PrimitiveDoubleCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method set.
/**
* Returns the {@code i}th value, converting it to the given Java type.
*
* <p>The {@link #codecRegistry()} will be used to look up a codec to handle the conversion.
*
* <p>If the target type is generic, use {@link #set(int, Object, GenericType)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
* @throws CodecNotFoundException if no codec can perform the conversion.
*/
@NonNull
@CheckReturnValue
default <ValueT> SelfT set(int i, @Nullable ValueT v, @NonNull Class<ValueT> targetClass) {
// This is duplicated from the GenericType variant, because we want to give the codec registry
// a chance to process the unwrapped class directly, if it can do so in a more efficient way.
DataType cqlType = getType(i);
TypeCodec<ValueT> codec = codecRegistry().codecFor(cqlType, targetClass);
return set(i, v, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method setInt.
/**
* Sets the {@code i}th value to the provided Java primitive integer.
*
* <p>By default, this works with CQL type {@code int}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Integer.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setInt(int i, int v) {
DataType cqlType = getType(i);
TypeCodec<Integer> codec = codecRegistry().codecFor(cqlType, Integer.class);
return (codec instanceof PrimitiveIntCodec) ? setBytesUnsafe(i, ((PrimitiveIntCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method setFloat.
/**
* Sets the {@code i}th value to the provided Java primitive float.
*
* <p>By default, this works with CQL type {@code float}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Float.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setFloat(int i, float v) {
DataType cqlType = getType(i);
TypeCodec<Float> codec = codecRegistry().codecFor(cqlType, Float.class);
return (codec instanceof PrimitiveFloatCodec) ? setBytesUnsafe(i, ((PrimitiveFloatCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method set.
/**
* Sets the {@code i}th value, converting it to the given Java type.
*
* <p>The {@link #codecRegistry()} will be used to look up a codec to handle the conversion.
*
* <p>This variant is for generic Java types. If the target type is not generic, use {@link
* #set(int, Object, Class)} instead, which may perform slightly better.
*
* @throws IndexOutOfBoundsException if the index is invalid.
* @throws CodecNotFoundException if no codec can perform the conversion.
*/
@NonNull
@CheckReturnValue
default <ValueT> SelfT set(int i, @Nullable ValueT v, @NonNull GenericType<ValueT> targetType) {
DataType cqlType = getType(i);
TypeCodec<ValueT> codec = codecRegistry().codecFor(cqlType, targetType);
return set(i, v, codec);
}
Aggregations