use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class SettableByIndex method setLong.
/**
* Sets the {@code i}th value to the provided Java primitive long.
*
* <p>By default, this works with CQL types {@code bigint} and {@code counter}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Long.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setLong(int i, long v) {
DataType cqlType = getType(i);
TypeCodec<Long> codec = codecRegistry().codecFor(cqlType, Long.class);
return (codec instanceof PrimitiveLongCodec) ? setBytesUnsafe(i, ((PrimitiveLongCodec) 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 setBoolean.
/**
* Sets the {@code i}th value to the provided Java primitive boolean.
*
* <p>By default, this works with CQL type {@code boolean}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Boolean.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setBoolean(int i, boolean v) {
DataType cqlType = getType(i);
TypeCodec<Boolean> codec = codecRegistry().codecFor(cqlType, Boolean.class);
return (codec instanceof PrimitiveBooleanCodec) ? setBytesUnsafe(i, ((PrimitiveBooleanCodec) 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 GettableByIndex method getLong.
/**
* Returns the {@code i}th value as a Java primitive long.
*
* <p>By default, this works with CQL types {@code bigint} and {@code counter}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Long.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default long getLong(int i) {
DataType cqlType = getType(i);
TypeCodec<Long> codec = codecRegistry().codecFor(cqlType, Long.class);
if (codec instanceof PrimitiveLongCodec) {
return ((PrimitiveLongCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Long value = get(i, codec);
return value == null ? 0 : value;
}
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class GettableByIndex method get.
/**
* 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>This variant is for generic Java types. If the target type is not generic, use {@link
* #get(int, Class)} instead, which may perform slightly better.
*
* @throws IndexOutOfBoundsException if the index is invalid.
* @throws CodecNotFoundException if no codec can perform the conversion.
*/
@Nullable
default <ValueT> ValueT get(int i, GenericType<ValueT> targetType) {
DataType cqlType = getType(i);
TypeCodec<ValueT> codec = codecRegistry().codecFor(cqlType, targetType);
return get(i, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class GettableByIndex method getShort.
/**
* Returns the {@code i}th value as a Java primitive short.
*
* <p>By default, this works with CQL type {@code smallint}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Short.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default short getShort(int i) {
DataType cqlType = getType(i);
TypeCodec<Short> codec = codecRegistry().codecFor(cqlType, Short.class);
if (codec instanceof PrimitiveShortCodec) {
return ((PrimitiveShortCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Short value = get(i, codec);
return value == null ? 0 : value;
}
}
Aggregations