use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private DocumentDeleteQuery getQuery(String query, DocumentObserverParser observer) {
DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
String collection = observer.fireEntity(deleteQuery.getEntity());
List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
DocumentCondition condition = null;
Params params = Params.newParams();
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultDocumentDeleteQuery(collection, condition, documents);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentConditionTest method shouldCreateOrCondition.
@Test
public void shouldCreateOrCondition() {
Document age = Document.of("age", 26);
Document name = Document.of("name", "Otavio");
DocumentCondition condition1 = DefaultDocumentCondition.of(name, Condition.EQUALS);
DocumentCondition condition2 = DefaultDocumentCondition.of(age, Condition.GREATER_THAN);
DocumentCondition and = condition1.or(condition2);
Document andDocument = and.getDocument();
assertEquals(Condition.OR, and.getCondition());
assertEquals(Condition.OR.getNameField(), andDocument.getName());
assertThat(andDocument.getValue().get(new TypeReference<List<DocumentCondition>>() {
}), Matchers.containsInAnyOrder(condition1, condition2));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentConditionTest method shouldAnd.
@Test
public void shouldAnd() {
DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
DocumentCondition gt = DocumentCondition.gt(Document.of("age", 10));
DocumentCondition lte = DocumentCondition.lte(Document.of("salary", 10_000.00));
DocumentCondition and = eq.and(gt);
List<DocumentCondition> conditions = and.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
assertEquals(Condition.AND, and.getCondition());
assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
DocumentCondition result = and.and(lte);
assertEquals(Condition.AND, result.getCondition());
assertThat(result.getDocument().get(new TypeReference<List<DocumentCondition>>() {
}), Matchers.containsInAnyOrder(eq, gt, lte));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentConditionTest method shouldAffirmDoubleNegate.
@Test
public void shouldAffirmDoubleNegate() {
DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
DocumentCondition affirm = eq.negate().negate();
assertEquals(eq.getCondition(), affirm.getCondition());
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentConditionTest method shouldNegate.
@Test
public void shouldNegate() {
DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
DocumentCondition negate = eq.negate();
assertEquals(Condition.NOT, negate.getCondition());
DocumentCondition condition = negate.getDocument().get(DocumentCondition.class);
assertEquals(eq, condition);
}
Aggregations