Examples of InvalidTypeException


Examples of com.datastax.driver.core.exceptions.InvalidTypeException

            return customClassName;
        }

        @Override
        public Object parse(String value) {
            throw new InvalidTypeException("Cannot parse values of custom types");
        }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

            throw new InvalidTypeException("Cannot parse values of custom types");
        }

        @Override
        public String format(Object value) {
            throw new InvalidTypeException("Cannot format values of custom types");
        }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    UDTValue parseValue(String value) {
        UDTValue v = newValue();

        int idx = ParseUtils.skipSpaces(value, 0);
        if (value.charAt(idx++) != '{')
            throw new InvalidTypeException(String.format("Cannot parse UDT value from \"%s\", at character %d expecting '{' but got '%c'", value, idx, value.charAt(idx)));

        idx = ParseUtils.skipSpaces(value, idx);

        if (value.charAt(idx) == '}')
            return v;

        while (idx < value.length()) {

            int n;
            try {
                n = ParseUtils.skipCQLId(value, idx);
            } catch (IllegalArgumentException e) {
                throw new InvalidTypeException(String.format("Cannot parse UDT value from \"%s\", cannot parse a CQL identifier at character %d", value, idx), e);
            }
            String name = value.substring(idx, n);
            idx = n;

            if (!contains(name))
                throw new InvalidTypeException(String.format("Unknown field %s in value \"%s\"", name, value));

            idx = ParseUtils.skipSpaces(value, idx);
            if (value.charAt(idx++) != ':')
                throw new InvalidTypeException(String.format("Cannot parse UDT value from \"%s\", at character %d expecting ':' but got '%c'", value, idx, value.charAt(idx)));
            idx = ParseUtils.skipSpaces(value, idx);

            try {
                n = ParseUtils.skipCQLValue(value, idx);
            } catch (IllegalArgumentException e) {
                throw new InvalidTypeException(String.format("Cannot parse UDT value from \"%s\", invalid CQL value at character %d", value, idx), e);
            }

            DataType dt = getFieldType(name);
            v.setBytesUnsafe(name, dt.serialize(dt.parse(value.substring(idx, n)), ProtocolVersion.V3));
            idx = n;

            idx = ParseUtils.skipSpaces(value, idx);
            if (value.charAt(idx) == '}')
                return v;
            if (value.charAt(idx) != ',')
                throw new InvalidTypeException(String.format("Cannot parse UDT value from \"%s\", at character %d expecting ',' but got '%c'", value, idx, value.charAt(idx)));
            ++idx; // skip ','

            idx = ParseUtils.skipSpaces(value, idx);
        }
        throw new InvalidTypeException(String.format("Malformed UDT value \"%s\", missing closing '}'", value));
    }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

        if (v == null)
            return setValue(i, null);

        if (type == DataType.Name.TIMEUUID && v.version() != 1)
            throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v));

        return type == DataType.Name.UUID
             ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v))
             : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v));
    }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    }

    public <E> T setList(int i, List<E> v) {
        DataType type = getType(i);
        if (type.getName() != DataType.Name.LIST)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a list", getName(i), type));

        if (v == null)
            return setValue(i, null);

        // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type
        if (!v.isEmpty()) {
            // Ugly? Yes
            Class<?> providedClass = v.get(0).getClass();
            Class<?> expectedClass = type.getTypeArguments().get(0).asJavaClass();

            if (!expectedClass.isAssignableFrom(providedClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting list of %s but provided list of %s", getName(i), type, expectedClass, providedClass));
        }
        return setValue(i, type.codec(protocolVersion).serialize(v));
    }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    }

    public <K, V> T setMap(int i, Map<K, V> v) {
        DataType type = getType(i);
        if (type.getName() != DataType.Name.MAP)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a map", getName(i), type));

        if (v == null)
            return setValue(i, null);

        if (!v.isEmpty()) {
            // Ugly? Yes
            Map.Entry<K, V> entry = v.entrySet().iterator().next();
            Class<?> providedKeysClass = entry.getKey().getClass();
            Class<?> providedValuesClass = entry.getValue().getClass();

            Class<?> expectedKeysClass = type.getTypeArguments().get(0).getName().javaType;
            Class<?> expectedValuesClass = type.getTypeArguments().get(1).getName().javaType;
            if (!expectedKeysClass.isAssignableFrom(providedKeysClass) || !expectedValuesClass.isAssignableFrom(providedValuesClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting map of %s->%s but provided map of %s->%s", getName(i), type, expectedKeysClass, expectedValuesClass, providedKeysClass, providedValuesClass));
        }
        return setValue(i, type.codec(protocolVersion).serialize(v));
    }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    }

    public <E> T setSet(int i, Set<E> v) {
        DataType type = getType(i);
        if (type.getName() != DataType.Name.SET)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a set", getName(i), type));

        if (v == null)
            return setValue(i, null);

        if (!v.isEmpty()) {
            // Ugly? Yes
            Class<?> providedClass = v.iterator().next().getClass();
            Class<?> expectedClass = type.getTypeArguments().get(0).getName().javaType;

            if (!expectedClass.isAssignableFrom(providedClass))
                throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting set of %s but provided set of %s", getName(i), type, expectedClass, providedClass));
        }
        return setValue(i, type.codec(protocolVersion).serialize(v));
    }
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    }

    public T setUDTValue(int i, UDTValue v) {
        DataType type = getType(i);
        if (type.getName() != DataType.Name.UDT)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a UDT", getName(i), type));

        if (v == null)
            return setValue(i, null);

        // UDT always use the V3 protocol version to encode values
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

    }

    public T setTupleValue(int i, TupleValue v) {
        DataType type = getType(i);
        if (type.getName() != DataType.Name.TUPLE)
            throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a tuple", getName(i), type));

        if (v == null)
            return setValue(i, null);

        // Tuples always user the V3 protocol version to encode values
View Full Code Here

Examples of com.datastax.driver.core.exceptions.InvalidTypeException

        if (v == null)
            return setValue(i, null);

        if (type == DataType.Name.TIMEUUID && v.version() != 1)
            throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v));

        return type == DataType.Name.UUID
             ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v))
             : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.