datastax/java-driver — pull request #180 by flarcher (2014-06-12 15:24:00+00:00)
Title: User Defined Types (outside a collection) for 'cassandra-driver-core'

Hello,

It adds a better support of UDT (User Defined Type) into the core of the C* java driver ; With this change, we can retrieve easily a UDT value from a 'Row' instance.

Simple usage example :
----------------------

Having the 'address' example :

CREATE TYPE address ( street text, city text, zip int );

With the current version of the C* java driver I can do :

Row row = resultSet.one();
ByteBuffer udtValue = row.getUnsafeBytes("address_col_name");
// What should I do next ?

And my modifications make possible the following :

Row row = resultSet.one();
UDTValue address = row.getUDT("address_col_name"); // New method
// address is not a resultSet's row but represents the UDT value as a Row
String street = address.get("street");
int zipCode = address.get("zip");
// And so on ...

UDTValue is a new class that implements the Row interface in order to access columns of a value of a UDT.

Features :
----------

* It works with UDTs having native types (see above)
* It works with a UDT that has another UDT (recursively)
* We can retrieve collections that are defined in a UDT

Limitations :
-------------

* There is no support for collections that contain a UDT ; I will probably work on this in the future (if not implemented in the meantime). See the 'address' example of http://www.datastax.com/dev/blog/cql-in-2-1 with the column 'addresses' from table 'user_profiles'. Is also related to the discussion here : https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/-RwaSNgmQNQ

Modifications :
---------------

Here are a brief description of my modifications :

* New UDTValue class
* Row ; I added the following methods ;

public UDTValue getUDT(int i);
public UDTValue getUDT(String name);

* ArrayBackedRow ; Implementation of new methods of Row
* CassandraTypeParser ; Parsing of the java custom type class name and its parameters in order to get UDT's columns' definitions
* TypeCodec.CollectionCodec ; Abstract implementation for collections' codecs that makes possible to handle the (de-)serialization of collections using the version 3 of the native interface. See https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/Om75DhUkSs0 for more information about the reason of the change
* TypeCodec.UserDefinedTypeCodec ; (de-)serialization of a UDT's value : 'ByteBuffer <=> List'

About testing :
---------------

I created the new test class 'UserDefinedTypeTest' about the new features describes above. I order to run it, I installed 'ccm-master' locally. But I could not run my tests in the project 'cassandra-driver-core' using 'mvn clean install -P short'. I asked for help here : https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/VYbcKMqS--M .

However, I added all these tests in another project that uses my modified 'C* java driver version 2.1-SNAPSHOT' and a classic install of C* 2.1-rc1 on localhost. From that project of mine, all tests are successfull.