public class DataType extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DataType.Name
The CQL type 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)
Deserialize a value of this type from the provided bytes.
|
boolean |
equals(Object o) |
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.
|
int |
hashCode() |
static DataType |
inet()
Returns the INET type.
|
boolean |
isCollection()
Returns whether this type is a collection one, i.e.
|
static DataType |
list(DataType elementType)
Returns the type of lists of
elementType elements. |
static DataType |
map(DataType keyType,
DataType valueType)
Returns the type of maps of
keyType to valueType elements. |
ByteBuffer |
parse(String value)
Parses a string value for the type this object represent, returning its
Cassandra binary representation.
|
ByteBuffer |
serialize(Object value)
Serialize a value of this type to bytes.
|
static DataType |
set(DataType elementType)
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.
|
String |
toString() |
static DataType |
uuid()
Returns the UUID type.
|
static DataType |
varchar()
Returns the VARCHAR type.
|
static DataType |
varint()
Returns the VARINT type.
|
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)
elementType
elements.elementType
- the type of the list elements.elementType
elements.public static DataType set(DataType elementType)
elementType
elements.elementType
- the type of the set elements.elementType
elements.public static DataType map(DataType keyType, DataType valueType)
keyType
to valueType
elements.keyType
- the type of the map keys.valueType
- the type of the map values.keyType
to valueType
elements.public static DataType custom(String typeClassName)
A custom type is defined by the name of the class used on the Cassandra
side to implement it. Note that the support for custom type by the
driver is limited: values of a custom type won't be interpreted by the
driver in any way. They will thus be expected (by BoundStatement.setBytesUnsafe(int, java.nio.ByteBuffer)
and returned (by Row.getBytesUnsafe(int)
) as ByteBuffer.
The use of custom types is rarely useful and is thus not encouraged.
Also note that currently, the class implementing the custom type server side must be present in the driver classpath (this restriction should hopefully lifted at some point).
typeClassName
- the server-side class name for the type.typeClassName
.public DataType.Name getName()
public List<DataType> getTypeArguments()
Note that only the collection types (LIST, MAP, SET) have type arguments. For the other types, this will return an empty list.
For the collection types:
public String getCustomTypeClassName()
null
for any other type.public ByteBuffer parse(String value)
value
- the value to parse.value
.InvalidTypeException
- if value
is not a valid string
representation for this type. Please note that values for custom types
can never be parsed and 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)
The actual format of the resulting bytes will correspond to the Cassandra encoding for this type.
value
- the value to serialize.null
if value
is null.InvalidTypeException
- if value
is not a valid object
for this DataType
.public Object deserialize(ByteBuffer bytes)
The format of bytes
must correspond to the Cassandra
encoding for this type.
bytes
- bytes holding the value to deserialize.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 implementation can generally be ignored).InvalidTypeException
- if bytes
is not a valid
encoding of an object of this DataType
.Copyright © 2014. All Rights Reserved.