Search in sources :

Example 21 with DataType

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);
}
Also used : PrimitiveDoubleCodec(com.datastax.oss.driver.api.core.type.codec.PrimitiveDoubleCodec) DataType(com.datastax.oss.driver.api.core.type.DataType) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 22 with DataType

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);
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 23 with DataType

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);
}
Also used : BigInteger(java.math.BigInteger) DataType(com.datastax.oss.driver.api.core.type.DataType) PrimitiveIntCodec(com.datastax.oss.driver.api.core.type.codec.PrimitiveIntCodec) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 24 with DataType

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);
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType) PrimitiveFloatCodec(com.datastax.oss.driver.api.core.type.codec.PrimitiveFloatCodec) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 25 with DataType

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);
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

DataType (com.datastax.oss.driver.api.core.type.DataType)73 NonNull (edu.umd.cs.findbugs.annotations.NonNull)21 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)19 SetType (com.datastax.oss.driver.api.core.type.SetType)10 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)10 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)10 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)9 CheckReturnValue (edu.umd.cs.findbugs.annotations.CheckReturnValue)9 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)8 Map (java.util.Map)8 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)7 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)7 ListType (com.datastax.oss.driver.api.core.type.ListType)7 MapType (com.datastax.oss.driver.api.core.type.MapType)7 TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)6 Nullable (edu.umd.cs.findbugs.annotations.Nullable)6 UUID (java.util.UUID)6 TupleType (com.datastax.oss.driver.api.core.type.TupleType)5 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)5 List (java.util.List)5