use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldDeleteNegate.
@Test
public void shouldDeleteNegate() {
String columnFamily = "columnFamily";
DocumentDeleteQuery query = delete().from(columnFamily).where("city").not().eq("Assis").and("name").not().eq("Lucas").build();
DocumentCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
assertEquals(columnFamily, query.getDocumentCollection());
Document column = condition.getDocument();
List<DocumentCondition> conditions = column.get(new TypeReference<List<DocumentCondition>>() {
});
assertEquals(Condition.AND, condition.getCondition());
assertThat(conditions, containsInAnyOrder(eq(Document.of("city", "Assis")).negate(), eq(Document.of("name", "Lucas")).negate()));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameOr.
@Test
public void shouldSelectWhereNameOr() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentDeleteQuery query = delete().from(documentCollection).where("name").eq(name).or("age").gt(10).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
});
assertEquals(Condition.OR, condition.getCondition());
assertThat(conditions, Matchers.containsInAnyOrder(eq(Document.of("name", name)), DocumentCondition.gt(Document.of("age", 10))));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldExecutePrepareStatement.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age = @age" })
public void shouldExecutePrepareStatement(String query) {
ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
prepare.bind("age", 12);
prepare.getResult();
Mockito.verify(manager).delete(captor.capture());
DocumentDeleteQuery documentQuery = captor.getValue();
DocumentCondition documentCondition = documentQuery.getCondition().get();
Document document = documentCondition.getDocument();
assertEquals(Condition.EQUALS, documentCondition.getCondition());
assertEquals("age", document.getName());
assertEquals(12, document.get());
}
use of jakarta.nosql.document.DocumentCondition 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);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDocumentConditionTest method shouldReturnBetween.
@Test
public void shouldReturnBetween() {
Document document = Document.of("age", Arrays.asList(12, 13));
DocumentCondition between = DocumentCondition.between(document);
assertEquals(Condition.BETWEEN, between.getCondition());
Iterable<Integer> integers = between.getDocument().get(new TypeReference<Iterable<Integer>>() {
});
assertThat(integers, contains(12, 13));
}
Aggregations