Search in sources :

Example 1 with ValueType

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

the class Values method get.

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 jakarta.nosql.Value.of(get(QueryValue.class.cast(params[0]), parameters)).get((Class<?>) params[1]);
            }
            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 JsonObjects.getColumns(JSONQueryValue.class.cast(value).get());
        case CONDITION:
        default:
            throw new QueryException("There is not support to the value: " + type);
    }
}
Also used : ParamQueryValue(jakarta.nosql.query.ParamQueryValue) QueryValue(jakarta.nosql.query.QueryValue) Arrays(java.util.Arrays) 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) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) 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) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) JSONQueryValue(jakarta.nosql.query.JSONQueryValue)

Example 2 with ValueType

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

the class Values method get.

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 jakarta.nosql.Value.of(get(QueryValue.class.cast(params[0]), parameters)).get((Class<?>) params[1]);
            }
            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 JsonObjects.getDocuments(JSONQueryValue.class.cast(value).get());
        case CONDITION:
        default:
            throw new QueryException("There is not support to the value: " + type);
    }
}
Also used : ParamQueryValue(jakarta.nosql.query.ParamQueryValue) QueryValue(jakarta.nosql.query.QueryValue) Arrays(java.util.Arrays) 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) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) 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) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) JSONQueryValue(jakarta.nosql.query.JSONQueryValue)

Example 3 with ValueType

use of jakarta.nosql.query.ValueType 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)

Aggregations

Params (jakarta.nosql.Params)3 QueryException (jakarta.nosql.QueryException)3 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)3 Function (jakarta.nosql.query.Function)3 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)3 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)3 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)3 QueryValue (jakarta.nosql.query.QueryValue)3 ValueType (jakarta.nosql.query.ValueType)3 Arrays (java.util.Arrays)3 Collectors.toList (java.util.stream.Collectors.toList)3 Stream (java.util.stream.Stream)3 Value (jakarta.nosql.Value)1