Search in sources :

Example 1 with Operator

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

the class AbstractMethodQueryProvider method exitLte.

@Override
public void exitLte(MethodParser.LteContext ctx) {
    boolean hasNot = Objects.nonNull(ctx.not());
    String variable = getVariable(ctx.variable());
    Operator operator = LESSER_EQUALS_THAN;
    appendCondition(hasNot, variable, operator);
}
Also used : Operator(jakarta.nosql.query.Operator)

Example 2 with Operator

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

the class AbstractMethodQueryProvider method exitLt.

@Override
public void exitLt(MethodParser.LtContext ctx) {
    boolean hasNot = Objects.nonNull(ctx.not());
    String variable = getVariable(ctx.variable());
    Operator operator = LESSER_THAN;
    appendCondition(hasNot, variable, operator);
}
Also used : Operator(jakarta.nosql.query.Operator)

Example 3 with Operator

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

the class AbstractMethodQueryProvider method exitEq.

@Override
public void exitEq(MethodParser.EqContext ctx) {
    Operator operator = EQUALS;
    boolean hasNot = Objects.nonNull(ctx.not());
    String variable = getVariable(ctx.variable());
    appendCondition(hasNot, variable, operator);
}
Also used : Operator(jakarta.nosql.query.Operator)

Example 4 with Operator

use of jakarta.nosql.query.Operator 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");
    }
}
Also used : Operator(jakarta.nosql.query.Operator) Condition(jakarta.nosql.query.Condition) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue)

Example 5 with Operator

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

the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery6.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeGreaterThanEqual" })
public void shouldReturnParserQuery6(String query) {
    Operator operator = Operator.GREATER_EQUALS_THAN;
    String variable = "age";
    checkCondition(query, operator, variable);
}
Also used : Operator(jakarta.nosql.query.Operator) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Operator (jakarta.nosql.query.Operator)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 ValueSource (org.junit.jupiter.params.provider.ValueSource)34 Condition (jakarta.nosql.query.Condition)3 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)3 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)2 QueryValue (jakarta.nosql.query.QueryValue)2 Where (jakarta.nosql.query.Where)2 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)1 DeleteQuery (jakarta.nosql.query.DeleteQuery)1 SelectQuery (jakarta.nosql.query.SelectQuery)1