use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method shouldRunQuery31.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteBySalary_CurrencyAndName" })
public void shouldRunQuery31(String query) {
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();
Assertions.assertEquals(Operator.AND, condition.getOperator());
final QueryValue<?> value = condition.getValue();
Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
Condition condition2 = ConditionQueryValue.class.cast(value).get().get(1);
assertEquals("salary.currency", condition1.getName());
assertEquals("name", condition2.getName());
}
use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteBy" })
public void shouldReturnParserQuery(String query) {
String entity = "entity";
DeleteQuery deleteQuery = queryProvider.apply(query, entity);
assertNotNull(deleteQuery);
assertEquals(entity, deleteQuery.getEntity());
assertTrue(deleteQuery.getFields().isEmpty());
Optional<Where> where = deleteQuery.getWhere();
assertFalse(where.isPresent());
}
use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery27.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeBetween" })
public void shouldReturnParserQuery27(String query) {
Operator operator = Operator.BETWEEN;
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(operator, condition.getOperator());
QueryValue<?>[] values = MethodArrayValue.class.cast(value).get();
ParamQueryValue param1 = (ParamQueryValue) values[0];
ParamQueryValue param2 = (ParamQueryValue) values[1];
assertNotEquals(param2.get(), param1.get());
}
use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.
the class BaseColumnRepository method getDeleteQuery.
protected ColumnDeleteQuery getDeleteQuery(Method method, Object[] args) {
DeleteMethodProvider deleteMethodFactory = DeleteMethodProvider.get();
DeleteQuery deleteQuery = deleteMethodFactory.apply(method, getClassMapping().getName());
ColumnDeleteQueryParams queryParams = DELETE_CONVERTER.apply(deleteQuery, getParser());
ColumnDeleteQuery query = queryParams.getQuery();
Params params = queryParams.getParams();
getParamsBinder().bind(params, args, method);
return query;
}
use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private DocumentDeleteQuery getQuery(Params params, DocumentObserverParser observer, DeleteQuery deleteQuery) {
String collection = observer.fireEntity(deleteQuery.getEntity());
List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
DocumentCondition condition = null;
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
return new DefaultDocumentDeleteQuery(collection, condition, documents);
}
Aggregations