public interface GettableByNameData
Modifier and Type | Method and Description |
---|---|
<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(String name)
Returns the value for
name as a boolean. |
byte |
getByte(String name)
Returns the value for
name as a byte. |
ByteBuffer |
getBytes(String name)
Returns the value for
name as a byte array. |
ByteBuffer |
getBytesUnsafe(String name)
Returns the value for
name as a ByteBuffer. |
LocalDate |
getDate(String name)
Returns the value for
name as a date (without time). |
BigDecimal |
getDecimal(String name)
Returns the value for
name as a variable length decimal. |
double |
getDouble(String name)
Returns the value for
name as a double. |
float |
getFloat(String name)
Returns the value for
name as a float. |
InetAddress |
getInet(String name)
Returns the value for
name as an InetAddress. |
int |
getInt(String name)
Returns the value for
name as an integer. |
<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(String name)
Returns the value for
name as a long. |
<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. |
Object |
getObject(String name)
Returns the value for
name as the Java type matching its CQL type. |
<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(String name)
Returns the value for
name as a short. |
String |
getString(String name)
Returns the value for
name as a string. |
long |
getTime(String name)
Returns the value for
name as a long in nanoseconds since midnight. |
Date |
getTimestamp(String name)
Returns the value for
name as a date. |
TupleValue |
getTupleValue(String name)
Return the value for
name as a tuple value. |
UDTValue |
getUDTValue(String name)
Return the value for
name as a UDT value. |
UUID |
getUUID(String name)
Returns the value for
name as a UUID. |
BigInteger |
getVarint(String name)
Returns the value for
name as a variable length integer. |
boolean |
isNull(String name)
Returns whether the value for
name is NULL. |
boolean isNull(String name)
name
is NULL.name
- the name to check.name
is NULL.IllegalArgumentException
- if name
is not valid name for this object.boolean getBool(String name)
name
as a boolean.name
- the name to retrieve.name
. If the value is NULL,
false
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type BOOLEAN.byte getByte(String name)
name
as a byte.name
- the name to retrieve.name
as a byte. If the value is NULL,
0
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type TINYINT.short getShort(String name)
name
as a short.name
- the name to retrieve.name
as a short. If the value is NULL,
0
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type SMALLINT.int getInt(String name)
name
as an integer.name
- the name to retrieve.name
as an integer. If the value is NULL,
0
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type INT.long getLong(String name)
name
as a long.name
- the name to retrieve.name
as a long. If the value is NULL,
0L
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value i
is not of type BIGINT or COUNTER.Date getTimestamp(String name)
name
as a date.name
- the name to retrieve.name
as a date. If the value is NULL,
null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type TIMESTAMP.LocalDate getDate(String name)
name
as a date (without time).name
- the name to retrieve.name
as a date. If the value is NULL,
null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type DATE.long getTime(String name)
name
as a long in nanoseconds since midnight.name
- the name to retrieve.name
as a long. If the value is NULL,
0L
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type TIME.float getFloat(String name)
name
as a float.name
- the name to retrieve.name
as a float. If the value is NULL,
0.0f
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type FLOAT.double getDouble(String name)
name
as a double.name
- the name to retrieve.name
as a double. If the value is NULL,
0.0
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type DOUBLE.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.name
- the name to retrieve.name
as a ByteBuffer. If the value is NULL,
null
is returned.IllegalArgumentException
- if name
is not valid name for this object.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 getBytesUnsafe(String)
instead.
name
- the name to retrieve.name
as a byte array. If the value is NULL,
null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value i
type is not of type BLOB.String getString(String name)
name
as a string.name
- the name to retrieve.name
as a string. If the value is NULL,
null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
type is none of:
VARCHAR, TEXT or ASCII.BigInteger getVarint(String name)
name
as a variable length integer.name
- the name to retrieve.name
as a variable length integer.
If the value is NULL, null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type VARINT.BigDecimal getDecimal(String name)
name
as a variable length decimal.name
- the name to retrieve.name
as a variable length decimal.
If the value is NULL, null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type DECIMAL.UUID getUUID(String name)
name
as a UUID.name
- the name to retrieve.name
as a UUID.
If the value is NULL, null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type
UUID or TIMEUUID.InetAddress getInet(String name)
name
as an InetAddress.name
- the name to retrieve.name
as an InetAddress.
If the value is NULL, null
is returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not of type
INET.<T> List<T> getList(String name, Class<T> elementsClass)
name
as a list.
If the type of the elements is generic, use getList(String, TypeToken)
.
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a list or if its
elements are not of class T
.<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>>() {});
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a list or if its
elements are not of class T
.<T> Set<T> getSet(String name, Class<T> elementsClass)
name
as a set.
If the type of the elements is generic, use getSet(String, TypeToken)
.
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a set or if its
elements are not of class T
.<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>>() {});
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a set or if its
elements are not of class T
.<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 getMap(String, TypeToken, TypeToken)
.
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a map, if its
keys are not of class K
or if its values are not of
class V
.<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>>() {});
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.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value name
is not a map, if its
keys are not of class K
or if its values are not of
class V
.UDTValue getUDTValue(String name)
name
as a UDT value.name
- the name to retrieve.name
as a UDT value. If the value is NULL,
then null
will be returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value i
is not a UDT value.TupleValue getTupleValue(String name)
name
as a tuple value.name
- the name to retrieve.name
as a tuple value. If the value is NULL,
then null
will be returned.IllegalArgumentException
- if name
is not valid name for this object.InvalidTypeException
- if value i
is not a tuple value.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 get(String, Class)
or get(String, TypeToken)
instead.
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.IllegalArgumentException
- if name
is not a valid name for this object.<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 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.
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.IllegalArgumentException
- if name
is not a valid name for this object.CodecNotFoundException
- if no TypeCodec
instance for targetClass
could be found
by the CodecRegistry
currently in use.<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 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.
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.IllegalArgumentException
- if name
is not a valid name for this object.CodecNotFoundException
- if no TypeCodec
instance for targetType
could be found
by the CodecRegistry
currently in use.<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.
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
.InvalidTypeException
- if the given codec does not accept
the underlying CQL type.IndexOutOfBoundsException
- if i
is not a valid index for this object.Copyright © 2012–2015. All rights reserved.