use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class SelectQueryProviderTest method shouldReturnParserQuery12.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where stamina <= 10.23" })
public void shouldReturnParserQuery12(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.LESSER_EQUALS_THAN, condition.getOperator());
assertEquals("stamina", condition.getName());
assertTrue(value instanceof NumberQueryValue);
assertEquals(10.23, value.get());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class AbstractWhereSupplier method appendCondition.
private void appendCondition(Operator operator, Condition newCondition) {
if (operator.equals(this.condition.getOperator())) {
ConditionQueryValue conditionValue = ConditionQueryValue.class.cast(this.condition.getValue());
List<Condition> conditions = new ArrayList<>(conditionValue.get());
conditions.add(newCondition);
this.condition = new DefaultCondition("_" + operator.name(), operator, DefaultConditionValue.of(conditions));
} else if (isNotAppendable()) {
List<Condition> conditions = Arrays.asList(this.condition, newCondition);
this.condition = new DefaultCondition("_" + operator.name(), operator, DefaultConditionValue.of(conditions));
} else {
List<Condition> conditions = ConditionQueryValue.class.cast(this.condition.getValue()).get();
Condition lastCondition = conditions.get(conditions.size() - 1);
if (isAppendable(lastCondition) && operator.equals(lastCondition.getOperator())) {
List<Condition> lastConditions = new ArrayList<>(ConditionQueryValue.class.cast(lastCondition.getValue()).get());
lastConditions.add(newCondition);
Condition newAppendable = new DefaultCondition("_" + operator.name(), operator, DefaultConditionValue.of(lastConditions));
List<Condition> newConditions = new ArrayList<>(conditions.subList(0, conditions.size() - 1));
newConditions.add(newAppendable);
this.condition = new DefaultCondition(this.condition.getName(), this.condition.getOperator(), DefaultConditionValue.of(newConditions));
} else {
Condition newAppendable = new DefaultCondition("_" + operator.name(), operator, DefaultConditionValue.of(Collections.singletonList(newCondition)));
List<Condition> newConditions = new ArrayList<>(conditions);
newConditions.add(newAppendable);
this.condition = new DefaultCondition(this.condition.getName(), this.condition.getOperator(), DefaultConditionValue.of(newConditions));
}
}
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class AbstractMethodQueryProvider method appendCondition.
private void appendCondition(Operator operator, Condition newCondition) {
if (operator.equals(this.condition.getOperator())) {
ConditionQueryValue conditionValue = ConditionQueryValue.class.cast(this.condition.getValue());
List<Condition> conditions = new ArrayList<>(conditionValue.get());
conditions.add(newCondition);
this.condition = new MethodCondition(SUB_ENTITY_FLAG + operator.name(), operator, MethodConditionValue.of(conditions));
} else if (isNotAppendable()) {
List<Condition> conditions = Arrays.asList(this.condition, newCondition);
this.condition = new MethodCondition(SUB_ENTITY_FLAG + operator.name(), operator, MethodConditionValue.of(conditions));
} else {
List<Condition> conditions = ConditionQueryValue.class.cast(this.condition.getValue()).get();
Condition lastCondition = conditions.get(conditions.size() - 1);
if (isAppendable(lastCondition) && operator.equals(lastCondition.getOperator())) {
List<Condition> lastConditions = new ArrayList<>(ConditionQueryValue.class.cast(lastCondition.getValue()).get());
lastConditions.add(newCondition);
Condition newAppendable = new MethodCondition(SUB_ENTITY_FLAG + operator.name(), operator, MethodConditionValue.of(lastConditions));
List<Condition> newConditions = new ArrayList<>(conditions.subList(0, conditions.size() - 1));
newConditions.add(newAppendable);
this.condition = new MethodCondition(this.condition.getName(), this.condition.getOperator(), MethodConditionValue.of(newConditions));
} else {
Condition newAppendable = new MethodCondition(SUB_ENTITY_FLAG + operator.name(), operator, MethodConditionValue.of(Collections.singletonList(newCondition)));
List<Condition> newConditions = new ArrayList<>(conditions);
newConditions.add(newAppendable);
this.condition = new MethodCondition(this.condition.getName(), this.condition.getOperator(), MethodConditionValue.of(newConditions));
}
}
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class AbstractQueryConvert method getPredicate.
protected GraphTraversal<Vertex, Vertex> getPredicate(GraphQueryMethod graphQuery, Condition condition, ClassMapping mapping) {
Operator operator = condition.getOperator();
String name = condition.getName();
String nativeName = mapping.getColumnField(name);
switch(operator) {
case EQUALS:
return __.has(nativeName, P.eq(graphQuery.getValue(name)));
case GREATER_THAN:
return __.has(nativeName, P.gt(graphQuery.getValue(name)));
case GREATER_EQUALS_THAN:
return __.has(nativeName, P.gte(graphQuery.getValue(name)));
case LESSER_THAN:
return __.has(nativeName, P.lt(graphQuery.getValue(name)));
case LESSER_EQUALS_THAN:
return __.has(nativeName, P.lte(graphQuery.getValue(name)));
case BETWEEN:
return __.has(nativeName, P.between(graphQuery.getValue(name), graphQuery.getValue(name)));
case IN:
return __.has(nativeName, P.within(graphQuery.getInValue(name)));
case NOT:
Condition notCondition = ((ConditionQueryValue) condition.getValue()).get().get(0);
return __.not(getPredicate(graphQuery, notCondition, mapping));
case AND:
return ((ConditionQueryValue) condition.getValue()).get().stream().map(c -> getPredicate(graphQuery, c, mapping)).reduce(GraphTraversal::and).orElseThrow(() -> new UnsupportedOperationException("There is an inconsistency at the AND operator"));
case OR:
return ((ConditionQueryValue) condition.getValue()).get().stream().map(c -> getPredicate(graphQuery, c, mapping)).reduce(GraphTraversal::or).orElseThrow(() -> new UnsupportedOperationException("There is an inconsistency at the OR operator"));
default:
throw new UnsupportedOperationException("There is not support to the type " + operator + " in graph");
}
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class AbstractQueryConvert method getGraphTraversal.
protected GraphTraversal<Vertex, Vertex> getGraphTraversal(GraphQueryMethod graphQuery, Supplier<Optional<Where>> whereSupplier, ClassMapping mapping) {
GraphTraversal<Vertex, Vertex> traversal = graphQuery.getTraversal();
Optional<Where> whereOptional = whereSupplier.get();
if (whereOptional.isPresent()) {
Where where = whereOptional.get();
Condition condition = where.getCondition();
traversal.filter(getPredicate(graphQuery, condition, mapping));
}
return traversal;
}
Aggregations