Modifier and Type | Class and Description |
---|---|
static class |
DataType.Name
The CQL type name.
|
Modifier and Type | Field and Description |
---|---|
protected DataType.Name |
name |
Modifier | Constructor and Description |
---|---|
protected |
DataType(DataType.Name name) |
Modifier and Type | Method and Description |
---|---|
static Set<DataType> |
allPrimitiveTypes()
Returns a set of all the primitive types, where primitive types are
defined as the types that don't have type arguments (that is excluding
lists, sets, and maps).
|
static DataType |
ascii()
Returns the ASCII type.
|
Class<?> |
asJavaClass()
Returns the Java Class corresponding to this type.
|
static DataType |
bigint()
Returns the BIGINT type.
|
static DataType |
blob()
Returns the BLOB type.
|
static DataType |
cboolean()
Returns the BOOLEAN type.
|
static DataType |
cdouble()
Returns the DOUBLE type.
|
static DataType |
cfloat()
Returns the FLOAT type.
|
static DataType |
cint()
Returns the INT type.
|
static DataType |
counter()
Returns the COUNTER type.
|
static DataType |
custom(String typeClassName)
Returns a Custom type.
|
static DataType |
decimal()
Returns the DECIMAL type.
|
Object |
deserialize(ByteBuffer bytes)
Deprecated.
This method is provided for binary compatibility only. It is no longer supported, will be removed,
and simply throws
UnsupportedOperationException . Use deserialize(ByteBuffer, ProtocolVersion) instead. |
Object |
deserialize(ByteBuffer bytes,
int protocolVersion)
Deprecated.
This method is provided for backward compatibility. Use
deserialize(ByteBuffer, ProtocolVersion) instead. |
Object |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize a value of this type from the provided bytes using the given protocol version.
|
String |
format(Object value)
Format a Java object as an equivalent CQL value.
|
static DataType |
frozenList(DataType elementType)
Returns the type of frozen lists of
elementType elements. |
static DataType |
frozenMap(DataType keyType,
DataType valueType)
Returns the type of frozen maps of
keyType to valueType elements. |
static DataType |
frozenSet(DataType elementType)
Returns the type of frozen sets of
elementType elements. |
String |
getCustomTypeClassName()
Returns the server-side class name for a custom type.
|
DataType.Name |
getName()
Returns the name of that type.
|
List<DataType> |
getTypeArguments()
Returns the type arguments of this type.
|
static DataType |
inet()
Returns the INET type.
|
boolean |
isCollection()
Returns whether this type is a collection one, i.e.
|
abstract boolean |
isFrozen()
Returns whether this data type is frozen.
|
static DataType |
list(DataType elementType)
Returns the type of "not frozen" lists of
elementType elements. |
static DataType |
list(DataType elementType,
boolean frozen)
Returns the type of lists of
elementType elements. |
static DataType |
map(DataType keyType,
DataType valueType)
Returns the type of "not frozen" maps of
keyType to valueType elements. |
static DataType |
map(DataType keyType,
DataType valueType,
boolean frozen)
Returns the type of maps of
keyType to valueType elements. |
Object |
parse(String value)
Parses a string CQL value for the type this object represent, returning its
value as a Java object.
|
ByteBuffer |
serialize(Object value)
Deprecated.
This method is provided for binary compatibility only. It is no longer supported, will be removed,
and simply throws
UnsupportedOperationException . Use serialize(Object, ProtocolVersion) instead. |
ByteBuffer |
serialize(Object value,
int protocolVersion)
Deprecated.
This method is provided for backward compatibility. Use
serialize(Object, ProtocolVersion) instead. |
ByteBuffer |
serialize(Object value,
ProtocolVersion protocolVersion)
Serialize a value of this type to bytes, with the given protocol version.
|
static ByteBuffer |
serializeValue(Object value)
Deprecated.
This method is provided for binary compatibility only. It is no longer supported, will be removed,
and simply throws
UnsupportedOperationException . Use serializeValue(Object, ProtocolVersion) instead. |
static ByteBuffer |
serializeValue(Object value,
int protocolVersion)
Deprecated.
This method is provided for backward compatibility. Use
serializeValue(Object, ProtocolVersion) instead. |
static ByteBuffer |
serializeValue(Object value,
ProtocolVersion protocolVersion)
Serialize an object based on its java class.
|
static DataType |
set(DataType elementType)
Returns the type of "not frozen" sets of
elementType elements. |
static DataType |
set(DataType elementType,
boolean frozen)
Returns the type of sets of
elementType elements. |
static DataType |
text()
Returns the TEXT type.
|
static DataType |
timestamp()
Returns the TIMESTAMP type.
|
static DataType |
timeuuid()
Returns the TIMEUUID type.
|
static DataType |
uuid()
Returns the UUID type.
|
static DataType |
varchar()
Returns the VARCHAR type.
|
static DataType |
varint()
Returns the VARINT type.
|
protected final DataType.Name name
protected DataType(DataType.Name name)
public static DataType ascii()
public static DataType bigint()
public static DataType blob()
public static DataType cboolean()
public static DataType counter()
public static DataType decimal()
public static DataType cdouble()
public static DataType cfloat()
public static DataType inet()
public static DataType cint()
public static DataType text()
public static DataType timestamp()
public static DataType uuid()
public static DataType varchar()
public static DataType varint()
public static DataType timeuuid()
public static DataType list(DataType elementType, boolean frozen)
elementType
elements.elementType
- the type of the list elements.frozen
- whether the list is frozen.elementType
elements.public static DataType list(DataType elementType)
elementType
elements.
This is a shorthand for list(elementType, false);
.elementType
- the type of the list elements.elementType
elements.public static DataType frozenList(DataType elementType)
elementType
elements.
This is a shorthand for list(elementType, true);
.elementType
- the type of the list elements.elementType
elements.public static DataType set(DataType elementType, boolean frozen)
elementType
elements.elementType
- the type of the set elements.frozen
- whether the set is frozen.elementType
elements.public static DataType set(DataType elementType)
elementType
elements.
This is a shorthand for set(elementType, false);
.elementType
- the type of the set elements.elementType
elements.public static DataType frozenSet(DataType elementType)
elementType
elements.
This is a shorthand for set(elementType, true);
.elementType
- the type of the set elements.elementType
elements.public static DataType map(DataType keyType, DataType valueType, boolean frozen)
keyType
to valueType
elements.keyType
- the type of the map keys.valueType
- the type of the map values.frozen
- whether the map is frozen.keyType
to valueType
elements.public static DataType map(DataType keyType, DataType valueType)
keyType
to valueType
elements.
This is a shorthand for map(keyType, valueType, false);
.keyType
- the type of the map keys.valueType
- the type of the map values.keyType
to valueType
elements.public static DataType frozenMap(DataType keyType, DataType valueType)
keyType
to valueType
elements.
This is a shorthand for map(keyType, valueType, true);
.keyType
- the type of the map keys.valueType
- the type of the map values.keyType
to valueType
elements.public static DataType custom(String typeClassName)
BoundStatement.setBytesUnsafe(int, java.nio.ByteBuffer)
and retrieved (by Row.getBytesUnsafe(int)
) as raw ByteBuffer.
The use of custom types is rarely useful and is thus not encouraged.typeClassName
- the server-side fully qualified class name for the type.typeClassName
.public DataType.Name getName()
public abstract boolean isFrozen()
public List<DataType> getTypeArguments()
public String getCustomTypeClassName()
null
for any other type.public Object parse(String value)
value
- the value to parse.value
. If value == null
, then
null
is returned.InvalidTypeException
- if value
is not a valid CQL string
representation for this type. Please note that values for custom types
can never be parsed and will always return this exception.public String format(Object value)
value
- the value to format.value
.InvalidTypeException
- if value
does not correspond to
a CQL value (known by the driver). Please note that for custom types this
method will always return this exception.public boolean isCollection()
public Class<?> asJavaClass()
getName().asJavaClass()
.DataType.Name.asJavaClass()
public static Set<DataType> allPrimitiveTypes()
public ByteBuffer serialize(Object value, ProtocolVersion protocolVersion)
value
- the value to serialize.protocolVersion
- the protocol version to use when serializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).null
if value
is null.InvalidTypeException
- if value
is not a valid object
for this DataType
.@Deprecated public ByteBuffer serialize(Object value, int protocolVersion)
serialize(Object, ProtocolVersion)
instead.IllegalArgumentException
- if protocolVersion
does not correspond to any known version.@Deprecated public ByteBuffer serialize(Object value)
UnsupportedOperationException
. Use serialize(Object, ProtocolVersion)
instead.public Object deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
bytes
- bytes holding the value to deserialize.protocolVersion
- the protocol version to use when deserializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).this.asJavaClass()
).
Will return null
if either bytes
is null
or if
bytes.remaining() == 0
and this type has no value corresponding
to an empty byte buffer (the latter somewhat strange behavior is due to
the fact that for historical/technical reason, Cassandra types always
accept empty byte buffer as valid value of those type, and so we avoid
throwing an exception in that case. It is however highly discouraged to
store empty byte buffers for types for which it doesn't make sense, so
this detail can generally be ignored).InvalidTypeException
- if bytes
is not a valid
encoding of an object of this DataType
.public Object deserialize(ByteBuffer bytes, int protocolVersion)
deserialize(ByteBuffer, ProtocolVersion)
instead.IllegalArgumentException
- if protocolVersion
does not correspond to any known version.@Deprecated public Object deserialize(ByteBuffer bytes)
UnsupportedOperationException
. Use deserialize(ByteBuffer, ProtocolVersion)
instead.public static ByteBuffer serializeValue(Object value, ProtocolVersion protocolVersion)
serialize(java.lang.Object, com.datastax.driver.core.ProtocolVersion)
but with the difference that
the actual DataType
of the resulting value is inferred from the
java class of value
. The correspondence between CQL DataType
and java class used is the one induced by the method DataType.Name.asJavaClass()
.
Note that if you know the DataType
of value
, you should use
the serialize(java.lang.Object, com.datastax.driver.core.ProtocolVersion)
method instead as it is going to be faster.value
- the value to serialize.protocolVersion
- the protocol version to use when deserializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).null
if value
is null.IllegalArgumentException
- if value
is not of a type
corresponding to a CQL3 type, i.e. is not a Class that could be returned
by asJavaClass()
.@Deprecated public static ByteBuffer serializeValue(Object value, int protocolVersion)
serializeValue(Object, ProtocolVersion)
instead.IllegalArgumentException
- if protocolVersion
does not correspond to any known version.@Deprecated public static ByteBuffer serializeValue(Object value)
UnsupportedOperationException
. Use serializeValue(Object, ProtocolVersion)
instead.