Search in sources :

Example 1 with QueryValue

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

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

the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery28.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeNotBetween" })
public void shouldReturnParserQuery28(String query) {
    String entity = "entity";
    DeleteQuery deleteQuery = queryProvider.apply(query, entity);
    assertNotNull(deleteQuery);
    assertEquals(entity, deleteQuery.getEntity());
    assertTrue(deleteQuery.getFields().isEmpty());
    Optional<Where> where = deleteQuery.getWhere();
    assertTrue(where.isPresent());
    Condition condition = where.get().getCondition();
    QueryValue<?> value = condition.getValue();
    assertEquals(Operator.NOT, condition.getOperator());
    Condition notCondition = MethodConditionValue.class.cast(value).get().get(0);
    assertEquals(Operator.BETWEEN, notCondition.getOperator());
    QueryValue<?>[] values = MethodArrayValue.class.cast(notCondition.getValue()).get();
    ParamQueryValue param1 = (ParamQueryValue) values[0];
    ParamQueryValue param2 = (ParamQueryValue) values[1];
    assertNotEquals(param2.get(), param1.get());
}
Also used : Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with QueryValue

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

the class DeleteQueryProviderTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age between 10 and 30" })
public void shouldReturnParserQuery8(String query) {
    DeleteQuery deleteQuery = checkDeleteFromStart(query);
    assertTrue(deleteQuery.getWhere().isPresent());
    Where where = deleteQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.BETWEEN, condition.getOperator());
    assertEquals("age", condition.getName());
    assertTrue(value instanceof ArrayQueryValue);
    ArrayQueryValue arrayValue = ArrayQueryValue.class.cast(value);
    QueryValue<?>[] values = arrayValue.get();
    assertThat(Stream.of(values).map(QueryValue::get).collect(toList()), contains(10L, 30L));
}
Also used : Condition(jakarta.nosql.query.Condition) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with QueryValue

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

the class RemoveProviderTest method shouldReturnParserQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del 12.12" })
public void shouldReturnParserQuery2(String query) {
    DelQuery delQuery = provider.apply(query);
    List<QueryValue<?>> keys = delQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof NumberQueryValue);
    assertEquals(12.12, NumberQueryValue.class.cast(key).get());
}
Also used : NumberQueryValue(jakarta.nosql.query.NumberQueryValue) DelQuery(jakarta.nosql.query.DelQuery) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with QueryValue

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

the class RemoveProviderTest method shouldReturnParserQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del \"Diana\"" })
public void shouldReturnParserQuery(String query) {
    DelQuery delQuery = provider.apply(query);
    List<QueryValue<?>> keys = delQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof StringQueryValue);
    assertEquals("Diana", StringQueryValue.class.cast(key).get());
}
Also used : DelQuery(jakarta.nosql.query.DelQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

QueryValue (jakarta.nosql.query.QueryValue)22 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ValueSource (org.junit.jupiter.params.provider.ValueSource)18 StringQueryValue (jakarta.nosql.query.StringQueryValue)15 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)14 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)9 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)7 Condition (jakarta.nosql.query.Condition)6 DelQuery (jakarta.nosql.query.DelQuery)6 GetQuery (jakarta.nosql.query.GetQuery)6 Where (jakarta.nosql.query.Where)6 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)5 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)5 Params (jakarta.nosql.Params)3 QueryException (jakarta.nosql.QueryException)3 DeleteQuery (jakarta.nosql.query.DeleteQuery)3 Function (jakarta.nosql.query.Function)3 SelectQuery (jakarta.nosql.query.SelectQuery)3 ValueType (jakarta.nosql.query.ValueType)3