Example usage for org.apache.cassandra.db.marshal TypeParser parse

List of usage examples for org.apache.cassandra.db.marshal TypeParser parse

Introduction

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

Prototype

public AbstractType<?> parse() throws SyntaxException, ConfigurationException 

Source Link

Document

Parse an AbstractType from current position of this parser.

Usage

From source file:com.impetus.client.cassandra.schemamanager.CassandraValidationClassMapper.java

License:Apache License

/**
 * Gets the value type name.// ww w  . j av  a  2  s .  co m
 * 
 * @param dataType
 *            the data type
 * @param genericClasses
 *            the generic classes
 * @param isCql3Enabled
 *            the is cql3 enabled
 * @return the value type name
 * @throws SyntaxException
 *             the syntax exception
 * @throws ConfigurationException
 *             the configuration exception
 * @throws IllegalArgumentException
 *             the illegal argument exception
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws NoSuchFieldException
 *             the no such field exception
 * @throws SecurityException
 *             the security exception
 */
public static String getValueTypeName(Class<?> dataType, List<Class<?>> genericClasses, boolean isCql3Enabled)
        throws SyntaxException, ConfigurationException, IllegalArgumentException, IllegalAccessException,
        NoSuchFieldException, SecurityException {
    String valueType;

    Class<?> validation_class = getValidationClassInstance(dataType, isCql3Enabled);

    valueType = validation_class.toString();
    if (validation_class.equals(ListType.class)) {
        TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled));
        valueType = ListType.getInstance(parser.parse(), true).toString();
    } else if (validation_class.equals(SetType.class)) {
        TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled));
        valueType = SetType.getInstance(parser.parse(), true).toString();
    } else if (validation_class.equals(MapType.class)) {
        Class keyClass = CassandraValidationClassMapper.getValidationClassInstance(genericClasses.get(0), true);
        Class valueClass = CassandraValidationClassMapper.getValidationClassInstance(genericClasses.get(1),
                true);

        Object keyClassInstance = keyClass.getDeclaredField("instance").get(null);
        Object valueClassInstance = valueClass.getDeclaredField("instance").get(null);

        valueType = MapType
                .getInstance((AbstractType) keyClassInstance, (AbstractType) valueClassInstance, true)
                .toString();
        // TypeParser keyParser = new
        // TypeParser(getValidationClass(genericClasses.get(0),
        // isCql3Enabled));
        // TypeParser valueParser = new
        // TypeParser(getValidationClass(genericClasses.get(1),
        // isCql3Enabled));
        // valueType = MapType.getInstance(keyParser,
        // valueParser).toString();
    }
    return valueType;
}