Example usage for org.apache.cassandra.db.marshal ListType getSerializer

List of usage examples for org.apache.cassandra.db.marshal ListType getSerializer

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal ListType getSerializer.

Prototype

public ListSerializer<T> getSerializer() 

Source Link

Usage

From source file:com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.java

License:Apache License

/**
 * Sets the element collection list.//from   ww w .j  a  v a2s. c om
 * 
 * @param listType
 *            the cql column metadata
 * @param thriftColumnValue
 *            the thrift column value
 * @param entity
 *            the entity
 * @param field
 *            the field
 * @param metaModel
 *            the meta model
 * @param embeddedObject
 *            the embedded object
 * @return the object
 */
private Object setElementCollectionList(ListType listType, ByteBuffer thriftColumnValue, Object entity,
        Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) {

    ListSerializer listSerializer = listType.getSerializer();
    Collection outputCollection = new ArrayList();
    if (useNativeProtocol2) {
        outputCollection.addAll((Collection) listSerializer.deserializeForNativeProtocol(thriftColumnValue, 2));
    } else {
        outputCollection.addAll((Collection) listSerializer.deserialize(thriftColumnValue));
    }

    UserType usertype = (UserType) listType.getElementsType();
    Collection result = new ArrayList();
    Iterator collectionItems = outputCollection.iterator();
    while (collectionItems.hasNext()) {
        Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass);
        Object value = populateEmbeddedRecursive((ByteBuffer) collectionItems.next(), usertype.allTypes(),
                usertype.fieldNames(), embeddedObject, metaModel);
        result.add(value);
    }
    PropertyAccessorHelper.set(entity, field, result);
    return entity;
}