Example usage for org.apache.cassandra.serializers UTF8Serializer instance

List of usage examples for org.apache.cassandra.serializers UTF8Serializer instance

Introduction

In this page you can find the example usage for org.apache.cassandra.serializers UTF8Serializer instance.

Prototype

UTF8Serializer instance

To view the source code for org.apache.cassandra.serializers UTF8Serializer instance.

Click Source Link

Usage

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

License:Apache License

/**
 * Sets the udt value./*from ww w  .j  av  a  2s  .  co  m*/
 * 
 * @param entity
 *            the entity
 * @param thriftColumnValue
 *            the thrift column value
 * @param metaModel
 *            the meta model
 * @param attribute
 *            the attribute
 * @return the object
 */
private Object setUdtValue(Object entity, Object thriftColumnValue, MetamodelImpl metaModel,
        Attribute attribute) {
    List<ByteBuffer> fieldNames = new ArrayList<ByteBuffer>();
    List<AbstractType<?>> fieldTypes = new ArrayList<AbstractType<?>>();

    String val = null;

    // get from cqlMetadata, details of types and names (for maintaining
    // order)
    Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types();
    for (Map.Entry<ByteBuffer, String> schemaType : schemaTypes.entrySet()) {
        UTF8Serializer utf8Serializer = UTF8Serializer.instance;
        String key = utf8Serializer.deserialize((schemaType.getKey()));
        if (key.equals(((AbstractAttribute) attribute).getJavaMember().getName())) {
            val = schemaType.getValue();
            break;
        }
    }

    UserType userType = null;

    try {
        userType = UserType.getInstance(new TypeParser(val.substring(val.indexOf("("), val.length())));
    } catch (ConfigurationException | SyntaxException e) {
        log.error(e.getMessage());
        throw new KunderaException("Error while getting instance of UserType " + e);
    }

    fieldNames = userType.fieldNames();
    fieldTypes = userType.allTypes();

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

    Object embeddedObject = KunderaCoreUtils.createNewInstance(embeddedClass);

    Object finalValue = populateEmbeddedRecursive((ByteBuffer.wrap((byte[]) thriftColumnValue)), fieldTypes,
            fieldNames, embeddedObject, metaModel);

    PropertyAccessorHelper.set(entity, field, finalValue);

    return entity;
}

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

License:Apache License

/**
 * Sets the element collection.//from ww  w  .jav a  2s. co m
 * 
 * @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;

}