Search in sources :

Example 6 with UserType

use of com.datastax.driver.core.UserType in project jnosql-diana-driver by eclipse.

the class CassandraConverter method getUDT.

private static UDT getUDT(String name, UDTValue udtValue) {
    List<Column> columns = new ArrayList<>();
    UserType type = udtValue.getType();
    for (String fieldName : type.getFieldNames()) {
        DataType fieldType = type.getFieldType(fieldName);
        Object elementValue = udtValue.get(fieldName, CODE_REGISTRY.codecFor(fieldType));
        if (elementValue != null) {
            columns.add(Column.of(fieldName, elementValue));
        }
    }
    return UDT.builder(type.getTypeName()).withName(name).addUDT(columns).build();
}
Also used : Column(org.jnosql.diana.api.column.Column) ArrayList(java.util.ArrayList) DataType(com.datastax.driver.core.DataType) UserType(com.datastax.driver.core.UserType)

Example 7 with UserType

use of com.datastax.driver.core.UserType in project jnosql-diana-driver by eclipse.

the class QueryUtils method insertUDT.

private static void insertUDT(UDT udt, String keyspace, Session session, Insert insert) {
    UserType userType = session.getCluster().getMetadata().getKeyspace(keyspace).getUserType(udt.getUserType());
    Iterable elements = Iterable.class.cast(udt.get());
    Object udtValue = getUdtValue(userType, elements);
    insert.value(getName(udt), udtValue);
}
Also used : UserType(com.datastax.driver.core.UserType)

Aggregations

UserType (com.datastax.driver.core.UserType)7 UDTValue (com.datastax.driver.core.UDTValue)4 TypeCodec (com.datastax.driver.core.TypeCodec)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CodecRegistry (com.datastax.driver.core.CodecRegistry)1 DataType (com.datastax.driver.core.DataType)1 GettableByIndexData (com.datastax.driver.core.GettableByIndexData)1 SimpleStatement (com.datastax.driver.core.SimpleStatement)1 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Schema (org.apache.avro.Schema)1 Field (org.apache.gora.cassandra.bean.Field)1 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)1 GoraException (org.apache.gora.util.GoraException)1 Column (org.jnosql.diana.api.column.Column)1 DatastaxColumnKey (org.simpleflatmapper.datastax.DatastaxColumnKey)1