Search in sources :

Example 16 with QueryException

use of jakarta.nosql.QueryException in project jnosql-diana by eclipse.

the class Values method get.

private static Object get(QueryValue<?> value, Params parameters) {
    ValueType type = value.getType();
    switch(type) {
        case NUMBER:
        case STRING:
            return value.get();
        case PARAMETER:
            return parameters.add(ParamQueryValue.class.cast(value).get());
        case ARRAY:
            return Stream.of(ArrayQueryValue.class.cast(value).get()).map(v -> get(v, parameters)).collect(toList());
        case FUNCTION:
            Function function = FunctionQueryValue.class.cast(value).get();
            String name = function.getName();
            Object[] params = function.getParams();
            if ("convert".equals(name)) {
                return executeConvert(parameters, params);
            }
            String message = String.format("There is not support to the function: %s with parameters %s", name, Arrays.toString(params));
            throw new QueryException(message);
        case JSON:
            return JSONQueryValue.class.cast(value).get().toString();
        case CONDITION:
        default:
            throw new QueryException("There is not support to the value: " + type);
    }
}
Also used : ParamQueryValue(jakarta.nosql.query.ParamQueryValue) Arrays(java.util.Arrays) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) Value(jakarta.nosql.Value) QueryValue(jakarta.nosql.query.QueryValue) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ValueType(jakarta.nosql.query.ValueType) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) QueryException(jakarta.nosql.QueryException) Function(jakarta.nosql.query.Function) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) Params(jakarta.nosql.Params) Function(jakarta.nosql.query.Function) QueryException(jakarta.nosql.QueryException) ValueType(jakarta.nosql.query.ValueType) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue)

Example 17 with QueryException

use of jakarta.nosql.QueryException in project jnosql-diana by eclipse.

the class DefaultFunctionQueryValue method getConverter.

private static FunctionQueryValue getConverter(QueryParser.FunctionContext context) {
    QueryParser.ConvertContext converter = context.convert();
    QueryValue<?> value = Elements.getElement(converter.element());
    String text = converter.name().getText();
    try {
        Object[] params = new Object[] { value, Class.forName(text) };
        Function function1 = DefaultFunction.of("convert", params);
        return new DefaultFunctionQueryValue(function1);
    } catch (ClassNotFoundException e) {
        throw new QueryException("Class does not found the converter function argument: " + text, e);
    }
}
Also used : Function(jakarta.nosql.query.Function) QueryException(jakarta.nosql.QueryException)

Aggregations

QueryException (jakarta.nosql.QueryException)17 Params (jakarta.nosql.Params)14 Stream (java.util.stream.Stream)9 Collectors.toList (java.util.stream.Collectors.toList)7 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)6 List (java.util.List)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)5 DocumentEntity (jakarta.nosql.document.DocumentEntity)5 Value (jakarta.nosql.Value)4 Function (jakarta.nosql.query.Function)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)4 Collectors (java.util.stream.Collectors)4 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)3 Objects (java.util.Objects)3 Sort (jakarta.nosql.Sort)2 ColumnCondition (jakarta.nosql.column.ColumnCondition)2 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)2 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)2 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)2 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)2