Example usage for org.apache.cassandra.db.marshal MapType getValuesType

List of usage examples for org.apache.cassandra.db.marshal MapType getValuesType

Introduction

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

Prototype

public AbstractType<V> getValuesType() 

Source Link

Usage

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

License:Apache License

/**
 * Sets the element collection map.//  ww  w.  j a  va  2 s  .c o  m
 * 
 * @param mapType
 *            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 setElementCollectionMap(MapType mapType, ByteBuffer thriftColumnValue, Object entity,
        Field field, MetamodelImpl metaModel, Class embeddedClass, boolean useNativeProtocol2) {

    Map result = new HashMap();
    MapSerializer mapSerializer = mapType.getSerializer();
    Map outputCollection = new HashMap();
    if (useNativeProtocol2) {
        outputCollection.putAll(mapSerializer.deserializeForNativeProtocol(thriftColumnValue, 2));
    } else {
        outputCollection.putAll((Map) mapSerializer.deserialize(thriftColumnValue));
    }

    UserType usertype = (UserType) mapType.getValuesType();

    for (Object key : outputCollection.keySet()) {
        Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass);
        Object value = populateEmbeddedRecursive((ByteBuffer) outputCollection.get(key), usertype.allTypes(),
                usertype.fieldNames(), embeddedObject, metaModel);
        result.put(key, value);
    }
    PropertyAccessorHelper.set(entity, field, result);
    return entity;
}