use of com.datastax.oss.driver.api.core.type.codec.PrimitiveShortCodec 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;
}
}
use of com.datastax.oss.driver.api.core.type.codec.PrimitiveShortCodec in project java-driver by datastax.
the class SettableByIndex method setShort.
/**
* Sets the {@code i}th value to the provided Java primitive short.
*
* <p>By default, this works with CQL type {@code smallint}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Short.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setShort(int i, short v) {
DataType cqlType = getType(i);
TypeCodec<Short> codec = codecRegistry().codecFor(cqlType, Short.class);
return (codec instanceof PrimitiveShortCodec) ? setBytesUnsafe(i, ((PrimitiveShortCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
Aggregations