Search in sources :

Example 26 with DeleteQuery

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

the class BaseDocumentRepository method getDeleteQuery.

protected DocumentDeleteQuery getDeleteQuery(Method method, Object[] args) {
    DeleteMethodProvider methodProvider = DeleteMethodProvider.get();
    DeleteQuery deleteQuery = methodProvider.apply(method, getClassMapping().getName());
    DeleteQueryConverter converter = ServiceLoaderProvider.get(DeleteQueryConverter.class);
    DocumentDeleteQueryParams queryParams = converter.apply(deleteQuery, getParser());
    DocumentDeleteQuery query = queryParams.getQuery();
    Params params = queryParams.getParams();
    getParamsBinder().bind(params, args, method);
    return query;
}
Also used : DeleteMethodProvider(org.eclipse.jnosql.communication.query.method.DeleteMethodProvider) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) DeleteQueryConverter(jakarta.nosql.document.DeleteQueryConverter) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 27 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery 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)

Example 28 with DeleteQuery

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

the class DeleteQueryProviderTest method shouldReturnParserQuery7.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where stamina < 10.23" })
public void shouldReturnParserQuery7(String query) {
    DeleteQuery deleteQuery = checkDeleteFromStart(query);
    assertTrue(deleteQuery.getWhere().isPresent());
    Where where = deleteQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.LESSER_THAN, condition.getOperator());
    assertEquals("stamina", condition.getName());
    assertTrue(value instanceof NumberQueryValue);
    assertEquals(10.23, value.get());
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with DeleteQuery

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

the class DeleteQueryProviderTest method shouldReturnParserQuery12.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery12(String query) {
    DeleteQuery deleteQuery = checkDeleteFromStart(query);
    assertTrue(deleteQuery.getWhere().isPresent());
    Where where = deleteQuery.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 : Condition(jakarta.nosql.query.Condition) JsonObject(javax.json.JsonObject) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with DeleteQuery

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

the class DeleteQueryProviderTest method shouldReturnParserQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete name, address from God" })
public void shouldReturnParserQuery2(String query) {
    DeleteQuery deleteQuery = selectProvider.apply(query);
    assertEquals("God", deleteQuery.getEntity());
    assertFalse(deleteQuery.getFields().isEmpty());
    assertThat(deleteQuery.getFields(), contains("name", "address"));
    assertFalse(deleteQuery.getWhere().isPresent());
}
Also used : DeleteQuery(jakarta.nosql.query.DeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DeleteQuery (jakarta.nosql.query.DeleteQuery)40 Where (jakarta.nosql.query.Where)30 Condition (jakarta.nosql.query.Condition)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 ValueSource (org.junit.jupiter.params.provider.ValueSource)28 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)11 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)11 StringQueryValue (jakarta.nosql.query.StringQueryValue)9 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)8 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)7 JsonObject (javax.json.JsonObject)7 Params (jakarta.nosql.Params)6 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)4 DeleteQueryProvider (jakarta.nosql.query.DeleteQuery.DeleteQueryProvider)4 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4