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));
}
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());
}
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]);
}
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());
}
Aggregations