public abstract class AbstractGettableData extends Object implements GettableData
Modifier and Type | Field and Description |
---|---|
protected ProtocolVersion |
protocolVersion |
Modifier | Constructor and Description |
---|---|
protected |
AbstractGettableData(ProtocolVersion protocolVersion)
Creates a new AbstractGettableData object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkType(int i,
DataType.Name actual) |
protected void |
checkType(int i,
DataType.Name actual1,
DataType.Name actual2) |
protected void |
checkType(int i,
DataType.Name actual1,
DataType.Name actual2,
DataType.Name actual3) |
protected <T> TypeCodec<T> |
codecFor(int i) |
protected <T> TypeCodec<T> |
codecFor(int i,
Class<T> javaClass) |
protected <T> TypeCodec<T> |
codecFor(int i,
T value) |
protected <T> TypeCodec<T> |
codecFor(int i,
com.google.common.reflect.TypeToken<T> javaType) |
<T> T |
get(int i,
Class<T> targetClass)
Returns the
i th value converted to the given Java type. |
<T> T |
get(int i,
TypeCodec<T> codec)
Returns the
i th value converted using the given TypeCodec . |
<T> T |
get(int i,
com.google.common.reflect.TypeToken<T> targetType)
Returns the
i th value converted to the given Java type. |
<T> T |
get(String name,
Class<T> targetClass)
Returns the value for
name converted to the given Java type. |
<T> T |
get(String name,
TypeCodec<T> codec)
Returns the value for
name converted using the given TypeCodec . |
<T> T |
get(String name,
com.google.common.reflect.TypeToken<T> targetType)
Returns the value for
name converted to the given Java type. |
boolean |
getBool(int i)
Returns the
i th value as a boolean. |
boolean |
getBool(String name)
Returns the value for
name as a boolean. |
byte |
getByte(int i)
Returns the
i th value as a byte. |
byte |
getByte(String name)
Returns the value for
name as a byte. |
ByteBuffer |
getBytes(int i)
Returns the
i th value as a byte array. |
ByteBuffer |
getBytes(String name)
Returns the value for
name as a byte array. |
ByteBuffer |
getBytesUnsafe(int i)
Returns the
i th value as a ByteBuffer. |
ByteBuffer |
getBytesUnsafe(String name)
Returns the value for
name as a ByteBuffer. |
protected abstract CodecRegistry |
getCodecRegistry() |
LocalDate |
getDate(int i)
Returns the
i th value as a date (without time). |
LocalDate |
getDate(String name)
Returns the value for
name as a date (without time). |
BigDecimal |
getDecimal(int i)
Returns the
i th value as a variable length decimal. |
BigDecimal |
getDecimal(String name)
Returns the value for
name as a variable length decimal. |
double |
getDouble(int i)
Returns the
i th value as a double. |
double |
getDouble(String name)
Returns the value for
name as a double. |
float |
getFloat(int i)
Returns the
i th value as a float. |
float |
getFloat(String name)
Returns the value for
name as a float. |
protected abstract int |
getIndexOf(String name)
Returns the index corresponding to a given name.
|
InetAddress |
getInet(int i)
Returns the
i th value as an InetAddress. |
InetAddress |
getInet(String name)
Returns the value for
name as an InetAddress. |
int |
getInt(int i)
Returns the
i th value as an integer. |
int |
getInt(String name)
Returns the value for
name as an integer. |
<T> List<T> |
getList(int i,
Class<T> elementsClass)
Returns the
i th value as a list. |
<T> List<T> |
getList(int i,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the
i th value as a list. |
<T> List<T> |
getList(String name,
Class<T> elementsClass)
Returns the value for
name as a list. |
<T> List<T> |
getList(String name,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the value for
name as a list. |
long |
getLong(int i)
Returns the
i th value as a long. |
long |
getLong(String name)
Returns the value for
name as a long. |
<K,V> Map<K,V> |
getMap(int i,
Class<K> keysClass,
Class<V> valuesClass)
Returns the
i th value as a map. |
<K,V> Map<K,V> |
getMap(int i,
com.google.common.reflect.TypeToken<K> keysType,
com.google.common.reflect.TypeToken<V> valuesType)
Returns the
i th value as a map. |
<K,V> Map<K,V> |
getMap(String name,
Class<K> keysClass,
Class<V> valuesClass)
Returns the value for
name as a map. |
<K,V> Map<K,V> |
getMap(String name,
com.google.common.reflect.TypeToken<K> keysType,
com.google.common.reflect.TypeToken<V> valuesType)
Returns the value for
name as a map. |
protected abstract String |
getName(int i)
Returns the name corresponding to the value at index
i . |
Object |
getObject(int i)
Returns the
i th value as the Java type matching its CQL type. |
Object |
getObject(String name)
Returns the value for
name as the Java type matching its CQL type. |
<T> Set<T> |
getSet(int i,
Class<T> elementsClass)
Returns the
i th value as a set. |
<T> Set<T> |
getSet(int i,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the
i th value as a set. |
<T> Set<T> |
getSet(String name,
Class<T> elementsClass)
Returns the value for
name as a set. |
<T> Set<T> |
getSet(String name,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the value for
name as a set. |
short |
getShort(int i)
Returns the
i th value as a short. |
short |
getShort(String name)
Returns the value for
name as a short. |
String |
getString(int i)
Returns the
i th value as a string. |
String |
getString(String name)
Returns the value for
name as a string. |
long |
getTime(int i)
Returns the
i th value as a long in nanoseconds since midnight. |
long |
getTime(String name)
Returns the value for
name as a long in nanoseconds since midnight. |
Date |
getTimestamp(int i)
Returns the
i th value as a date. |
Date |
getTimestamp(String name)
Returns the value for
name as a date. |
TupleValue |
getTupleValue(int i)
Return the
i th value as a tuple value. |
TupleValue |
getTupleValue(String name)
Return the value for
name as a tuple value. |
protected abstract DataType |
getType(int i)
Returns the type for the value at index
i . |
UDTValue |
getUDTValue(int i)
Return the
i th value as a UDT value. |
UDTValue |
getUDTValue(String name)
Return the value for
name as a UDT value. |
UUID |
getUUID(int i)
Returns the
i th value as a UUID. |
UUID |
getUUID(String name)
Returns the value for
name as a UUID. |
protected abstract ByteBuffer |
getValue(int i)
Returns the value at index
i . |
BigInteger |
getVarint(int i)
Returns the
i th value as a variable length integer. |
BigInteger |
getVarint(String name)
Returns the value for
name as a variable length integer. |
boolean |
isNull(int i)
Returns whether the
i th value is NULL. |
boolean |
isNull(String name)
Returns whether the value for
name is NULL. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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
protected final ProtocolVersion protocolVersion
protected AbstractGettableData(ProtocolVersion protocolVersion)
protocolVersion
- the protocol version in which values returned
by getValue(int)
will be returned. This must be a protocol version
supported by this driver. In general, the correct value will be the
value returned by ProtocolOptions.getProtocolVersion()
.IllegalArgumentException
- if protocolVersion
is not a valid protocol version.protected abstract int getIndexOf(String name)
name
- the name for which to return the index of.name
.IllegalArgumentException
- if name
is not valid name for this object.public boolean isNull(String name)
name
is NULL.isNull
in interface GettableByNameData
name
- the name to check.name
is NULL.public boolean getBool(String name)
name
as a boolean.getBool
in interface GettableByNameData
name
- the name to retrieve.name
. If the value is NULL,
false
is returned.public byte getByte(String name)
name
as a byte.getByte
in interface GettableByNameData
name
- the name to retrieve.name
as a byte. If the value is NULL,
0
is returned.public short getShort(String name)
name
as a short.getShort
in interface GettableByNameData
name
- the name to retrieve.name
as a short. If the value is NULL,
0
is returned.public int getInt(String name)
name
as an integer.getInt
in interface GettableByNameData
name
- the name to retrieve.name
as an integer. If the value is NULL,
0
is returned.public long getLong(String name)
name
as a long.getLong
in interface GettableByNameData
name
- the name to retrieve.name
as a long. If the value is NULL,
0L
is returned.public Date getTimestamp(String name)
name
as a date.getTimestamp
in interface GettableByNameData
name
- the name to retrieve.name
as a date. If the value is NULL,
null
is returned.public LocalDate getDate(String name)
name
as a date (without time).getDate
in interface GettableByNameData
name
- the name to retrieve.name
as a date. If the value is NULL,
null
is returned.public long getTime(String name)
name
as a long in nanoseconds since midnight.getTime
in interface GettableByNameData
name
- the name to retrieve.name
as a long. If the value is NULL,
0L
is returned.public float getFloat(String name)
name
as a float.getFloat
in interface GettableByNameData
name
- the name to retrieve.name
as a float. If the value is NULL,
0.0f
is returned.public double getDouble(String name)
name
as a double.getDouble
in interface GettableByNameData
name
- the name to retrieve.name
as a double. If the value is NULL,
0.0
is returned.public ByteBuffer getBytesUnsafe(String name)
name
as a ByteBuffer.
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.getBytesUnsafe
in interface GettableByNameData
name
- the name to retrieve.name
as a ByteBuffer. If the value is NULL,
null
is returned.public ByteBuffer getBytes(String name)
name
as a byte array.
Note that this method validate that the column is of type BLOB. If you want to retrieve
the bytes for any type, use GettableByNameData.getBytesUnsafe(String)
instead.
getBytes
in interface GettableByNameData
name
- the name to retrieve.name
as a byte array. If the value is NULL,
null
is returned.public String getString(String name)
name
as a string.getString
in interface GettableByNameData
name
- the name to retrieve.name
as a string. If the value is NULL,
null
is returned.public BigInteger getVarint(String name)
name
as a variable length integer.getVarint
in interface GettableByNameData
name
- the name to retrieve.name
as a variable length integer.
If the value is NULL, null
is returned.public BigDecimal getDecimal(String name)
name
as a variable length decimal.getDecimal
in interface GettableByNameData
name
- the name to retrieve.name
as a variable length decimal.
If the value is NULL, null
is returned.public UUID getUUID(String name)
name
as a UUID.getUUID
in interface GettableByNameData
name
- the name to retrieve.name
as a UUID.
If the value is NULL, null
is returned.public InetAddress getInet(String name)
name
as an InetAddress.getInet
in interface GettableByNameData
name
- the name to retrieve.name
as an InetAddress.
If the value is NULL, null
is returned.public <T> List<T> getList(String name, Class<T> elementsClass)
name
as a list.
If the type of the elements is generic, use GettableByNameData.getList(String, TypeToken)
.
getList
in interface GettableByNameData
name
- the name to retrieve.elementsClass
- the class for the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.public <T> List<T> getList(String name, com.google.common.reflect.TypeToken<T> elementsType)
name
as a list.
Use this variant with nested collections, which produce a generic element type:
List<List<String>> l = row.getList("theColumn", new TypeToken<List<String>>() {});
getList
in interface GettableByNameData
name
- the name to retrieve.elementsType
- the type for the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.public <T> Set<T> getSet(String name, Class<T> elementsClass)
name
as a set.
If the type of the elements is generic, use GettableByNameData.getSet(String, TypeToken)
.
getSet
in interface GettableByNameData
name
- the name to retrieve.elementsClass
- the class for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.public <T> Set<T> getSet(String name, com.google.common.reflect.TypeToken<T> elementsType)
name
as a set.
Use this variant with nested collections, which produce a generic element type:
Set<List<String>> l = row.getSet("theColumn", new TypeToken<List<String>>() {});
getSet
in interface GettableByNameData
name
- the name to retrieve.elementsType
- the type for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.public <K,V> Map<K,V> getMap(String name, Class<K> keysClass, Class<V> valuesClass)
name
as a map.
If the type of the keys and/or values is generic, use GettableByNameData.getMap(String, TypeToken, TypeToken)
.
getMap
in interface GettableByNameData
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.name
as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.public <K,V> Map<K,V> getMap(String name, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
name
as a map.
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>>() {});
getMap
in interface GettableByNameData
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.name
as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.public UDTValue getUDTValue(String name)
name
as a UDT value.getUDTValue
in interface GettableByNameData
name
- the name to retrieve.name
as a UDT value. If the value is NULL,
then null
will be returned.public TupleValue getTupleValue(String name)
name
as a tuple value.getTupleValue
in interface GettableByNameData
name
- the name to retrieve.name
as a tuple value. If the value is NULL,
then null
will be returned.public Object getObject(String name)
name
as the Java type matching its CQL type.
This method uses the default codec for the underlying CQL type
to perform deserialization, and is safe to be used
as long as only default codecs are in use.
If a second, custom codec for the same CQL type is registered, which one will
be used is unspecified; in such cases, it is preferable to use
the more deterministic methods GettableByNameData.get(String, Class)
or GettableByNameData.get(String, TypeToken)
instead.
getObject
in interface GettableByNameData
name
- the name to retrieve.i
th value 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.public <T> T get(String name, Class<T> targetClass)
name
converted to the given Java type.
A suitable TypeCodec
instance for for the underlying CQL type and targetClass
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of GettableByNameData.getObject(String)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
get
in interface GettableByNameData
name
- the name to retrieve.targetClass
- The Java type the value should be converted to.name
value converted to the given Java type.
If the CQL value is NULL
, then null
is returned.public <T> T get(String name, com.google.common.reflect.TypeToken<T> targetType)
name
converted to the given Java type.
A suitable TypeCodec
instance for for the underlying CQL type and targetType
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of GettableByNameData.getObject(String)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
get
in interface GettableByNameData
name
- the name to retrieve.targetType
- The Java type the value should be converted to.name
value converted to the given Java type.
If the CQL value is NULL
, then null
is returned.public <T> T get(String name, TypeCodec<T> codec)
name
converted using the given TypeCodec
.
Note that this method allows to entirely bypass the CodecRegistry
currently in use
and forces the driver to use the given codec instead.
It is the caller's responsibility to ensure that the given codec accepts
the underlying CQL type; failing to do so may result in InvalidTypeException
s being thrown.
get
in interface GettableByNameData
name
- the name to retrieve.codec
- The TypeCodec
to use to deserialize the value; may not be null
.i
th value converted using the given TypeCodec
.protected abstract DataType getType(int i)
i
.i
- the index of the type to fetch.i
.IndexOutOfBoundsException
- if i
is not a valid index.protected abstract String getName(int i)
i
.i
- the index of the name to fetch.i
.IndexOutOfBoundsException
- if i
is not a valid index.protected abstract ByteBuffer getValue(int i)
i
.i
- the index to fetch.i
.IndexOutOfBoundsException
- if i
is not a valid index.protected abstract CodecRegistry getCodecRegistry()
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, T value)
protected void checkType(int i, DataType.Name actual)
protected void checkType(int i, DataType.Name actual1, DataType.Name actual2)
protected void checkType(int i, DataType.Name actual1, DataType.Name actual2, DataType.Name actual3)
public boolean isNull(int i)
i
th value is NULL.isNull
in interface GettableByIndexData
i
- the index (0 <= i < size()
) of the value to check.i
th value is NULL.public boolean getBool(int i)
i
th value as a boolean.getBool
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element. If the
value is NULL, false
is returned.public byte getByte(int i)
i
th value as a byte.getByte
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a byte. If the
value is NULL, 0
is returned.public short getShort(int i)
i
th value as a short.getShort
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a short. If the
value is NULL, 0
is returned.public int getInt(int i)
i
th value as an integer.getInt
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as an integer. If the
value is NULL, 0
is returned.public long getLong(int i)
i
th value as a long.getLong
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a long. If the
value is NULL, 0L
is returned.public Date getTimestamp(int i)
i
th value as a date.getTimestamp
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a data. If the
value is NULL, null
is returned.public LocalDate getDate(int i)
i
th value as a date (without time).getDate
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as an date. If the
value is NULL, null
is returned.public long getTime(int i)
i
th value as a long in nanoseconds since midnight.getTime
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a long. If the
value is NULL, 0L
is returned.public float getFloat(int i)
i
th value as a float.getFloat
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a float. If the
value is NULL, 0.0f
is returned.public double getDouble(int i)
i
th value as a double.getDouble
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a double. If the
value is NULL, 0.0
is returned.public ByteBuffer getBytesUnsafe(int i)
i
th value as a ByteBuffer.
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.getBytesUnsafe
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a ByteBuffer. If the
value is NULL, null
is returned.public ByteBuffer getBytes(int i)
i
th value as a byte array.
Note that this method validate that the column is of type BLOB. If you want to retrieve
the bytes for any type, use GettableByIndexData.getBytesUnsafe(int)
instead.
getBytes
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a byte array. If the
value is NULL, null
is returned.public String getString(int i)
i
th value as a string.getString
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a string. If the
value is NULL, null
is returned.public BigInteger getVarint(int i)
i
th value as a variable length integer.getVarint
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a variable
length integer. If the value is NULL, null
is returned.public BigDecimal getDecimal(int i)
i
th value as a variable length decimal.getDecimal
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a variable
length decimal. If the value is NULL, null
is returned.public UUID getUUID(int i)
i
th value as a UUID.getUUID
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a UUID.
If the value is NULL, null
is returned.public InetAddress getInet(int i)
i
th value as an InetAddress.getInet
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as an InetAddress.
If the value is NULL, null
is returned.public <T> List<T> getList(int i, Class<T> elementsClass)
i
th value as a list.
If the type of the elements is generic, use GettableByIndexData.getList(int, TypeToken)
.
getList
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.public <T> List<T> getList(int i, com.google.common.reflect.TypeToken<T> elementsType)
i
th value as a list.
Use this variant with nested collections, which produce a generic element type:
List<List<String>> l = row.getList(1, new TypeToken<List<String>>() {});
getList
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type of the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.public <T> Set<T> getSet(int i, Class<T> elementsClass)
i
th value as a set.
If the type of the elements is generic, use GettableByIndexData.getSet(int, TypeToken)
.
getSet
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.public <T> Set<T> getSet(int i, com.google.common.reflect.TypeToken<T> elementsType)
i
th value as a set.
Use this variant with nested collections, which produce a generic element type:
Set<List<String>> l = row.getSet(1, new TypeToken<List<String>>() {});
getSet
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.public <K,V> Map<K,V> getMap(int i, Class<K> keysClass, Class<V> valuesClass)
i
th value as a map.
If the type of the keys and/or values is generic, use GettableByIndexData.getMap(int, TypeToken, TypeToken)
.
getMap
in interface GettableByIndexData
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.i
th element as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.public <K,V> Map<K,V> getMap(int i, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
i
th value as a map.
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>>() {});
getMap
in interface GettableByIndexData
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.i
th element as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.public UDTValue getUDTValue(int i)
i
th value as a UDT value.getUDTValue
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a UDT value. If the value is NULL,
then null
will be returned.public TupleValue getTupleValue(int i)
i
th value as a tuple value.getTupleValue
in interface GettableByIndexData
i
- the index (0 <= i < size()
) to retrieve.i
th element as a tuple value. If the value is NULL,
then null
will be returned.public Object getObject(int i)
i
th value as the Java type matching its CQL type.
This method uses the default codec for the underlying CQL type
to perform deserialization, and is safe to be used
as long as only default codecs are in use.
If a second, custom codec for the same CQL type is registered, which one will
be used is unspecified; in such cases, it is preferable to use
the more deterministic methods GettableByIndexData.get(int, Class)
or GettableByIndexData.get(int, TypeToken)
instead.
getObject
in interface GettableByIndexData
i
- the index to retrieve.i
th value 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.public <T> T get(int i, Class<T> targetClass)
GettableByIndexData
i
th value converted to the given Java type.
A suitable TypeCodec
instance for the underlying CQL type and targetClass
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of GettableByIndexData.getObject(int)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
get
in interface GettableByIndexData
i
- the index to retrieve.targetClass
- The Java type the value should be converted to.i
th value converted to the given Java type.
If the CQL value is NULL
, this method will return null
for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.public <T> T get(int i, com.google.common.reflect.TypeToken<T> targetType)
GettableByIndexData
i
th value converted to the given Java type.
A suitable TypeCodec
instance for the underlying CQL type and targetType
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of GettableByIndexData.getObject(int)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
get
in interface GettableByIndexData
i
- the index to retrieve.targetType
- The Java type the value should be converted to.i
th value converted to the given Java type.
If the CQL value is NULL
, the default set of codecs will return null
for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.public <T> T get(int i, TypeCodec<T> codec)
GettableByIndexData
i
th value converted using the given TypeCodec
.
Note that this method allows to entirely bypass the CodecRegistry
currently in use
and forces the driver to use the given codec instead.
It is the caller's responsibility to ensure that the given codec accepts
the underlying CQL type; failing to do so may result in InvalidTypeException
s being thrown.
get
in interface GettableByIndexData
i
- the index to retrieve.codec
- The TypeCodec
to use to deserialize the value; may not be null
.i
th value converted using the given TypeCodec
.Copyright © 2012–2015. All rights reserved.