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

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

Introduction

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

Prototype

public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException 

Source Link

Usage

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

License:Apache License

/**
 * Sets the element collection.//from   w  ww .  j  a  va 2  s  . com
 * 
 * @param entity
 *            the entity
 * @param thriftColumnValue
 *            the thrift column value
 * @param metaModel
 *            the meta model
 * @param attribute
 *            the attribute
 * @return the object
 */
private Object setElementCollection(Object entity, Object thriftColumnValue, MetamodelImpl metaModel,
        Attribute attribute) {
    String cqlColumnMetadata = null;
    Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types();
    for (Map.Entry<ByteBuffer, String> schemaType : schemaTypes.entrySet()) {

        String key = UTF8Serializer.instance.deserialize((schemaType.getKey()));
        if (key.equals(((AbstractAttribute) attribute).getJavaMember().getName())) {
            cqlColumnMetadata = schemaType.getValue();
        }
    }

    Field field = (Field) ((AbstractAttribute) attribute).getJavaMember();
    Class embeddedClass = ((AbstractAttribute) attribute).getBindableJavaType();

    if (List.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) {
        ListType listType = null;
        try {
            listType = ListType.getInstance(new TypeParser(
                    cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
        } catch (ConfigurationException | SyntaxException e) {
            log.error(e.getMessage());
            throw new KunderaException("Error while getting instance of ListType " + e);
        }
        return setElementCollectionList(listType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                metaModel, embeddedClass, true);

    } else if (Set.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) {
        SetType setType = null;
        try {
            setType = SetType.getInstance(new TypeParser(
                    cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
        } catch (ConfigurationException | SyntaxException e) {
            log.error(e.getMessage());
            throw new KunderaException("Error while getting instance of SetType " + e);
        }
        return setElementCollectionSet(setType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                metaModel, embeddedClass, true);

    } else if (Map.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType())) {
        MapType mapType = null;
        try {
            mapType = MapType.getInstance(new TypeParser(
                    cqlColumnMetadata.substring(cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
        } catch (ConfigurationException | SyntaxException e) {
            log.error(e.getMessage());
            throw new KunderaException("Error while getting instance of MapType " + e);
        }
        return setElementCollectionMap(mapType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                metaModel, embeddedClass, true);
    }

    return entity;

}