Example usage for org.apache.cassandra.db.marshal SetType getElementsType

List of usage examples for org.apache.cassandra.db.marshal SetType getElementsType

Introduction

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

Prototype

public AbstractType<T> getElementsType() 

Source Link

Usage

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

License:Apache License

/**
 * Sets the element collection set./*from w w  w. j a v  a  2  s.  c  o m*/
 * 
 * @param setType
 *            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 setElementCollectionSet(SetType setType, ByteBuffer thriftColumnValue, Object entity,
        Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) {

    SetSerializer setSerializer = setType.getSerializer();
    Collection outputCollection = new ArrayList();
    if (useNativeProtocol2) {
        outputCollection.addAll((Collection) setSerializer.deserializeForNativeProtocol(thriftColumnValue, 2));
    } else {
        outputCollection.addAll((Collection) setSerializer.deserialize(thriftColumnValue));
    }

    UserType usertype = (UserType) setType.getElementsType();
    Collection result = new HashSet();
    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;
}