Search in sources :

Example 41 with Where

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

the class SelectQueryProviderTest method shouldReturnParserQuery16.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = 'diana'" })
public void shouldReturnParserQuery16(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.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof StringQueryValue);
    assertEquals("diana", value.get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) StringQueryValue(jakarta.nosql.query.StringQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with Where

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

the class SelectQueryProviderTest method shouldReturnParserQuery10.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where stamina > 10.23" })
public void shouldReturnParserQuery10(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.GREATER_THAN, condition.getOperator());
    assertEquals("stamina", condition.getName());
    assertTrue(value instanceof NumberQueryValue);
    assertEquals(10.23, value.get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with Where

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

the class SelectQueryProviderTest method shouldReturnParserQuery19.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery19(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.EQUALS, condition.getOperator());
    assertEquals("siblings", condition.getName());
    assertTrue(value instanceof JSONQueryValue);
    JsonObject jsonObject = JSONQueryValue.class.cast(value).get();
    assertEquals("Brother", jsonObject.getString("apollo"));
    assertEquals("Father", jsonObject.getString("Zeus"));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) JsonObject(javax.json.JsonObject) Where(jakarta.nosql.query.Where) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with Where

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

the class SelectQueryProviderTest method shouldReturnParserQuery20.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = @name" })
public void shouldReturnParserQuery20(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.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof ParamQueryValue);
    assertEquals("name", ParamQueryValue.class.cast(value).get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with Where

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

the class DeleteByMethodQueryProviderTest method checkAppendCondition.

private void checkAppendCondition(String query, Operator operator, Operator operator2, String variable, String variable2, Operator operatorAppender) {
    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(operatorAppender, condition.getOperator());
    assertTrue(value instanceof ConditionQueryValue);
    Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
    Condition condition2 = ConditionQueryValue.class.cast(value).get().get(1);
    assertEquals(operator, condition1.getOperator());
    QueryValue<?> param = condition1.getValue();
    assertEquals(operator, condition1.getOperator());
    assertTrue(ParamQueryValue.class.cast(param).get().contains(variable));
    assertEquals(operator2, condition2.getOperator());
    QueryValue<?> param2 = condition2.getValue();
    assertEquals(condition2.getOperator(), operator2);
    assertTrue(ParamQueryValue.class.cast(param2).get().contains(variable2));
}
Also used : Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where)

Aggregations

Where (jakarta.nosql.query.Where)63 Condition (jakarta.nosql.query.Condition)61 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)54 ValueSource (org.junit.jupiter.params.provider.ValueSource)54 SelectQuery (jakarta.nosql.query.SelectQuery)32 DeleteQuery (jakarta.nosql.query.DeleteQuery)30 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)22 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)22 StringQueryValue (jakarta.nosql.query.StringQueryValue)19 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)16 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)14 JsonObject (javax.json.JsonObject)14 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)8 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)8 Function (jakarta.nosql.query.Function)6 QueryValue (jakarta.nosql.query.QueryValue)6 Operator (jakarta.nosql.query.Operator)2 Sort (jakarta.nosql.Sort)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1