use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class GetProviderTest method shouldReturnParserQuery1.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get 12" })
public void shouldReturnParserQuery1(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(12L, NumberQueryValue.class.cast(key).get());
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class GetProviderTest method shouldReturnParserQuery3.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get -12" })
public void shouldReturnParserQuery3(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(-12L, NumberQueryValue.class.cast(key).get());
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery27.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeBetween" })
public void shouldReturnParserQuery27(String query) {
Operator operator = Operator.BETWEEN;
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, condition.getOperator());
QueryValue<?>[] values = MethodArrayValue.class.cast(value).get();
ParamQueryValue param1 = (ParamQueryValue) values[0];
ParamQueryValue param2 = (ParamQueryValue) values[1];
assertNotEquals(param2.get(), param1.get());
}
use of jakarta.nosql.query.QueryValue in project jnosql-diana by eclipse.
the class FindByMethodQueryProviderTest method shouldReturnParserQuery28.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeNotBetween" })
public void shouldReturnParserQuery28(String query) {
String entity = "entity";
SelectQuery selectQuery = queryProvider.apply(query, entity);
assertNotNull(selectQuery);
assertEquals(entity, selectQuery.getEntity());
assertTrue(selectQuery.getFields().isEmpty());
assertTrue(selectQuery.getOrderBy().isEmpty());
assertEquals(0, selectQuery.getLimit());
assertEquals(0, selectQuery.getSkip());
Optional<Where> where = selectQuery.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());
}
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.getDocuments(JSONQueryValue.class.cast(value).get());
case CONDITION:
default:
throw new QueryException("There is not support to the value: " + type);
}
}
Aggregations