Search in sources :

Example 11 with UpdateQuery

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

the class UpdateQueryParser method query.

Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    UpdateQuery updateQuery = updateQueryProvider.apply(query);
    Params params = Params.newParams();
    ColumnEntity entity = getEntity(params, updateQuery, observer);
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    return Stream.of(manager.update(entity));
}
Also used : QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) UpdateQuery(jakarta.nosql.query.UpdateQuery) Params(jakarta.nosql.Params)

Example 12 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (stamina = 32.23)" })
public void shouldReturnParserQuery2(String query) {
    UpdateQuery updateQuery = checkUpdateFromStart(query);
    List<Condition> conditions = updateQuery.getConditions();
    assertEquals(1, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("stamina", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof NumberQueryValue);
    assertEquals(32.23, NumberQueryValue.class.cast(value).get());
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) UpdateQuery(jakarta.nosql.query.UpdateQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (birthday = convert(\"1988-01-01\", java.time.LocalDate))" })
public void shouldReturnParserQuery5(String query) {
    UpdateQuery updateQuery = checkUpdateFromStart(query);
    List<Condition> conditions = updateQuery.getConditions();
    assertEquals(1, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("birthday", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof FunctionQueryValue);
    Function function = FunctionQueryValue.class.cast(value).get();
    assertEquals("convert", function.getName());
    Object[] params = function.getParams();
    assertEquals(2, params.length);
    assertEquals("1988-01-01", StringQueryValue.class.cast(params[0]).get());
    assertEquals(LocalDate.class, params[1]);
}
Also used : Condition(jakarta.nosql.query.Condition) Function(jakarta.nosql.query.Function) UpdateQuery(jakarta.nosql.query.UpdateQuery) JsonObject(javax.json.JsonObject) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = \"Diana\")" })
public void shouldReturnParserQuery(String query) {
    UpdateQuery updateQuery = checkUpdateFromStart(query);
    List<Condition> conditions = updateQuery.getConditions();
    assertEquals(1, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("name", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof StringQueryValue);
    assertEquals("Diana", StringQueryValue.class.cast(value).get());
}
Also used : Condition(jakarta.nosql.query.Condition) UpdateQuery(jakarta.nosql.query.UpdateQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UpdateQuery (jakarta.nosql.query.UpdateQuery)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 Condition (jakarta.nosql.query.Condition)7 Params (jakarta.nosql.Params)4 JsonObject (javax.json.JsonObject)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)3 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)3 QueryException (jakarta.nosql.QueryException)2 ColumnEntity (jakarta.nosql.column.ColumnEntity)2 DocumentEntity (jakarta.nosql.document.DocumentEntity)2 StringQueryValue (jakarta.nosql.query.StringQueryValue)2 Function (jakarta.nosql.query.Function)1 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)1 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)1 JsonArray (javax.json.JsonArray)1