use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class SelectQueryProviderTest method shouldReturnParserQuery14.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age between 10 and 30" })
public void shouldReturnParserQuery14(String query) {
SelectQuery selectQuery = checkSelectFromStart(query);
assertTrue(selectQuery.getWhere().isPresent());
Where where = selectQuery.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));
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class RemoveProviderTest method shouldReturnParserQuery5.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del {1,12}" })
public void shouldReturnParserQuery5(String query) {
DelQuery delQuery = provider.apply(query);
List<QueryValue<?>> keys = delQuery.getKeys();
assertEquals(1, keys.size());
QueryValue<?> key = keys.get(0);
assertTrue(key instanceof ArrayQueryValue);
QueryValue<?>[] values = ArrayQueryValue.class.cast(key).get();
MatcherAssert.assertThat(Arrays.stream(values).map(QueryValue::get).collect(Collectors.toList()), Matchers.contains(1L, 12L));
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class GetProviderTest method shouldReturnParserQuery4.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get -12.12" })
public void shouldReturnParserQuery4(String query) {
GetQuery getQuery = queryProvider.apply(query);
List<QueryValue<?>> keys = getQuery.getKeys();
assertEquals(1, keys.size());
QueryValue<?> key = keys.get(0);
assertTrue(key instanceof NumberQueryValue);
assertEquals(-12.12, NumberQueryValue.class.cast(key).get());
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class GetProviderTest method shouldReturnParserQuery.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get \"Diana\"" })
public void shouldReturnParserQuery(String query) {
GetQuery getQuery = queryProvider.apply(query);
List<QueryValue<?>> keys = getQuery.getKeys();
assertEquals(1, keys.size());
QueryValue<?> key = keys.get(0);
assertTrue(key instanceof StringQueryValue);
assertEquals("Diana", StringQueryValue.class.cast(key).get());
}
use of jakarta.nosql.query.QueryValue 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);
}
}
Aggregations