Class AbstractGettableData
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.types.AbstractGettableData
-
- All Implemented Interfaces:
GettableByIndexData
,GettableByNameData
,GettableData
- Direct Known Subclasses:
UDTValue
public abstract class AbstractGettableData extends java.lang.Object implements GettableData
-
-
Field Summary
Fields Modifier and Type Field Description protected ProtocolVersion
protocolVersion
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected <T> TypeCodec<T>
codecFor(int i)
protected <T> TypeCodec<T>
codecFor(int i, com.google.common.reflect.TypeToken<T> javaType)
protected <T> TypeCodec<T>
codecFor(int i, java.lang.Class<T> javaClass)
protected <T> TypeCodec<T>
codecFor(int i, T value)
<T> T
get(int i, com.google.common.reflect.TypeToken<T> targetType)
Returns thei
th value converted to the given Java type.<T> T
get(int i, java.lang.Class<T> targetClass)
Returns thei
th value converted to the given Java type.<T> T
get(int i, TypeCodec<T> codec)
Returns thei
th value converted using the givenTypeCodec
.<T> T
get(java.lang.String name, com.google.common.reflect.TypeToken<T> targetType)
Returns the value forname
converted to the given Java type.<T> T
get(java.lang.String name, java.lang.Class<T> targetClass)
Returns the value forname
converted to the given Java type.<T> T
get(java.lang.String name, TypeCodec<T> codec)
Returns the value forname
converted using the givenTypeCodec
.boolean
getBool(int i)
Returns thei
th value as a boolean.boolean
getBool(java.lang.String name)
Returns the value forname
as a boolean.byte
getByte(int i)
Returns thei
th value as a byte.byte
getByte(java.lang.String name)
Returns the value forname
as a byte.java.nio.ByteBuffer
getBytes(int i)
Returns thei
th value as a byte array.java.nio.ByteBuffer
getBytes(java.lang.String name)
Returns the value forname
as a byte array.java.nio.ByteBuffer
getBytesUnsafe(int i)
Returns thei
th value as aByteBuffer
.java.nio.ByteBuffer
getBytesUnsafe(java.lang.String name)
Returns the value forname
as a ByteBuffer.protected abstract CodecRegistry
getCodecRegistry()
LocalDate
getDate(int i)
Returns thei
th value as a date (without time).LocalDate
getDate(java.lang.String name)
Returns the value forname
as a date (without time).java.math.BigDecimal
getDecimal(int i)
Returns thei
th value as a variable length decimal.java.math.BigDecimal
getDecimal(java.lang.String name)
Returns the value forname
as a variable length decimal.double
getDouble(int i)
Returns thei
th value as a double.double
getDouble(java.lang.String name)
Returns the value forname
as a double.float
getFloat(int i)
Returns thei
th value as a float.float
getFloat(java.lang.String name)
Returns the value forname
as a float.protected abstract int
getIndexOf(java.lang.String name)
Returns the index corresponding to a given name.java.net.InetAddress
getInet(int i)
Returns thei
th value as an InetAddress.java.net.InetAddress
getInet(java.lang.String name)
Returns the value forname
as an InetAddress.int
getInt(int i)
Returns thei
th value as an integer.int
getInt(java.lang.String name)
Returns the value forname
as an integer.<T> java.util.List<T>
getList(int i, com.google.common.reflect.TypeToken<T> elementsType)
Returns thei
th value as a list.<T> java.util.List<T>
getList(int i, java.lang.Class<T> elementsClass)
Returns thei
th value as a list.<T> java.util.List<T>
getList(java.lang.String name, com.google.common.reflect.TypeToken<T> elementsType)
Returns the value forname
as a list.<T> java.util.List<T>
getList(java.lang.String name, java.lang.Class<T> elementsClass)
Returns the value forname
as a list.long
getLong(int i)
Returns thei
th value as a long.long
getLong(java.lang.String name)
Returns the value forname
as a long.<K,V>
java.util.Map<K,V>getMap(int i, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
Returns thei
th value as a map.<K,V>
java.util.Map<K,V>getMap(int i, java.lang.Class<K> keysClass, java.lang.Class<V> valuesClass)
Returns thei
th value as a map.<K,V>
java.util.Map<K,V>getMap(java.lang.String name, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
Returns the value forname
as a map.<K,V>
java.util.Map<K,V>getMap(java.lang.String name, java.lang.Class<K> keysClass, java.lang.Class<V> valuesClass)
Returns the value forname
as a map.protected abstract java.lang.String
getName(int i)
Returns the name corresponding to the value at indexi
.java.lang.Object
getObject(int i)
Returns thei
th value as the Java type matching its CQL type.java.lang.Object
getObject(java.lang.String name)
Returns the value forname
as the Java type matching its CQL type.<T> java.util.Set<T>
getSet(int i, com.google.common.reflect.TypeToken<T> elementsType)
Returns thei
th value as a set.<T> java.util.Set<T>
getSet(int i, java.lang.Class<T> elementsClass)
Returns thei
th value as a set.<T> java.util.Set<T>
getSet(java.lang.String name, com.google.common.reflect.TypeToken<T> elementsType)
Returns the value forname
as a set.<T> java.util.Set<T>
getSet(java.lang.String name, java.lang.Class<T> elementsClass)
Returns the value forname
as a set.short
getShort(int i)
Returns thei
th value as a short.short
getShort(java.lang.String name)
Returns the value forname
as a short.java.lang.String
getString(int i)
Returns thei
th value as a string.java.lang.String
getString(java.lang.String name)
Returns the value forname
as a string.long
getTime(int i)
Returns thei
th value as a long in nanoseconds since midnight.long
getTime(java.lang.String name)
Returns the value forname
as a long in nanoseconds since midnight.java.util.Date
getTimestamp(int i)
Returns thei
th value as a date.java.util.Date
getTimestamp(java.lang.String name)
Returns the value forname
as a date.TupleValue
getTupleValue(int i)
Return thei
th value as a tuple value.TupleValue
getTupleValue(java.lang.String name)
Return the value forname
as a tuple value.protected abstract DataType
getType(int i)
Returns the type for the value at indexi
.UDTValue
getUDTValue(int i)
Return thei
th value as a UDT value.UDTValue
getUDTValue(java.lang.String name)
Return the value forname
as a UDT value.java.util.UUID
getUUID(int i)
Returns thei
th value as a UUID.java.util.UUID
getUUID(java.lang.String name)
Returns the value forname
as a UUID.protected abstract java.nio.ByteBuffer
getValue(int i)
Returns the value at indexi
.java.math.BigInteger
getVarint(int i)
Returns thei
th value as a variable length integer.java.math.BigInteger
getVarint(java.lang.String name)
Returns the value forname
as a variable length integer.boolean
isNull(int i)
Returns whether thei
th value is NULL.boolean
isNull(java.lang.String name)
Returns whether the value forname
is NULL.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.cql3.functions.types.GettableByIndexData
get, get, get, getBool, getByte, getBytes, getBytesUnsafe, getDate, getDecimal, getDouble, getFloat, getInet, getInt, getList, getList, getLong, getMap, getMap, getObject, getSet, getSet, getShort, getString, getTime, getTimestamp, getTupleValue, getUDTValue, getUUID, getVarint, isNull
-
-
-
-
Field Detail
-
protocolVersion
protected final ProtocolVersion protocolVersion
-
-
Method Detail
-
getIndexOf
protected abstract int getIndexOf(java.lang.String name)
Returns the index corresponding to a given name.- Parameters:
name
- the name for which to return the index of.- Returns:
- the index for the value coressponding to
name
. - Throws:
java.lang.IllegalArgumentException
- ifname
is not valid name for this object.
-
isNull
public boolean isNull(java.lang.String name)
Returns whether the value forname
is NULL.- Specified by:
isNull
in interfaceGettableByNameData
- Parameters:
name
- the name to check.- Returns:
- whether the value for
name
is NULL.
-
getBool
public boolean getBool(java.lang.String name)
Returns the value forname
as a boolean.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javaboolean
(for CQL typeboolean
, this will be the built-in codec).- Specified by:
getBool
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the boolean value for
name
. If the value is NULL,false
is returned. If you need to distinguish NULL and false values, check first withGettableByNameData.isNull(String)
or useget(name, Boolean.class)
.
-
getByte
public byte getByte(java.lang.String name)
Returns the value forname
as a byte.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javabyte
(for CQL typetinyint
, this will be the built-in codec).- Specified by:
getByte
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a byte. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByNameData.isNull(String)
or useget(name, Byte.class)
.0
is returned.
-
getShort
public short getShort(java.lang.String name)
Returns the value forname
as a short.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javashort
(for CQL typesmallint
, this will be the built-in codec).- Specified by:
getShort
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a short. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByNameData.isNull(String)
or useget(name, Short.class)
.0
is returned.
-
getInt
public int getInt(java.lang.String name)
Returns the value forname
as an integer.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javaint
(for CQL typeint
, this will be the built-in codec).- Specified by:
getInt
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as an integer. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByNameData.isNull(String)
or useget(name, Integer.class)
.0
is returned.
-
getLong
public long getLong(java.lang.String name)
Returns the value forname
as a long.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javabyte
(for CQL typesbigint
andcounter
, this will be the built-in codec).- Specified by:
getLong
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a long. If the value is NULL,0L
is returned. If you need to distinguish NULL and 0L, check first withGettableByNameData.isNull(String)
or useget(name, Long.class)
.
-
getTimestamp
public java.util.Date getTimestamp(java.lang.String name)
Returns the value forname
as a date.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aDate
(for CQL typetimestamp
, this will be the built-in codec).- Specified by:
getTimestamp
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a date. If the value is NULL,null
is returned.
-
getDate
public LocalDate getDate(java.lang.String name)
Returns the value forname
as a date (without time).This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aLocalDate
(for CQL typedate
, this will be the built-in codec).- Specified by:
getDate
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a date. If the value is NULL,null
is returned.
-
getTime
public long getTime(java.lang.String name)
Returns the value forname
as a long in nanoseconds since midnight.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javalong
(for CQL typetime
, this will be the built-in codec).- Specified by:
getTime
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a long. If the value is NULL,0L
is returned.
-
getFloat
public float getFloat(java.lang.String name)
Returns the value forname
as a float.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javafloat
(for CQL typefloat
, this will be the built-in codec).- Specified by:
getFloat
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a float. If the value is NULL,0.0f
is returned. If you need to distinguish NULL and 0.0f, check first withGettableByNameData.isNull(String)
or useget(name, Float.class)
.
-
getDouble
public double getDouble(java.lang.String name)
Returns the value forname
as a double.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javadouble
(for CQL typedouble
, this will be the built-in codec).- Specified by:
getDouble
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a double. If the value is NULL,0.0
is returned. If you need to distinguish NULL and 0.0, check first withGettableByNameData.isNull(String)
or useget(name, Double.class)
.
-
getBytesUnsafe
public java.nio.ByteBuffer getBytesUnsafe(java.lang.String name)
Returns the value forname
as a ByteBuffer.This method does not use any codec; it returns a copy of the binary representation of the value. It is up to the caller to convert the returned value appropriately.
Note: this method always return the bytes composing the value, even if the column is not of type BLOB. That is, this method never throw an InvalidTypeException. However, if the type is not BLOB, it is up to the caller to handle the returned value correctly.
- Specified by:
getBytesUnsafe
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a ByteBuffer. If the value is NULL,null
is returned.
-
getBytes
public java.nio.ByteBuffer getBytes(java.lang.String name)
Returns the value forname
as a byte array.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a JavaByteBuffer
(for CQL typeblob
, this will be the built-in codec).- Specified by:
getBytes
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a byte array. If the value is NULL,null
is returned.
-
getString
public java.lang.String getString(java.lang.String name)
Returns the value forname
as a string.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Java string (for CQL typestext
,varchar
andascii
, this will be the built-in codec).- Specified by:
getString
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a string. If the value is NULL,null
is returned.
-
getVarint
public java.math.BigInteger getVarint(java.lang.String name)
Returns the value forname
as a variable length integer.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aBigInteger
(for CQL typevarint
, this will be the built-in codec).- Specified by:
getVarint
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a variable length integer. If the value is NULL,null
is returned.
-
getDecimal
public java.math.BigDecimal getDecimal(java.lang.String name)
Returns the value forname
as a variable length decimal.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aBigDecimal
(for CQL typedecimal
, this will be the built-in codec).- Specified by:
getDecimal
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a variable length decimal. If the value is NULL,null
is returned.
-
getUUID
public java.util.UUID getUUID(java.lang.String name)
Returns the value forname
as a UUID.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aUUID
(for CQL typesuuid
andtimeuuid
, this will be the built-in codec).- Specified by:
getUUID
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as a UUID. If the value is NULL,null
is returned.
-
getInet
public java.net.InetAddress getInet(java.lang.String name)
Returns the value forname
as an InetAddress.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to anInetAddress
(for CQL typeinet
, this will be the built-in codec).- Specified by:
getInet
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value for
name
as an InetAddress. If the value is NULL,null
is returned.
-
getList
public <T> java.util.List<T> getList(java.lang.String name, java.lang.Class<T> elementsClass)
Returns the value forname
as a list.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a list of the specified type.If the type of the elements is generic, use
GettableByNameData.getList(String, TypeToken)
.Implementation note: the actual
List
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getList
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.elementsClass
- the class for the elements of the list to retrieve.- Returns:
- the value of the
i
th element as a list ofT
objects.
-
getList
public <T> java.util.List<T> getList(java.lang.String name, com.google.common.reflect.TypeToken<T> elementsType)
Returns the value forname
as a list.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a list of the specified type.Use this variant with nested collections, which produce a generic element type:
List<List<String>> l = row.getList("theColumn", new TypeToken<List<String>>() {});
Implementation note: the actual
List
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getList
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.elementsType
- the type for the elements of the list to retrieve.- Returns:
- the value of the
i
th element as a list ofT
objects.
-
getSet
public <T> java.util.Set<T> getSet(java.lang.String name, java.lang.Class<T> elementsClass)
Returns the value forname
as a set.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a set of the specified type.If the type of the elements is generic, use
GettableByNameData.getSet(String, TypeToken)
.Implementation note: the actual
Set
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getSet
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.elementsClass
- the class for the elements of the set to retrieve.- Returns:
- the value of the
i
th element as a set ofT
objects.
-
getSet
public <T> java.util.Set<T> getSet(java.lang.String name, com.google.common.reflect.TypeToken<T> elementsType)
Returns the value forname
as a set.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a set of the specified type.Use this variant with nested collections, which produce a generic element type:
Set<List<String>> l = row.getSet("theColumn", new TypeToken<List<String>>() {});
Implementation note: the actual
Set
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getSet
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.elementsType
- the type for the elements of the set to retrieve.- Returns:
- the value of the
i
th element as a set ofT
objects.
-
getMap
public <K,V> java.util.Map<K,V> getMap(java.lang.String name, java.lang.Class<K> keysClass, java.lang.Class<V> valuesClass)
Returns the value forname
as a map.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a map of the specified types.If the type of the keys and/or values is generic, use
GettableByNameData.getMap(String, TypeToken, TypeToken)
.Implementation note: the actual
Map
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getMap
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.keysClass
- the class for the keys of the map to retrieve.valuesClass
- the class for the values of the map to retrieve.- Returns:
- the value of
name
as a map ofK
toV
objects.
-
getMap
public <K,V> java.util.Map<K,V> getMap(java.lang.String name, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
Returns the value forname
as a map.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a map of the specified types.Use this variant with nested collections, which produce a generic element type:
Map<Int, List<String>> l = row.getMap("theColumn", TypeToken.of(Integer.class), new TypeToken<List<String>>() {});
Implementation note: the actual
Map
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getMap
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.keysType
- the class for the keys of the map to retrieve.valuesType
- the class for the values of the map to retrieve.- Returns:
- the value of
name
as a map ofK
toV
objects.
-
getUDTValue
public UDTValue getUDTValue(java.lang.String name)
Return the value forname
as a UDT value.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aUDTValue
(if the CQL type is a UDT, the registry will generate a codec automatically).- Specified by:
getUDTValue
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value of
name
as a UDT value. If the value is NULL, thennull
will be returned.
-
getTupleValue
public TupleValue getTupleValue(java.lang.String name)
Return the value forname
as a tuple value.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aTupleValue
(if the CQL type is a tuple, the registry will generate a codec automatically).- Specified by:
getTupleValue
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value of
name
as a tuple value. If the value is NULL, thennull
will be returned.
-
getObject
public java.lang.Object getObject(java.lang.String name)
Returns the value forname
as the Java type matching its CQL type.This method uses the
CodecRegistry
to find the first codec that handles the underlying CQL type. The Java type of the returned object will be determined by the codec that was selected.Use this method to dynamically inspect elements when types aren't known in advance, for instance if you're writing a generic row logger. If you know the target Java type, it is generally preferable to use typed getters, such as the ones for built-in types (
GettableByNameData.getBool(String)
,GettableByNameData.getInt(String)
, etc.), orGettableByNameData.get(String, Class)
andGettableByNameData.get(String, TypeToken)
for custom types.- Specified by:
getObject
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.- Returns:
- the value of
name
as the Java type matching its CQL type. If the value is NULL and is a simple type, UDT or tuple,null
is returned. If it is NULL and is a collection type, an empty (immutable) collection is returned. - See Also:
CodecRegistry.codecFor(DataType)
-
get
public <T> T get(java.lang.String name, java.lang.Class<T> targetClass)
Returns the value forname
converted to the given Java type.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to the given Java type.If the target type is generic, use
GettableByNameData.get(String, TypeToken)
.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.targetClass
- The Java type the value should be converted to.- Returns:
- the value for
name
value converted to the given Java type.
-
get
public <T> T get(java.lang.String name, com.google.common.reflect.TypeToken<T> targetType)
Returns the value forname
converted to the given Java type.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to the given Java type.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.targetType
- The Java type the value should be converted to.- Returns:
- the value for
name
value converted to the given Java type.
-
get
public <T> T get(java.lang.String name, TypeCodec<T> codec)
Returns the value forname
converted using the givenTypeCodec
.This method entirely bypasses the
CodecRegistry
and forces the driver to use the given codec instead. This can be useful if the codec would collide with a previously registered one, or if you want to use the codec just once without registering it.It is the caller's responsibility to ensure that the given codec
accepts
the underlying CQL type; failing to do so may result inInvalidTypeException
s being thrown.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByNameData
- Parameters:
name
- the name to retrieve.codec
- TheTypeCodec
to use to deserialize the value; may not benull
.- Returns:
- the value of the
i
th value converted using the givenTypeCodec
.
-
getType
protected abstract DataType getType(int i)
Returns the type for the value at indexi
.- Parameters:
i
- the index of the type to fetch.- Returns:
- the type of the value at index
i
. - Throws:
java.lang.IndexOutOfBoundsException
- ifi
is not a valid index.
-
getName
protected abstract java.lang.String getName(int i)
Returns the name corresponding to the value at indexi
.- Parameters:
i
- the index of the name to fetch.- Returns:
- the name corresponding to the value at index
i
. - Throws:
java.lang.IndexOutOfBoundsException
- ifi
is not a valid index.
-
getValue
protected abstract java.nio.ByteBuffer getValue(int i)
Returns the value at indexi
.- Parameters:
i
- the index to fetch.- Returns:
- the value at index
i
. - Throws:
java.lang.IndexOutOfBoundsException
- ifi
is not a valid index.
-
getCodecRegistry
protected abstract CodecRegistry getCodecRegistry()
-
codecFor
protected <T> TypeCodec<T> codecFor(int i)
-
codecFor
protected <T> TypeCodec<T> codecFor(int i, java.lang.Class<T> javaClass)
-
codecFor
protected <T> TypeCodec<T> codecFor(int i, com.google.common.reflect.TypeToken<T> javaType)
-
codecFor
protected <T> TypeCodec<T> codecFor(int i, T value)
-
isNull
public boolean isNull(int i)
Returns whether thei
th value is NULL.- Specified by:
isNull
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) of the value to check.- Returns:
- whether the
i
th value is NULL.
-
getBool
public boolean getBool(int i)
Returns thei
th value as a boolean.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javaboolean
(for CQL typeboolean
, this will be the built-in codec).- Specified by:
getBool
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the boolean value of the
i
th element. If the value is NULL,false
is returned. If you need to distinguish NULL and false values, check first withGettableByIndexData.isNull(int)
or useget(i, Boolean.class)
.
-
getByte
public byte getByte(int i)
Returns thei
th value as a byte.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javabyte
(for CQL typetinyint
, this will be the built-in codec).- Specified by:
getByte
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a byte. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByIndexData.isNull(int)
or useget(i, Byte.class)
.
-
getShort
public short getShort(int i)
Returns thei
th value as a short.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javashort
(for CQL typesmallint
, this will be the built-in codec).- Specified by:
getShort
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a short. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByIndexData.isNull(int)
or useget(i, Short.class)
.
-
getInt
public int getInt(int i)
Returns thei
th value as an integer.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javaint
(for CQL typeint
, this will be the built-in codec).- Specified by:
getInt
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as an integer. If the value is NULL,0
is returned. If you need to distinguish NULL and 0, check first withGettableByIndexData.isNull(int)
or useget(i, Integer.class)
.
-
getLong
public long getLong(int i)
Returns thei
th value as a long.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javabyte
(for CQL typesbigint
andcounter
, this will be the built-in codec).- Specified by:
getLong
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a long. If the value is NULL,0L
is returned. If you need to distinguish NULL and 0L, check first withGettableByIndexData.isNull(int)
or useget(i, Long.class)
.
-
getTimestamp
public java.util.Date getTimestamp(int i)
Returns thei
th value as a date.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aDate
(for CQL typetimestamp
, this will be the built-in codec).- Specified by:
getTimestamp
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a data. If the value is NULL,null
is returned.
-
getDate
public LocalDate getDate(int i)
Returns thei
th value as a date (without time).This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aLocalDate
(for CQL typedate
, this will be the built-in codec).- Specified by:
getDate
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as an date. If the value is NULL,null
is returned.
-
getTime
public long getTime(int i)
Returns thei
th value as a long in nanoseconds since midnight.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javalong
(for CQL typetime
, this will be the built-in codec).- Specified by:
getTime
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a long. If the value is NULL,0L
is returned.
-
getFloat
public float getFloat(int i)
Returns thei
th value as a float.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javafloat
(for CQL typefloat
, this will be the built-in codec).- Specified by:
getFloat
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a float. If the value is NULL,0.0f
is returned. If you need to distinguish NULL and 0.0f, check first withGettableByIndexData.isNull(int)
or useget(i, Float.class)
.
-
getDouble
public double getDouble(int i)
Returns thei
th value as a double.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Javadouble
(for CQL typedouble
, this will be the built-in codec).- Specified by:
getDouble
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a double. If the value is NULL,0.0
is returned. If you need to distinguish NULL and 0.0, check first withGettableByIndexData.isNull(int)
or useget(i, Double.class)
.
-
getBytesUnsafe
public java.nio.ByteBuffer getBytesUnsafe(int i)
Returns thei
th value as aByteBuffer
.This method does not use any codec; it returns a copy of the binary representation of the value. It is up to the caller to convert the returned value appropriately.
- Specified by:
getBytesUnsafe
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a ByteBuffer. If the value is NULL,null
is returned.
-
getBytes
public java.nio.ByteBuffer getBytes(int i)
Returns thei
th value as a byte array.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a JavaByteBuffer
(for CQL typeblob
, this will be the built-in codec).- Specified by:
getBytes
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a byte array. If the value is NULL,null
is returned.
-
getString
public java.lang.String getString(int i)
Returns thei
th value as a string.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a Java string (for CQL typestext
,varchar
andascii
, this will be the built-in codec).- Specified by:
getString
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a string. If the value is NULL,null
is returned.
-
getVarint
public java.math.BigInteger getVarint(int i)
Returns thei
th value as a variable length integer.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aBigInteger
(for CQL typevarint
, this will be the built-in codec).- Specified by:
getVarint
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a variable length integer. If the value is NULL,null
is returned.
-
getDecimal
public java.math.BigDecimal getDecimal(int i)
Returns thei
th value as a variable length decimal.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aBigDecimal
(for CQL typedecimal
, this will be the built-in codec).- Specified by:
getDecimal
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a variable length decimal. If the value is NULL,null
is returned.
-
getUUID
public java.util.UUID getUUID(int i)
Returns thei
th value as a UUID.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aUUID
(for CQL typesuuid
andtimeuuid
, this will be the built-in codec).- Specified by:
getUUID
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a UUID. If the value is NULL,null
is returned.
-
getInet
public java.net.InetAddress getInet(int i)
Returns thei
th value as an InetAddress.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to anInetAddress
(for CQL typeinet
, this will be the built-in codec).- Specified by:
getInet
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as an InetAddress. If the value is NULL,null
is returned.
-
getList
public <T> java.util.List<T> getList(int i, java.lang.Class<T> elementsClass)
Returns thei
th value as a list.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a list of the specified type.If the type of the elements is generic, use
GettableByIndexData.getList(int, TypeToken)
.Implementation note: the actual
List
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will be mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getList
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the list to retrieve.- Returns:
- the value of the
i
th element as a list ofT
objects.
-
getList
public <T> java.util.List<T> getList(int i, com.google.common.reflect.TypeToken<T> elementsType)
Returns thei
th value as a list.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a list of the specified type.Use this variant with nested collections, which produce a generic element type:
List<List<String>> l = row.getList(1, new TypeToken<List<String>>() {});
Implementation note: the actual
List
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getList
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type of the elements of the list to retrieve.- Returns:
- the value of the
i
th element as a list ofT
objects.
-
getSet
public <T> java.util.Set<T> getSet(int i, java.lang.Class<T> elementsClass)
Returns thei
th value as a set.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a set of the specified type.If the type of the elements is generic, use
GettableByIndexData.getSet(int, TypeToken)
.Implementation note: the actual
Set
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getSet
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the set to retrieve.- Returns:
- the value of the
i
th element as a set ofT
objects.
-
getSet
public <T> java.util.Set<T> getSet(int i, com.google.common.reflect.TypeToken<T> elementsType)
Returns thei
th value as a set.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a set of the specified type.Use this variant with nested collections, which produce a generic element type:
Set<List<String>> l = row.getSet(1, new TypeToken<List<String>>() {});
Implementation note: the actual
Set
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getSet
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type for the elements of the set to retrieve.- Returns:
- the value of the
i
th element as a set ofT
objects.
-
getMap
public <K,V> java.util.Map<K,V> getMap(int i, java.lang.Class<K> keysClass, java.lang.Class<V> valuesClass)
Returns thei
th value as a map.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a map of the specified types.If the type of the keys and/or values is generic, use
GettableByIndexData.getMap(int, TypeToken, TypeToken)
.Implementation note: the actual
Map
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getMap
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.keysClass
- the class for the keys of the map to retrieve.valuesClass
- the class for the values of the map to retrieve.- Returns:
- the value of the
i
th element as a map ofK
toV
objects.
-
getMap
public <K,V> java.util.Map<K,V> getMap(int i, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
Returns thei
th value as a map.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to a map of the specified types.Use this variant with nested collections, which produce a generic element type:
Map<Int, List<String>> l = row.getMap(1, TypeToken.of(Integer.class), new TypeToken<List<String>>() {});
Implementation note: the actual
Map
implementation will depend on thecodec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent. By default, the driver will return mutable instances, and a CQLNULL
will mapped to an empty collection (note that Cassandra makes no distinction betweenNULL
and an empty collection).- Specified by:
getMap
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.keysType
- the type for the keys of the map to retrieve.valuesType
- the type for the values of the map to retrieve.- Returns:
- the value of the
i
th element as a map ofK
toV
objects.
-
getUDTValue
public UDTValue getUDTValue(int i)
Return thei
th value as a UDT value.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aUDTValue
(if the CQL type is a UDT, the registry will generate a codec automatically).- Specified by:
getUDTValue
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a UDT value. If the value is NULL, thennull
will be returned.
-
getTupleValue
public TupleValue getTupleValue(int i)
Return thei
th value as a tuple value.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to aTupleValue
(if the CQL type is a tuple, the registry will generate a codec automatically).- Specified by:
getTupleValue
in interfaceGettableByIndexData
- Parameters:
i
- the index (0 <= i < size()
) to retrieve.- Returns:
- the value of the
i
th element as a tuple value. If the value is NULL, thennull
will be returned.
-
getObject
public java.lang.Object getObject(int i)
Returns thei
th value as the Java type matching its CQL type.This method uses the
CodecRegistry
to find the first codec that handles the underlying CQL type. The Java type of the returned object will be determined by the codec that was selected.Use this method to dynamically inspect elements when types aren't known in advance, for instance if you're writing a generic row logger. If you know the target Java type, it is generally preferable to use typed getters, such as the ones for built-in types (
GettableByIndexData.getBool(int)
,GettableByIndexData.getInt(int)
, etc.), orGettableByIndexData.get(int, Class)
andGettableByIndexData.get(int, TypeToken)
for custom types.- Specified by:
getObject
in interfaceGettableByIndexData
- Parameters:
i
- the index to retrieve.- Returns:
- the value of the
i
th value as the Java type matching its CQL type. - See Also:
CodecRegistry.codecFor(DataType)
-
get
public <T> T get(int i, java.lang.Class<T> targetClass)
Description copied from interface:GettableByIndexData
Returns thei
th value converted to the given Java type.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to the given Java type.If the target type is generic, use
GettableByIndexData.get(int, TypeToken)
.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByIndexData
- Parameters:
i
- the index to retrieve.targetClass
- The Java type the value should be converted to.- Returns:
- the value of the
i
th value converted to the given Java type.
-
get
public <T> T get(int i, com.google.common.reflect.TypeToken<T> targetType)
Description copied from interface:GettableByIndexData
Returns thei
th value converted to the given Java type.This method uses the
CodecRegistry
to find a codec to convert the underlying CQL type to the given Java type.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByIndexData
- Parameters:
i
- the index to retrieve.targetType
- The Java type the value should be converted to.- Returns:
- the value of the
i
th value converted to the given Java type.
-
get
public <T> T get(int i, TypeCodec<T> codec)
Description copied from interface:GettableByIndexData
Returns thei
th value converted using the givenTypeCodec
.This method entirely bypasses the
CodecRegistry
and forces the driver to use the given codec instead. This can be useful if the codec would collide with a previously registered one, or if you want to use the codec just once without registering it.It is the caller's responsibility to ensure that the given codec
accepts
the underlying CQL type; failing to do so may result inInvalidTypeException
s being thrown.Implementation note: the actual object returned by this method will depend on the
codec
being used; therefore, callers should make no assumptions concerning its mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQLNULL
values is also codec-dependent; by default, a CQLNULL
value translates tonull
for simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.- Specified by:
get
in interfaceGettableByIndexData
- Parameters:
i
- the index to retrieve.codec
- TheTypeCodec
to use to deserialize the value; may not benull
.- Returns:
- the value of the
i
th value converted using the givenTypeCodec
.
-
-